How to install ownCloud 8 on a CentOS 7 VPS

owncloud vpsownCloud is an open source web application for data synchronization and file sharing. The latest version of ownCloud brings improved sharing and collaboration and introduces an improved search, faster ways of getting at your files with favorites and provides extremely quick and easy access to important files.

The installation of ownCloud 8 on a CentOS 7 VPS should take about ten minutes if you follow the very easy steps described below.

Stop the Apache service and disable it to start on server boot:

systemctl stop httpd
systemctl disable httpd

Install Nginx and PHP-FPM:

yum install nginx php-fpm php-cli php-gd php-mcrypt php-mysql php-pear php-xml bzip2

Download the latest version of ownCloud available at https://download.owncloud.org/ and extract it to a directory on your server:

cd /opt/
wget https://download.owncloud.org/community/owncloud-8.0.0.tar.bz2
tar xfv owncloud-8.0.0.tar.bz2
mv owncloud /var/www/html

The webserver user (nginx) needs to be able to write to files and directories inside the ‘/var/www/html/owncloud’ directory, so it can easily be accomplished by executing the following command:

chown nginx:nginx -R /var/www/html/owncloud

Edit the ‘/etc/php-fpm.d/www.conf’ configuration file and set user and group to nginx:

sed -i s'/user = apache/user = nginx/' /etc/php-fpm.d/www.conf
sed -i s'/group = apache/group = nginx/' /etc/php-fpm.d/www.conf

Create ‘data’ directory outside the document root, so that it is not accessible from the web:

mkdir -p /data
chown nginx:nginx /data

ownCloud 8 requires a database, so create a new database using the following commands:

mysql -uroot -p
MariaDB [(none)]> create database ownclouddb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON ownclouddb.* TO 'owncloud'@'localhost' IDENTIFIED BY 'your-password';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> quit

It is recommended to secure ownCloud with SSL certificate and force ownCloud using HTTPS to encrypt ownCloud traffic. You can purchase a trusted SSL Certificate, or create a self-signed SSL certificate using:

openssl req -new -x509 -days 365 -nodes -out /etc/nginx/your-domain.com.crt -keyout /etc/nginx/your-domain.com.key

chmod 600 /etc/nginx/your-domain.com.crt
chmod 600 /etc/nginx/your-domain.com.key

Create a new Nginx server block with the following content:

vi /etc/nginx/sites-available/your-domain.com.conf
server {
    listen       80;
    server_name  your-domain.com;
    rewrite ^ https://$server_name$request_uri? permanent;
}

server {
  listen 443 ssl;
		server_name your-domain.com;
		ssl_certificate /etc/nginx/your-domain.com.crt;
		ssl_certificate_key /etc/nginx/your-domain.com.key;
		root   /var/www/html/owncloud;
  access_log  /var/log/nginx/your-domain.com_access.log;
  error_log  /var/log/nginx/your-domain.com_error.log;
  index index.php;
  client_max_body_size 2000M;

        rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
        rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
        rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;

        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 / {
                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 unix:/var/run/php5-fpm.sock;
        }

  error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root           html;
  }
}

Run the following command to see the ‘session.save_path’ setting:

#cat /etc/php-fpm.d/www.conf | grep session.save_path
php_value[session.save_path] = /var/lib/php/session

Change permissions on PHP’s ‘session.save_path’ directory:

chown root:nginx /var/lib/php/session
chown -R nginx:nginx /var/lib/php/session/*

Enable the newly created Nginx server block:

mkdir -p /etc/nginx/sites-available
mkdir -p /etc/nginx/sites-enabled
ln -s /etc/nginx/sites-available/your-domain.com.conf /etc/nginx/sites-enabled/your-domain.com.conf

Edit Nginx’s main configuration file (/etc/nginx/nginx.conf) and add this line:

include /etc/nginx/sites-enabled/*.conf;

to the end of the http {} block, immediately before the server {} block:

vi /etc/nginx/nginx.conf
include /etc/nginx/sites-enabled/*.conf;

Optionally, delete the default server {} block.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS

Edit the ‘/etc/php-fpm.d/www.conf’ configuration file and change (or comment out) ‘listen = 127.0.0.1:9000’ to ‘listen = /var/run/php5-fpm.sock’ .

vi /etc/php-fpm.d/www.conf
;listen = 127.0.0.1:9000
listen = /var/run/php5-fpm.sock

Restart PHP-FPM and Nginx services for the changes to take effect:

systemctl restart php-fpm
systemctl restart nginx

Set PHP-FPM and Nginx to start on server boot:

systemctl enable php-fpm
systemctl enable nginx

Open https://your-domain.com in your favorite web browser, create an admin account (set admin username and password), change the ‘data’ directory to ‘/data’ (do not leave the default setting ‘/var/www/html/owncloud/data’), click ‘Storage & database’, select MySQL/MariaDB, enter database info (MariaDB user, password, database and hostname) and click ‘Finish setup’.

That is it, the OwnCloud 8 installation is now complete.

Of course, you don’t have to do any of this if you use one of our CentOS Hosting Plans, in which case you can simply ask our expert Linux admins to install ownCloud 8 for you. They are available 24×7 and will take care of your request immediately. For updates, you can also try our guide on How to install OwnCloud 7 on an Ubuntu 14.04 VPS.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

6 thoughts on “How to install ownCloud 8 on a CentOS 7 VPS”

  1. Just a question, but would you want to change the password from nginx to something very secure?

    mkdir -p /data
    chown nginx:nginx /data

    Reply
    • The command:

      chown nginx:nginx /data

      is used to change the ownership of the /data directory. Anyway, the passwords in the guide are used for testing purposes only and it is recommended to replace them with more secure values.

      Reply
  2. Hello,

    Thank you for your great tutorial it worked great!!

    One thing! when I entered for the first time to my https://domain.com i did not change the data directory to /data.

    how can i correct this?

    Thx in advance!!!

    Reply
    • You can reinstall ownCloud, choose ‘advanced’ setup method and set the directory in the setup wizard.

      Reply
  3. Hello.

    You have a typo in the /etc/nginx/sites-available/your-domain.com.conf file. Line 3. There is an extra dot after the semicolon in the server name.

    Thank you for the guide.
    Regards.

    Reply

Leave a Comment