How to Setup ownCloud on CentOS 7

In the future, using the website cloudhosting.lv, you agree to the rules of using Cookies. Read more. I agree

How to configure ownCloud on CentOS 7

ownCloud is open source software that allows you to run your own cloud server or file hosting server. ownCloud is based on a client-server model, and its functionality is similar to Dropbox or Google Drive. ownCloud is open source and free, so anyone can install it on their private server. ownCloud also supports various extensions that add many additional features, such as an online document editor, calendar, and more. Users can sync files from various desktop clients, as the ownCloud client is available for Windows, OS X, Linux, and FreeBSD. Mobile clients for iOS and Android are also available. In addition, files can be downloaded or downloaded using the web interface. Any update in its file system is instantly reflected on other connected devices. ownCloud is written in PHP and JavaScript and uses the Saber / DAV server for remote access. ownCloud can work with several database management systems, such as SQLite, MySQL, MariaDB or PostgreSQL.

Although ownCloud comes with many features, here are a few

  • OwnCloud offers a simple user interface with search capabilities, favorites, tags and other ways to quickly navigate files
  • It supports editing files and previewing PDFs, images, text files, an open document, Word files, and more.
  • Comment on files
  • ownCloud contains comments, sharing within and between ownCloud servers, public links, and more
  • Integration of the anti-virus scan function with the anti-virus application
  • It supports LDAP / Active Directory integration along with powerful integrated registration
  • Full control over access to data and sharing capabilities by user and by group
  • Advanced quota management with custom external storage accounting
  • Previous versions of the files that you have changed are saved and can be returned. Deleted files can be found in the recycle bin
  • Flexible external storage processing allows you to access your existing data through ownCloud
  • In this tutorial, we will learn how to install the latest version of ownCloud on CentOS 7.

    Requirements

    OwnCloud requires at least 128 MB of RAM, but 512 MB of RAM is recommended, which should be increased depending on the number of users, files, and activity. You will also need a server with CentOS 7.x installed. In this guide, we will use the roo account to run the commands. If you are logged in as a user without root privileges, use the sudo command at the beginning of the commands we are about to execute. You can also run the sudo su command to go to the root account.

    Installing ownCloud

    Before installing any packages, it is recommended to update the system and packages using the following command.

    yum -y update

    Now we will need to install the LAMP stack in order to build the necessary platform for installing our 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 start automatically at boot time using the following commands.

    systemctl start httpd
    systemctl enable httpd

    ownCloud works on any version of PHP 5.4+, but PHP 5.4 gets EOL, we will install PHP 5.5 on our server in accordance with the recommendations of ownCloud. Run the following commands to install PHP 5.5 on your system. PHP 5.5 is not available in the YUM repository by default, so you also need to add SCL repositories.

    yum -y install centos-release-scl
    yum -y install php55 php55-php php55-php-gd php55-php-mbstring php55-php-mysqlnd

    Now restart the Apache web server using the following command.

    systemctl restart httpd

    Now install and configure 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 the following command

    systemctl start sendmail
    systemctl enable sendmail

    Now you will need to install MySQL / MariaDB, to do this, run the following command.

    yum install mariadb mariadb-server

    Now start and enable MariaDB to start automatically 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, since we just set MariaDB, so the root password does not exist, just leave it blank and continue to create a new root password for the MariaDB server. Next, he will ask you to remove the anonymous user, the sample database, and ask if you want to disable remote login. Just press Enter for all the questions asked, since we want to use the default selection for each question. This will configure and start our database server. When the MariaDB server is ready, we will need to create a database and database user for ownCloud. Enter the MariaDB command line interface using the following command.

    mysql -u root -p

    Enter the password for the root user that you created when securing the MySQL server. After logging in, you will see the 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 the database using the following command.

    MariaDB [(none)]> CREATE DATABASE owncloud;

    Now create the database user using the following command.

    MariaDB [(none)]> GRANT ALL ON owncloud.* to 'ownclouduser'@'localhost' IDENTIFIED BY 'StrongPassword';

    Be sure to change the database name and username and use a strong password instead of StrongPassword. Now reload the privilege table using the following command.

    MariaDB [(none)]> FLUSH PRIVILEGES;
    MariaDB [(none)]> exit

    Since everything is ready, we can start installing our 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

    Now you need to fix some directory 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 use 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 to 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 with the following command.

    chmod 750 ~/prm.sh && bash ~/prm.sh

    You will see the 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 SELinux is enabled on your system, you need to configure the SELinux module, otherwise you will receive some messages about denied access in the log. To check if you have SELinux enabled, run the following command.

    sestatus

    You will get a conclusion 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

    In the first line, you will see the status of SELinux. If enabled, run the following commands to configure 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 setting up the appropriate SELinux configurations for directories, you will need to run these commands so that your ownCloud can connect to other servers and 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 your ownCloud through 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 to 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 to match the domain you are going to use. Now save the file, exit the editor and restart the Apache web server.

    systemctl restart httpd

    Now you can access your ownCloud installation through the interface using the domain that you used when setting up the virtual host, if you configured DNS. You can also access your ownCloud using your server’s IP address.

    http://your-domain.com

    Or

    http://Your-ServerIP

    You will see the following page. Create a username and password for the administrator account. Then click on the “Storage and Database” link and select MySQL / MariaDB in the “Database Setup” section. Now provide the database username, password, and database database name that you created earlier. Click on the “Finish” button after completion. After installation is complete, you will see the following screen, now you are logged into your ownCloud dashboard.

    OwnCloud Security

    ou can use your ownCloud on top of regular HTTP, but it is highly recommended that you use SSL / TLS to encrypt all the traffic on your server, as well as to protect user logins and user data during transmission. To protect traffic, you can use any SSL certificates, for example, a self-signed certificate, Certbot or Let's Encrypt SSL or Enterprise SSL. To configure Certbot or Let's Encrypt SSL, follow this guide. Once you have a working SSL certificate, you can redirect all traffic to HTTPS by editing the virtual hosts file /etc/httpd/conf.d/owncloud.conf.

    nano /etc/httpd/conf.d/owncloud.conf

    Now add the following line under the virtual host.

    Redirect permanent / https://your-domain.com/

    After editing, your file should look like 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 advised to set the HTTP Strict Transport Security header, which asks browsers not to allow any connection to their ownCloud server using HTTP, and tries to prevent site visitors from circumventing invalid certificate warnings. To enable HSTS on your server, edit the Virtual Hosts file.

    nano /etc/httpd/conf.d/owncloud.conf

    Now add the following lines to your file.

    ServerName your-domain.com
    Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"

    Save the file and exit the editor. Now restart the Apache server using the following command.

    systemctl restart httpd

    After restarting the server, all your HTTP requests will be sent to HTTPS, and HSTS will also be enabled on your server.

    Conclusion

    In this tutorial, we installed our ownCloud on CentOS 7. We also took some steps to ensure the security of our own Cloud installation. Now you can successfully deploy your own cloud server on your server. You can download clients for different platforms to synchronize your data.