Instaling ownCloud with nginx and php-fpm

      3 Comments on Instaling ownCloud with nginx and php-fpm

Setting up an ownCloud instance is rather straight forward. OwnCloud6 rpm packages for recent Fedora versions (20+) already exist and can be easily installed with yum. Unfortunately, ownCloud’s storage mechanism is rather slow compared to other private cloud solution like Seafile or SparkleShare. However the overall speed can be improved greatly by switching from the most obvious and most popular server choice – an apache server – to nginx, for example.

0. Installation prerequisites

Let’s start by installing the necessary packages:

# yum install owncloud owncloud-nginx php-fpm

1. Setting up the database

Next, we need to set up a database backend for ownCloud, which can be either MySQL or PostgreSQL. Since the MySQL comminity fork MariaDB is officially part of Fedora, let’s use a MariaDB instance here:

# systemctl enable mariadb.service 
ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
# systemctl start mariadb.service 
# mysql_secure_installation 
[...]

# mysql --user=root --password
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE USER 'owncloud'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> CREATE SCHEMA owncloud CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON owncloud.* TO 'owncloud'@'localhost';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye

2. Configuring nginx

Configuring the nginx backend is pretty simple. First, you have to allow clients from your subnet to access the nginx server by adding an appropriate access rule to the server section of the owncloud configuration file and change the server name to match your server’s FQDN:

[...]
server {
#         listen 443 ssl;
        listen 80;
        server_name ownCloud;

        allow 127.0.0.1;
        allow 192.168.2.0/24;
        deny all;

#         ssl_certificate /etc/ssl/nginx/cloud.example.com.crt;
#         ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;

        # Path to the root of your installation
        root /usr/share/owncloud/;
[...]

Second, enable and start the nginx server as well as PHP FastCGI Process Manager

# systemctl enable php-fpm.service 
ln -s '/usr/lib/systemd/system/php-fpm.service' '/etc/systemd/system/multi-user.target.wants/php-fpm.service'
# systemctl start php-fpm.service
# systemctl enable nginx.service 
ln -s '/usr/lib/systemd/system/nginx.service' '/etc/systemd/system/multi-user.target.wants/nginx.service'
# systemctl start nginx.service

And finally, open up your web browser and point it to your owncloud server. You should see ownCloud’s installation screen:

ownCloud installation screen

ownCloud installation screen

If you click on Advanced you can fill in the details of your database connection:

ownCloud advanced setup  options

ownCloud advanced setup options

And if you confirm your settings with a click on Finish setup you should be redirected to ownCloud’s web UI.

3. Tuning the setup

To speed up ownCloud even further, you may want to look into nginx’s memchached module and MySQLTuner.
There are also quite a few tutorials on nginx performance tuning out there, some of which have great tips on how to tune your nginx server for maximum performance. Among a lot of other things, you could reduce the keepalive_timeout and disable logging with access_log off; (both to be set in the nginx config file /etc/nginx/nginx.conf).

4. Bug, bugs, bugs…

Unfortunately, there’s currently a bug in Fedora 20’s php package, which results in the /var/lib/php/session/ directory not being created when you install only nginx and the PHP FastCGI Process Manager as described above. This will create a redirection loop when you try to log into your owncloud web UI. You can either install the php interpreter package (wich owns /var/lib/php/session/) with yum install php or create the directory manually:

# mkdir /var/lib/php/session
# chown root:apache /var/lib/php/session/
# chmod 770 /var/lib/php/session/
# systemctl restart nginx.service

Don’t forget to restart the nginx server afterwards!

3 thoughts on “Instaling ownCloud with nginx and php-fpm

  1. avatarJames McDonald

    I found the bug under point 4 was caused by upgrading from php to php55u on CentOS 6.5. It pulled in Apache as a dependency and then changed /var/lib/php/session to be owned by the apache user instead of my nginx user.

    Did the above and fixed it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.