How to install OwnCloud 9 server on CentOS/RHEL 7 and 6

OwnCloud CentOS Logo

OwnCloud is a Dropbox-like solution for self-hosted file sharing and syncing. Installing OwnCloud 9 on CentOS/RHEL is quite simple. Whether you want to backup, have file-syncing or just have a Google Calendar alternative, this guide is for you.

Newer version!

There is a newer version of the software and a newer version of this guide available:

What is OwnCloud? Is it like a “cloud”?

If you stumbled here by chance and don’t know what OwnCloud is, here is an article explaining its principal features and advantages/disadvantages. To tell you the truth, OwnCloud is a SaaS cloud, if you want to know more about cloud types you can read this article.

In this article we will cover the installation of the server (not the client).

Step 1: Add the repositories

Important
I take absolutely NO responsibility of what you do with your machine; use this tutorial as a guide and remember you can possibly cause data loss if you touch things carelessly.

The first step is to add the repositories to your system. You will need root access during this procedure. The following procedure will install apache as webserver. Input the commands one by one to avoid errors!

CentOS 7CentOS 6RHEL 7RHEL 6

Open a terminal and input the following commands:

# rpm --import https://download.owncloud.org/download/repositories/stable/CentOS_7/repodata/repomd.xml.key
# curl http://download.owncloud.org/download/repositories/stable/CentOS_7/ce:stable.repo | tee /etc/yum.repos.d/owncloud_CE:stable.repo
# yum install owncloud

Open a terminal and input the following commands:

# rpm --import https://download.owncloud.org/download/repositories/stable/CentOS_6_SCL_PHP54/repodata/repomd.xml.key
# curl http://download.owncloud.org/download/repositories/stable/CentOS_6_SCL_PHP54/ce:stable.repo | tee /etc/yum.repos.d/owncloud_CE:stable.repo
# yum install owncloud

Open a terminal and input the following commands:

# rpm --import https://download.owncloud.org/download/repositories/stable/RHEL_7/repodata/repomd.xml.key
# curl http://download.owncloud.org/download/repositories/stable/RHEL_7/ce:stable.repo | tee /etc/yum.repos.d/owncloud_CE:stable.repo
# yum install owncloud

Open a terminal and input the following commands:

# rpm --import https://download.owncloud.org/download/repositories/stable/RHEL_6/repodata/repomd.xml.key
# curl http://download.owncloud.org/download/repositories/stable/RHEL_6/ce:stable.repo | tee /etc/yum.repos.d/owncloud_CE:stable.repo
# yum install owncloud

These commands will add the repositories that contain the software and install it on your machine.

Step 2: Database selection

Now that you got the OwnCloud software, all that is left is to choose a database that will support the installation. You have three choices:

  • SQLite: is a single-file database. It is suggested only for small installations since it will slow OwnCloud down sensibly.
  • MariaDB/MySQL: are popular open source databases especially amongst web developers. It is the suggested choice.
  • PostgreSQL: a popular enterprise-class database. More complicated than MySQL/MariaDB.

Now, this choice won’t really alter the functionality of OwnCloud (except if you use SQLite), so pick whatever you know best. If you’re unsure pick MariaDB/MySQL.

SQLiteMariaDB/MySQLPostgreSQL

No additional steps are required if you choose SQLite.

Install the software:

# yum install mariadb-server php-mysql
# mysql_secure_installation

During the installation you will be prompted to choose a root password, pick a strong one.

Start (and enable at boot) the service (if you’re on CentOS/RHEL 7):

# systemctl start mariadb
# systemctl enable mariadb

Start (and enable at boot) the service (if you’re on CentOS/RHEL 6):

# service mariadb start
# chkconfig mariadb on

Now you need to enter the database (you will be asked the password you just set):

$ mysql -u root -p

Now that you are in create a database:

CREATE DATABASE owncloud;

Now you need to create the user that will be used to connect to the database:

CREATE USER 'oc_user'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD_HERE';

The last step is to grant the privileges to the new user:

GRANT ALL PRIVILEGES ON owncloud.* TO 'oc_user'@'localhost';
FLUSH PRIVILEGES;

When you’re done type Ctrl-D to exit.

Install the software:

# yum install postgresql postgresql-server php-pgsql

Run the setup, start (and enable at boot) the service (if you’re on CentOS/RHEL 7):

# postgresql-setup initdb
# systemctl start postgresql
# systemctl enable postgresql

Run the setup, start (and enable at boot) the service (if you’re on CentOS/RHEL 6):

# service postgresql initdb
# service postgresql start
# chkconfig postgresql on

Now you need to enter the database:

$ sudo -u postgres psql

Now that you are in create a database:

CREATE DATABASE owncloud;

Now you need to create the user that will be used to connect to the database:

CREATE USER oc_user WITH PASSWORD 'YOUR_PASSWORD_HERE';

The last step is to grant the privileges to the new user:

GRANT ALL PRIVILEGES ON DATABASE owncloud to oc_user;

When you’re done type \q and press enter to exit.

Warning!
You may experience difficulties in authenticating OwnCloud with PostgreSQL since the local authentication method is set to ident by default. If you want to change it keep reading.

The configuration file for PostgreSQL is a file located in /var/lib/pgsql/data/pg_hba.conf . Open it with your favourite editor and look for the marked line:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            ident
#host    replication     postgres        ::1/128                 ident

Replace ident with md5 on that line and restart PostgreSQL:

If you’re on CentOS/RHEL 7:

# systemctl restart postgresql

If you’re on CentOS/RHEL 6:

# service postgresql restart

Step 3: Setting Apache and SELinux

In this step we’ll start (and enable) the webserver and we’ll set SELinux up. Now, many tutorials will tell you to disable SELinux (because it is a difficult component to manage). Instead, I suggest you to keep it on and add the rules for OwnCloud:

CentOS/RHEL 7CentOS/RHEL 6
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/data(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/config(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/apps(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/assets(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/.htaccess'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/.user.ini'
# restorecon -Rv '/var/www/html/owncloud/'

If you decided to use a Mariadb/MySQL/PostgreSQL, you also need to allow apache to access it:

# setsebool -P httpd_can_network_connect_db 1
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/data(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/config(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/apps(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/assets(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/.htaccess'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/.user.ini'
# restorecon -Rv '/var/www/html/owncloud/'

If you decided to use Mariadb/MySQL/PostgreSQL, you also need to allow apache to access the database:

# setsebool -P httpd_can_network_connect_db 1

Now that you’ve configured SELinux let’s start and enable Apache:

CentOS/RHEL 7CentOS/RHEL 6

Start (and enable at boot) the service:

# systemctl start httpd
# systemctl enable httpd

Start (and enable at boot) the service:

# service httpd start
# chkconfig httpd on

Step 4: Configuring firewall

This step is essential when your firewall is enabled. If your firewall is enabled you won’t be able to access your OwnCloud 9 instance; on the other hand if it isn’t enabled you shouldn’t have any problems and you can simply skip this step. 

Tip!
Keep in mind having a firewall enabled is a good security practice and you should already have one enabled.

In order for the firewall to work, it must be enabled. This guide will not include this part. When you enable a firewall many things can go wrong, e.g. you’re using SSH, you enable the firewall and your connection is cut and can’t connect otherwise, hence you should carefully review the documentation from your distribution.

To open the ports needed by OwnCloud 9 follow these steps:

CentOS/RHEL 7 - FirewallDCentOS/RHEL 6 and 7 - IPtables

FirewallD is a newer firewall used to simplify firewall management. If you’re using it you can simply do:

# firewall-cmd --add-service http --permanent
# firewall-cmd --add-service https --permanent
# firewall-cmd --reload

IPtables is an older firewall (still widely used), if you’re on CentOS 6 or you have disabled firewallD on CentOS 7 you can use IPtables directly.

# iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
# iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT

Step 5: Install

Once you’re done with selecting the database, it’s time to install everything. Head to http://YOUR_IP_ADDRESS/owncloud/ and you will be facing the following screen:

OwnCloud 9 Installation

OwnCloud 9 Installation

Select an administrator username and password, then you can select the data folder, but if you don’t know what you’re doing it’s best if you leave it with the default value. Then click on “Storage & Database” to select the database you chose during step 2. Fill everything and if you’ve followed all the steps correctly you should be seeing the Files app:

OwnCloud 9 Files app

OwnCloud 9 Files app

Image courtesy of mark | marksei
mark

You may also like...

Leave a Reply

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