How to Install OwnCloud 8 with Nginx and MariaDB on CentOS 7
This tutorial exists for these OS versions
- CentOS 7.3
- CentOS 7
On this page
- Prerequisites
- To Do
- Disable SELinux and configure firewalld
- Install and configure LEMP
- Step 2 - Installing Nginx, MariaDB and php-fpm
- Step 3 - Start and Configure MariaDB
- Step 4 - Configure php-fpm
- Step 5 - Start nginx
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
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/.
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 ownclouduser@localhost identified by 'ownclouduser';
Grant permissions for the user to the database
grant all privileges on owncloud_db.* to ownclouduser@localhost identified by 'ownclouduser';
flush privileges;
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.
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.