ownCloud is open source software which lets you run your own cloud server or file hosting server. ownCloud is based on Client-Server model and it’s functionality is similar to Dropbox or Google Drive. ownCloud is open source and free hence anyone can install it on his private server. ownCloud also supports various extensions which adds many extra features to it, like, online document editor, calendar and many more. Users can synchronize files from various desktop client as ownCloud client is available for Windows, OS X, Linux and FreeBSD. It also has mobile clients available for IOS and Android. Additionally files can be uploaded or downloaded using its web based interface also. Any update in its file system is reflected instantly on other connected devices. ownCloud is written in PHP and JavaScript and uses sabre/dav server for remote access. ownCloud can work with several Database management systems like SQLite, MySQL, MariaDB or PostgreSQL.
Although ownCloud comes with tons of features, but few of them are
- ownCloud offers an easy user interface with search, favorites, tags and other ways to quickly navigate within files.
- It supports file editing and previewing of PDF, images, text files, Open Document, Word files and more.
- Comment on your files
- ownCloud features comments, sharing within and between ownCloud servers, public links and more.
- Integration of anti-virus scanning functionality with the anti-virus app.
- It supports LDAP / Active Directory integration along with powerful integrated logging.
- Total control over access to data and sharing capabilities by user and by group.
- Advanced quota management with configurable accounting of external storage.
- Previous versions of files you modified are retained and can be brought back. Deleted files can be found in the trash.
- Flexible external storage handling allows you to access your existing data through ownCloud.
In this tutorial we will learn to install the latest version of ownCloud on CentOS 7.x.
Requirements
ownCloud requires at least 128MB RAM but, recommended is 512 MB RAM, which should be increased according to number of users, files and activity. Also you will need a server with CentOS 7.x installed. In this tutorial we will be using root
account to run the commands, if you are logged in as non root user, use sudo
command at the start of the commands we are going to run. You may also run sudo su
command to switch to root account.
Installing ownCloud
Before installing any packages, it is recommended to update the system and packages, using following command.
yum -y update
Now we will need to install LAMP stack in order to build up the required platform to install ownCloud. We will need to install Apache 2.4 with mod_php, PHP 5.4+ and MySQL/MariaDB.
To install Apache 2.4 run the following command.
yum -y install httpd
Now start and enable it to automatically start at boot time using the following commands.
systemctl start httpd
systemctl enable httpd
ownCloud run on any PHP 5.4+ version, but PHP 5.4 is getting EOL, we will install PHP 5.5 on our server as recommended by ownCloud. Run the following commands to install PHP 5.5 on your system. PHP 5.5 is not available on default YUM repository, hence you will need to add SCL repositories too.
yum -y install centos-release-scl
yum -y install php55 php55-php php55-php-gd php55-php-mbstring php55-php-mysqlnd
Now restart Apache web server using the following command.
systemctl restart httpd
Now install and setup Sendmail so that ownCloud can send push notifications using Sendmail. To install Sendmail run the following command.
yum -y install sendmail
Now start Sendmail and enable it to start at boot time using following command.
systemctl start sendmail
systemctl enable sendmail
Now you will need to install MySQL/MariaDB, run the following command to do so.
yum install mariadb mariadb-server
Now start and enable MariaDB to start automatically start at boot time using the following commands.
systemctl start mariadb
systemctl enable mariadb
Now secure your MariaDB installation using the following command.
mysql_secure_installation
This will run a small script and ask for your current root password, as we have just installed MariaDB, so there is no root password, just leave it blank and proceed further to create a new root password for MariaDB server. It will further ask for removing anonymous user, sample database and it will ask if you want to disable remote login. Just hit enter for all question asked as we want to use the default choice for each question. This will configure and run our database server.
Once MariaDB server is ready we will need to create a database and database user for ownCloud. Login to your MariaDB command line interface, using the following command.
mysql -u root -p
Now enter the password for root user which you have created during securing MySQL server. Once you are logged in, you will see following output.
[root@Testbox ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 10
Server version: 5.5.47-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]>
Create a database using following command.
MariaDB [(none)]> CREATE DATABASE owncloud;
Now create a database user using following command.
MariaDB [(none)]> GRANT ALL ON owncloud.* to 'ownclouduser'@'localhost' IDENTIFIED BY 'StrongPassword';
Be sure to change your database name and username and use a strong password replacing StrongPassword
. Now reload the privileges table using following command.
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit
As we have everything ready now, we can start the installation of ownCloud by running the following commands.
rpm --import https://download.owncloud.org/download/repositories/stable/CentOS_7/repodata/repomd.xml.key
wget http://download.owncloud.org/download/repositories/stable/CentOS_7/ce:stable.repo -O /etc/yum.repos.d/ce:stable.repo
yum clean expire-cache
yum -y install owncloud
This will download and install ownCloud in your server, you can find the ownCloud files in /var/www/owncloud
directory.
Now you will need to fix some directories permissions so that ownCloud can manage the data on your server. Create a new file using any editor of your choice. In this tutorial we will be using nano
, if you don’t have nano
installed, you can easily install it using yum -y install nano
.
nano ~/prm.sh
Now add the following lines of code into the script.
#!/bin/bash
ocpath='/var/www/html/owncloud'
htuser='apache'
htgroup='apache'
rootuser='root'
printf "Creating possible missing Directoriesn"
mkdir -p $ocpath/data
mkdir -p $ocpath/assets
mkdir -p $ocpath/updater
printf "chmod Files and Directoriesn"
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750
printf "chown Directoriesn"
chown -R ${rootuser}:${htgroup} ${ocpath}/
chown -R ${htuser}:${htgroup} ${ocpath}/apps/
chown -R ${htuser}:${htgroup} ${ocpath}/assets/
chown -R ${htuser}:${htgroup} ${ocpath}/config/
chown -R ${htuser}:${htgroup} ${ocpath}/data/
chown -R ${htuser}:${htgroup} ${ocpath}/themes/
chown -R ${htuser}:${htgroup} ${ocpath}/updater/
chmod +x ${ocpath}/occ
printf "chmod/chown .htaccessn"
if [ -f ${ocpath}/.htaccess ]
then
chmod 0644 ${ocpath}/.htaccess
chown ${rootuser}:${htgroup} ${ocpath}/.htaccess
fi
if [ -f ${ocpath}/data/.htaccess ]
then
chmod 0644 ${ocpath}/data/.htaccess
chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess
fi
Now save the file and exit the editor. Now make your file executable and run it using the following command.
chmod 750 ~/prm.sh && bash ~/prm.sh
You will see following output.
[root@Testbox ~]# chmod 750 ~/prm.sh && bash ~/prm.sh
Creating possible missing Directories
chmod Files and Directories
chown Directories
chmod/chown .htaccess
If you have SELinux enabled in your system, then you will need to adjust your SELinux module, otherwise you will get some permissions denied log messages. To check if you have SELinux enabled or not, run the following command.
sestatus
You will get output similar to this.
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 28
On first line you will see the status of SELinux. If enabled run the following commands to adjust the SELinux permissions.
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/data'
restorecon '/var/www/html/owncloud/data'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/config'
restorecon '/var/www/html/owncloud/config'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/apps'
restorecon '/var/www/html/owncloud/apps'
After settings appropriate SELinux configurations for the directories, you will need to run these commands so that ownCloud can connect other servers, also can can send notifications using Sendmail.
setsebool -P httpd_can_network_connect on
setsebool -P httpd_can_sendmail on
Now set up virtual hosts so that you can access ownCloud using your domain. Create a new file /etc/httpd/conf.d/owncloud.conf
using your favorite text editor.
nano /etc/httpd/conf.d/owncloud.conf
Add the following lines in the file.
ServerName MyCloud
ServerName your-domain.com
DocumentRoot /var/www/html/owncloud/
Alias /owncloud "/var/www/html/owncloud/"
Options +FollowSymLinks
AllowOverride All
Dav off
SetEnv HOME /var/www/html/owncloud
SetEnv HTTP_HOME /var/www/html/owncloud
Make sure you change your-domain.com
according to the domain you are going to use. Now save the file, exit from editor and restart Apache web server.
systemctl restart httpd
Now you can access your ownCloud installation through front end using the domain you used during Virtual Host setup, if you have configured DNS. You can also access ownCloud using your server IP address.
http://your-domain.com
Or
http://Your-ServerIP
You will see following page.
HP_NO_IMG/data/uploads/users/d0888044-e701-4d69-a760-fddd1b09f3f2/1933357653.png” alt=”” />
Create a username and password for your administrator account. Next click on Storage and database link, and click on MySQL/MariaDB under Configure the database. Now provide database username, password and database name of the database, which you have created earlier. Click on Finish setup button once done.
HP_NO_IMG/data/uploads/users/d0888044-e701-4d69-a760-fddd1b09f3f2/1971761631.png” alt=”” />
Once the installation finishes you will see the following screen, you are now logged in to your ownCloud dashboard.
HP_NO_IMG/data/uploads/users/d0888044-e701-4d69-a760-fddd1b09f3f2/2057600292.png” alt=”” />
Securing ownCloud
You can use ownCloud over plain HTTP, but it is strongly recommended to use SSL/TLS to encrypt all of your server traffic, and to protect user’s logins and data in transit. You can use any SSL certificates to secure the traffic, for example self-signed certificate, Certbot or Let’s Encrypt SSL or Enterprise SSL. For setting up Certbot or Let’s Encrypt SSL, follow this guide.
Once you have a working SSL certificate, you can redirect all the traffic to HTTPS by editing your virtual hosts file, /etc/httpd/conf.d/owncloud.conf
.
nano /etc/httpd/conf.d/owncloud.conf
Now add the following line under virtual host.
Redirect permanent / https://your-domain.com/
After editing your file should look like as shown below.
ServerName MyCloud
ServerName your-domain.com
DocumentRoot /var/www/html/owncloud/
Redirect permanent / https://your-domain.com/
Alias /owncloud "/var/www/html/owncloud/"
Options +FollowSymLinks
AllowOverride All
Dav off
SetEnv HOME /var/www/html/owncloud
SetEnv HTTP_HOME /var/www/html/owncloud
Administrators are encouraged to set the HTTP Strict Transport Security header, which asks browsers to not allow any connection to the ownCloud server using HTTP, and it attempts to prevent site visitors from bypassing invalid certificate warnings. To enable HSTS on your server, edit your Virtual Hosts file.
nano /etc/httpd/conf.d/owncloud.conf
Now append the following lines into your file.
ServerName your-domain.com
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
Save the file and exit from editor. Now restart your Apache server using following command.
systemctl restart httpd
Once you restart your server, all your HTTP requests will be sent to HTTPS, also HSTS will be enabled on your server too.
Conclusion
In this tutorial we have installed ownCloud on CentOS 7.x. We also took some measures to secure our ownCloud installation. You can now successfully deploy your own cloud server on your server machine. You can download clients for different platforms to sync your data.