How to Install OwnCloud 8 with Nginx and MariaDB on CentOS 7

OwnCloud is a server software for data synchronization and file-sharing with an easy to use web-based frontend that is available under a open source license. Owncloud can be installed on a Linux or Windows webserver, is easy to configure and has a comprehensive online documentation. The native client is available for Windows, MacOS and Linux (Desktop Application). There is also a mobile app for Android and iOS.

This tutorial describes the installation of Owncloud 8 on CentOS 7 with nginx webserver and MariaDB database.

The latest version as of today is OwnCloud 8.0.

Prerequisites

  • 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

Disable SELinux

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 http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
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
mysql_secure_installation

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 = 127.0.0.1:9000

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 http://192.168.1.101/.

Nginx CentOS 7

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;

Create database and user mariaDB

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/
wget https://download.owncloud.org/community/owncloud-8.0.0.tar.bz2

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 127.0.0.1:9000;
    #server unix:/var/run/php5-fpm.sock;
}

server {
        listen 80;
        server_name 192.168.1.101; #YourIP or domain
        return 301 https://$server_name$request_uri;  # redirect all to use ssl
}


server {
        listen 443 ssl;
        server_name 192.168.1.101; #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:

reboot

Test OwnCloud

http://192.168.1.101 and you will be redirect to ssl connection https://192.168.1.101.

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

Owncloud  in CentOS 7

Conclusion

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.

Share this page:

8 Comment(s)

Add comment

Comments

From: Jino

How to set up on nginx with owncloud & pydio?

I tried first, set up owncloud in my server (Centos 7.0).

Then, create xe_db in MariaDB. After download xe and unzip /usr/share/nginx/html/.

I think that Restart MariaDB and nginx, i will see xe home page on my localhost address.

but, i saw just owncloud's homepage.

How to i will fix?

Anybody please help me.

   

From: coastdweller

It is same for me, followed directions and end up with nginx default page only.

From: Ryan

I followed this completely. However, I get the nginx default page. I don't get a redirect, and when I append IP address with "/owncloud" I get a 404 error.  This should be easier than it is, I suppose, but I thought I'd ask.

From: Some_Bored_Dude

Disabling SELINUX is a BAD IDEA, particularly if your OC is web facing. It's really simple to configure the rules. OwnCloud includes documentation on howto made selinux play nicely.

https://doc.owncloud.org/server/8.0/admin_manual/installation/selinux_configuration.html

 

From: manu

hmmz

it seems that i can't use the updates after folowing this installation guide.I always get the message that i must read the log read log.When i refresh my page i can  do the update but get these errors.

Security & setup warnings php does not seem to be setup properly to query system environment variables. The test with getenv("PATH") only returns an empty response.Please check the installation documentation for php configuration notes and the php configuration of your server, especially when using php-fpm. Your web server is not yet set up properly to allow file synchronization because the WebDAV interface seems to be broken. Error occurred while checking server setup The "Strict-Transport-Security" HTTP header is not configured to least "15768000" seconds. For enhanced security we recommend enabling HSTS as described in our security tips.

can someone please help met out with this

From: Travis van der Font

Very nice steps! Easy to follow and precise.Don't forget chown -R nginx:nginx "/usr/share/nginx/html" else the admin will run into 403 permission errors!Also, look into adding some error logging into Nginx configuration (via /var/log/nginx)

From: sirmonkey

followed the guide.index.php gets downloaded if you goto http://<host ip>/owncloud (nothing on http://<host ip> )

php not setup corretly?

From: henry

how to enable ldap ,an error :the library ldap is not available, 

when i install php-ldap,but it still have this error ,

how to solve it .thanks a lot !