Install OwnCloud 8 with Nginx and MariaDB on CentOS 7

Install OwnCloud 8 with Nginx and MariaDB on CentOS 7


  • CentOS 7

To Do

These are the steps that we will do in this tutorial:

  • Disable SELinux and configure firewalld.
  • Instal and configure Nginx, MariaDB, php-fpm.
  • Create a database and configure SSL.
  • Install OwnCloud.
  • Configure a virtualhost for OwnCloud.
  • Test OwnCloud in the browser.

Disable SELinux and configure firewalld

To disable SELinux, edit the file /etc/sysconfig/selinux, and change enforced to disabled.

vim /etc/sysconfig/selinux

Install OwnCloud 8 with Nginx and MariaDB on CentOS 7 – VPSCheap.NET Blog

Run these commands to open port 80/http and 443/https in firewalld so that we can reach the OwnCloud interface by http and https later.

firewall-cmd –permanent –add-service=http
firewall-cmd –permanent –add-service=https
firewall-cmd –reload

Install and configure LEMP

These are the steps to setup the basic LEMP (Linux – Nginx – MariaDB – PHP) Server to run OwnCloud on.

Step 1 – Enable epel-repository

To install LEMP(Linux, Nginx, MariaDB and PHP) you must enable epel-repository.

yum -y install epel-release

Step 2 – Installing Nginx, MariaDB and php-fpm

sudo rpm -Uvh
yum -y install nginx mariadb mariadb-server php-fpm php-cli php-gd php-mcrypt php-mysql php-pear php-xml bzip2 vim

Step 3 – Start and Configure MariaDB

systemctl start mariadb

the first time you just press Enter.

Change the root password? [Y/n] Y Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y

Step 4 – Configure php-fpm

Edit file /etc/php-fpm.d/www.conf.

vim /etc/php-fpm.d/www.conf

make sure the line listen is :

listen =

And edit the line for user – group :

user = nginx group = nginx

Create directory for session-path.

mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/

Start php-fpm.

systemctl start php-fpm

Step 5 – Start nginx

systemctl start nginx

At this step you can visit your web server

Install OwnCloud 8 with Nginx and MariaDB on CentOS 7 – VPSCheap.NET Blog

Create a database and Configure SSL

Step 1 – Create Database and User

Login to MariaDB with the mysql commandline client:

mysql -u root -p

Create the database:

create database owncloud_db;

Add a user:

create user [email protected] identified by ‘ownclouduser’;

Grant permissions for the user to the database

grant all privileges on owncloud_db.* to [email protected] identified by ‘ownclouduser’;
flush privileges;

Install OwnCloud 8 with Nginx and MariaDB on CentOS 7 – VPSCheap.NET Blog

Step 2 – Create SSL Certificate

mkdir -p /etc/nginx/cert/
cd /etc/nginx/cert/
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/owncloud.crt -keyout /etc/nginx/cert/owncloud.key

the command will generate a owncloud.crt and owncloud.key in directory /etc/nginx/cert/.

Change permission certificate file.

chmod 600 owncloud.crt
chmod 600 owncloud.key

Install OwnCloud

Download the application source with wget.

yum -y install wget
cd /tmp/

Extract and move owncloud directory to /usr/share/nginx/html.

tar -xjvf owncloud-8.0.0.tar.bz2
mv owncloud/ /usr/share/nginx/html/

Change the owner of owncloud directory to nginx.

cd /usr/share/nginx/html/
chown nginx:nginx -R owncloud/

Create directory called data on owncloud directory, and change owner to nginx.

mkdir -p owncloud/data/
chown nginx:nginx -R owncloud/data/

Configure a Virtualhost for OwnCloud

The last step is to configure a virtualhost for owncloud.

cd /etc/nginx/conf.d/
mv default.conf default

add owncloud configuration to /etc/nginx/conf.d/

vim owncloud.conf

Paste configuration below :

upstream php-handler {     server;     #server unix:/var/run/php5-fpm.sock; }  server {         listen 80;         server_name; #YourIP or domain         return 301 https://$server_name$request_uri;  # redirect all to use ssl }   server {         listen 443 ssl;         server_name; #YourIP or domain          #SSL Certificate you created         ssl_certificate /etc/nginx/cert/owncloud.crt;          ssl_certificate_key /etc/nginx/cert/owncloud.key;          # owncloud path         root /usr/share/nginx/html/owncloud/;          client_max_body_size 10G; # set max upload size         fastcgi_buffers 64 4K;          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 ~ ^/(data|config|/.ht|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)(/.*)?$ {                 try_files $1 = 404;                  include fastcgi_params;                 fastcgi_param SCRIPT_FILENAME $document_root$1;                 fastcgi_param PATH_INFO $2;                 fastcgi_param HTTPS on;                 fastcgi_pass php-handler;         }          # Optional: set long EXPIRES header on static assets         location ~* ^.+/.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {                 expires 30d;                 # Optional: Don't log access to assets                 access_log off;         }  }

And then restart the LEMP stack:

systemctl restart nginx mariadb php-fpm

Now configure the LEMP Services to start on boot.

systemctl enable nginx
systemctl enable php-fpm
systemctl enable mariadb

Then reboot your server:


Test OwnCloud and you will be redirect to ssl connection

Create admin account and fill all Database(Username,Password,dbname) then click Finish Setup.

Install OwnCloud 8 with Nginx and MariaDB on CentOS 7 – VPSCheap.NET Blog


OwnCloud is the right solution for a private cloud today. Easy to use and configure and with a userfriendly interface which makes it easy to use and install. Owncloud is fast, stable and has many features.


Install OwnCloud 8 with Nginx and MariaDB on CentOS 7 – VPSCheap.NET Blog


Leave a Reply

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