Installing Owncloud 7 (from source), PostgreSQL 9.3, PHP-FPM and NginX on Ubuntu Server 14.04 64 bit

Want to support HowtoForge? Become a subscriber!
Submitted by s2s (Contact Author) (Forums) on Tue, 2014-08-12 10:19. :: Linux | Ubuntu | Web Server | nginx

Installing Owncloud 7 (from source), PostgreSQL 9.3, PHP-FPM and NginX on Ubuntu Server 14.04 64 bit

Version 1.0 
Author: Sebastian Sasu
Last edited 2014-08-12

1. Install ubuntu server 14.04 64 bit (not covered in this howto) and at software selection choose OpenSSH Server only. In this way we'll have ssh access to the server.

After reboot add nginx repository to /etc/apt/sources.list

sudo nano -wc /etc/apt/sources.list

2. Add the following at the end of the file:

# nginx stable 
deb trusty nginx 
deb-src trusty nginx 
# nginx mainline 
deb trusty nginx 
deb-src trusty nginx

3. Update your software

sudo apt-get update
sudo apt-get dist-upgrade

4. Install nginx

sudo apt-get install nginx

5. Install neccesarry software for owncloud:

sudo apt-get install acl at-spi2-core ca-certificates-java colord cpp cpp-4.8 dbus-x11 dconf-gsettings-backend dconf-service default-jre default-jre-headless desktop-file-utils dictionaries-common fontconfig fontconfig-config fonts-dejavu fonts-dejavu-core fonts-dejavu-extra fonts-font-awesome fonts-liberation fonts-opensymbol fonts-sil-gentium fonts-sil-gentium-basic gconf-service gconf-service-backend gconf2 gconf2-common gdisk ghostscript gsfonts gvfs gvfs-common gvfs-daemons gvfs-libs heirloom-mailx hicolor-icon-theme hunspell-en-us icedtea-7-jre-jamvm imagemagick-common java-common javascript-common libao-common libao4 libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libasound2 libasound2-data libasyncns0 libatasmart4 libatk-bridge2.0-0 libatk-wrapper-java libatk-wrapper-java-jni libatk1.0-0 libatk1.0-data libatspi2.0-0 libav-tools libavahi-client3 libavahi-common-data libavahi-common3 libavahi-glib1 libavcodec54 libavdevice53 libavfilter3 libavformat54 libavresample1 libavutil52 libbonobo2-0 libbonobo2-common libboost-date-time1.54.0 libboost-system1.54.0 libcaca0 libcairo-gobject2 libcairo2 libcanberra0 libcdio-cdda1 libcdio-paranoia1 libcdio13 libcdr-0.0-0 libcloog-isl4 libclucene-contribs1 libclucene-core1 libcmis-0.4-4 libcolamd2.8.0 libcolord1 libcolorhug1 libcups2 libcupsfilters1 libcupsimage2 libdatrie1 libdc1394-22 libdconf1 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libexif12 libexttextcat-2.0-0 libexttextcat-data libfftw3-double3 libflac8 libfontconfig1 libfontenc1 libgconf-2-4 libgconf2-4 libgd3 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libgif4 libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa libglu1-mesa libgmp10 libgnome2-0 libgnome2-bin libgnome2-common libgnomevfs2-0 libgnomevfs2-common libgomp1 libgphoto2-6 libgphoto2-l10n libgphoto2-port10 libgraphite2-3 libgs9 libgs9-common libgsm1 libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 libgtk-3-0 libgtk-3-bin libgtk-3-common libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libgudev-1.0-0 libgusb2 libharfbuzz-icu0 libharfbuzz0b libhsqldb1.8.0-java libhunspell-1.3-0 libhyphen0 libice6 libicu52 libidl-common libidl0 libieee1284-3 libijs-0.35 libisl10 libjack-jackd2-0 libjasper1 libjbig0 libjbig2dec0 libjpeg-turbo8 libjpeg8 libjs-chosen libjs-dojo-core libjs-dojo-dijit libjs-dojo-dojox libjs-jcrop libjs-jquery libjs-jquery-metadata libjs-jquery-minicolors libjs-jquery-mousewheel libjs-jquery-tablesorter libjs-jquery-timepicker libjs-jquery-ui libjs-pdf libjs-sphinxdoc libjs-twitter-bootstrap libjs-underscore liblangtag-common liblangtag1 liblcms2-2 libldb1 libllvm3.4 liblqr-1-0 libltdl7 libmagickcore5 libmagickwand5 libmcrypt4 libmhash2 libmp3lame0 libmpc3 libmpfr4 libmspub-0.0-0 libmysqlclient18 libmythes-1.2-0 libneon27-gnutls libnspr4 libnss3 libnss3-1d libnss3-nssdb libntdb1 liboauth-php libogg0 libopenjpeg2 libopus0 liborbit-2-0 liborbit2 liborc-0.4-0 liborcus-0.6-0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpaper-utils libpaper1 libpciaccess0 libphp-pclzip libphp-phpmailer libpixman-1-0 libpoppler44 libpulse0 libpython3.4 libraptor2-0 librasqal3 libraw1394-11 librdf0 libreoffice libreoffice-avmedia-backend-gstreamer libreoffice-base libreoffice-base-core libreoffice-base-drivers libreoffice-calc libreoffice-common libreoffice-core libreoffice-draw libreoffice-gnome libreoffice-gtk libreoffice-impress libreoffice-java-common libreoffice-math libreoffice-pdfimport libreoffice-report-builder-bin libreoffice-sdbc-firebird libreoffice-sdbc-hsqldb libreoffice-style-galaxy libreoffice-style-human libreoffice-writer libsamplerate0 libsane libsane-common libschroedinger-1.0-0 libsdl1.2debian libsecret-1-0 libsecret-common libservlet3.0-java libsm6 libsmbclient libsndfile1 libspeex1 libswscale2 libtalloc2 libtdb1 libtevent0 libthai-data libthai0 libtheora0 libtidy-0.99-0 libtiff5 libtxc-dxtn-s2tc0 libudisks2-0 libv4l-0 libv4lconvert0 libva1 libvisio-0.0-0 libvorbis0a libvorbisenc2 libvorbisfile3 libvpx1 libwayland-client0 libwayland-cursor0 libwbclient0 libwpd-0.9-9 libwpg-0.2-2 libwps-0.2-2 libx11-xcb1 libx264-142 libxaw7 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-render0 libxcb-shape0 libxcb-shm0 libxcb-sync1 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxfont1 libxft2 libxi6 libxinerama1 libxkbcommon0 libxmu6 libxpm4 libxrandr2 libxrender1 libxshmfence1 libxslt1.1 libxt6 libxtst6 libxv1 libxvidcore4 libxxf86dga1 libxxf86vm1 libyajl2 libzend-framework-php lp-solve mediawiki-classes mysql-common openjdk-7-jre openjdk-7-jre-headless owncloud-doc php-aws-sdk php-crypt-blowfish php-doctrine-common php-dompdf php-dropbox php-font-lib php-getid3 php-google-api-php-client php-guzzle php-irods-prods php-opencloud php-patchwork-utf8 php-pear php-phpdocx php-sabre-dav php-sabre-vobject php-seclib php-services-json php-symfony-console php-symfony-eventdispatcher php-symfony-routing php-tcpdf php-xml-parser php5 php5-apcu php5-cli php5-common php5-curl php5-gd php5-imagick php5-intl php5-json php5-ldap php5-mcrypt php5-mysql php5-oauth php5-readline php5-tidy php5-xsl policykit-1-gnome poppler-data python-crypto python-ldb python-ntdb python-samba python-talloc python-tdb python3-uno samba-common samba-common-bin samba-libs sdop smbclient sound-theme-freedesktop ssl-cert ttf-dejavu-core tzdata-java udisks2 uno-libs3 ure vorbis-tools x11-common x11-utils xfonts-encodings xfonts-mathml xfonts-utils zend-framework zend-framework-bin php5-pgsql postgresql-9.3 php5-fpm mc

6. Disable apache2

sudo update-rc.d -f apache2 disable

7. Edit postgresql pg_hba.conf

nano -wc /etc/postgresql/9.3/main/pg_hba.conf

You should have these entries in the file

# Database administrative login by Unix domain socket 
local   all             postgres                                peer 
# TYPE  DATABASE        USER            ADDRESS                 METHOD 
# "local" is for Unix domain socket connections only 
local   all             all                                     trust 
# IPv4 local connections: 
host    all             all               md5 
# IPv6 local connections: 
host    all             all             ::1/128                 md5 
# Allow replication connections from localhost, by a user with the 
# replication privilege. 
#local   replication     postgres                                peer 
#host    replication     postgres            md5 
#host    replication     postgres        ::1/128                 md5

8. Create database for OwnCloud 7 (OC7)

sudo su postgres

psql template1

psql (9.3.5)
Type "help" for help.

template1=# create user cloud with password 'pa55w0rd';
template1=# create database cloud template template0 encoding 'UNICODE';
template1=# alter database cloud owner to cloud;
template1=# grant all privileges on database cloud to cloud;
template1=# \q
$ exit


9. Download owncloud:

cd /tmp
tar jxvf owncloud-7.0.1.tar.bz2
mv owncloud /var/www/owncloud

10. Configure nginx:

Generate ssl certificates:

mkdir -p /etc/ssl/nginx/ && cd /etc/ssl/nginx/
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout nginx.key -out nginx.crt

Edit configuration files:

Backup your nginx.conf file first then create an empty one with the following:

sudo mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
sudo nano -wc /etc/nginx/nginx.conf

user  www-data;
worker_processes  2; # Set this according to your number of CPU's

error_log  /var/log/nginx/error.log warn;
pid        /var/run/;

events {
        worker_connections  1024;
        use epoll;

http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                '$status $body_bytes_sent "$http_referer" '
                '"$http_user_agent" "$http_x_forwarded_for"';

        access_log  /var/log/nginx/access.log  main;
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        gzip on;
	  gzip_disable "msie6";
	  gzip_vary on;
	  gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_min_length 1000;
        gzip_buffers 4 32k;
        gzip_types text/plain application/x-javascript text/xml text/css application/xml;

include /etc/nginx/conf.d/*.conf;

upstream php-handler {
        server unix:/var/run/php5-fpm.sock;


Create a config file for your cloud:

mkdir /etc/nginx/conf.d
nano -wc /etc/nginx/conf.d/cloud.conf

Add the following into your cloud.conf:

# Example taken form owncloud administrator manual
server {
        listen 80;
        server_name serverIP_or_FQDN;
        return 301 https://$server_name$request_uri;  # enforce https

server {
        listen 443 ssl spdy; # Activate SPDY for SSL connections
        server_name serverIP_or_FQDN;
        ssl_certificate /etc/ssl/nginx/nginx.crt;
        ssl_certificate_key /etc/ssl/nginx/nginx.key;
        # Path to the root of your installation
        root /var/www/owncloud/;

        client_max_body_size 10G; # set max upload size
        fastcgi_buffers 64 4K;
        client_body_buffer_size 2M;
        rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
        rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
        rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;

        index index.php;
        error_page 403 /core/templates/403.php;
        error_page 404 /core/templates/404.php;

        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;

        location ~ ^/(?:\.htaccess|data|config|db_structure\.xml|README) {
                deny all;

        location / {
                # The following 2 rules are only needed with webfinger
                rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
                rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
                rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
                rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;
                rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
                try_files $uri $uri/ index.php;

        location ~ \.php(?:$|/) {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param HTTPS on;
                fastcgi_pass php-handler;
                fastcgi_read_timeout 600; # Increase this to allow larger uploads
                access_log off; # Disable logging for performance

        # Optional: set long EXPIRES header on static assets

        location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
                expires 365d;
                # Optional: Don't log access to assets
                access_log off;


Before proceeding to OC7 installation from browser first change the owner of the owncloud directory to allow the webserver to have read/write access to it.

sudo chown -R www-data:www-data /var/www/owncloud

Proceed installing owncloud by pointing your browser to https://serverIP_or_FQDN/

Enter the username and password for your admin account.

Select the database type (PostgreSQL) and input the postgresql user/database/password created earlier.

Additional information for file uploads

PHP/PHP-FPM information

For large uploads (>5GB) increase the timeout limits:

For php.ini edit /etc/php5/fpm/php.ini and change the default execution time from 60 seconds to 600:

max_execution_time = 600

For php-fpm add this to your /etc/nginx/conf.d/cloud.conf:

location ~ \.php(?:$|/) {


fastcgi_read_timeout 600;



Also you can increase client_body_buffer_size to limit nginx's buffering to temporary files. Add this to your nginx cloud.conf server directive:

server {

listen 443 ssl spdy;

server_name serverFQDN;


client_body_buffer_size 2M;



An upload of 1G made with ownCloud-client will syncronize in aprox 1 minute (60s) after the last chunk has been uploaded on the server. This is almost direct proportional with the size of an upload. So for a 2G file, it will take aprox 2 minutes (120s) to syncronize after the last chunk has been uploaded.

The settings above will allow you to upload a 5G file without “Gateway Timeout” issues on a network latency of 20-30ms.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.