{"id":242,"date":"2017-05-22T10:05:37","date_gmt":"2017-05-22T08:05:37","guid":{"rendered":"http:\/\/owncloud.gonscak.sk\/?p=242"},"modified":"2019-09-24T09:18:32","modified_gmt":"2019-09-24T07:18:32","slug":"how-to-install-nextcloud-on-centos-7-minimal","status":"publish","type":"post","link":"https:\/\/www.gonscak.sk\/?p=242","title":{"rendered":"How to install nextcloud on centos 7 minimal"},"content":{"rendered":"<p>At first, please update your centos. Every command I use, is used as root \ud83d\ude09<\/p>\n<pre>yum -y update<\/pre>\n<h1>Installing database server MariaDB<\/h1>\n<p>Next, we install and create empty database for our nextcloud. Then we start it and enable for autostart after boot.<br \/>\nIf you wish, you can skip installations of MariaDB and you can use built-in SQLite. Then you can continue with installing apache web server.<\/p>\n<pre>yum -y install mariadb mariadb-server\n...\nsystemctl start mariadb\nsystemctl enable mariadb<\/pre>\n<p>Now, we run post installation script to finish setting up mariaDB server:<\/p>\n<pre>mysql_secure_installation\n...\nEnter current password for root (enter for none): ENTER\nSet root password? [Y\/n] Y\nRemove anonymous users? [Y\/n] Y\nDisallow root login remotely? [Y\/n] Y\nRemove test database and access to it? [Y\/n] Y\nReload privilege tables now? [Y\/n] Y<\/pre>\n<p>Now, we can create a database for nextcloud.<\/p>\n<pre>mysql -u root -p\n...\nCREATE DATABASE nextcloud;\nGRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost' IDENTIFIED BY 'YOURPASSWORD';\nFLUSH PRIVILEGES;\nexit;<\/pre>\n<h1>Installing Apache Web Server with ssl (letsencrypt)<\/h1>\n<p>Now, we install Apache web server, and we start it and enable for autostart after boot:<\/p>\n<pre>yum install httpd -y\nsystemctl start httpd.service\nsystemctl enable httpd.service<\/pre>\n<p>Now, we install ssl for apache and allow https service for firewall:<\/p>\n<pre class=\"code-pre command\"><code>yum -y install epel-release\nyum -y install httpd mod_ssl\n...\nfirewall-cmd --zone=public --permanent --add-service=https\nfirewall-cmd --zone=public --permanent --add-service=http\nfirewall-cmd --reload\nsystemctl restart httpd.service\nsystemctl status httpd<\/code><\/pre>\n<p>Now we can access our server via https:\/\/out.server.sk<br \/>\nIf we want signed certificate from letsencrypt, we can do it with next commands. Certboot will ask some questions, so answer them.<\/p>\n<pre class=\"code-pre command\"><code>yum -y install python-certbot-apache\ncertbot --apache -d <span class=\"highlight\">example.com<\/span><\/code><\/pre>\n<p>If we are good, we can see:<\/p>\n<pre class=\"code-pre \"><code>IMPORTANT NOTES:\n - Congratulations! Your certificate and chain have been saved at\n   \/etc\/letsencrypt\/live\/example.com\/fullchain.pem.\n...\n<\/code><\/pre>\n<p>And we can test our page with this:<\/p>\n<pre>https:\/\/www.ssllabs.com\/ssltest\/analyze.html?d=example.com&amp;latest<\/pre>\n<h1>Install PHP 7<\/h1>\n<p>As creators of nextcloud recommends at minimal PHP 5.4, I use php 7.<br \/>\nPHP 5.4 has been end-of-life since September 2015 and is no longer supported by the PHP team. RHEL 7 still ships with PHP 5.4, and Red Hat supports it. Nextcloud also supports PHP 5.4, so upgrading is not required. However, it is highly recommended to upgrade to PHP 5.5+ for best security and performance.<br \/>\nNow we must add some additional repositories:<\/p>\n<pre>rpm -Uvh https:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm\nrpm -Uvh https:\/\/mirror.webtatic.com\/yum\/el7\/webtatic-release.rpm<\/pre>\n<p>And we can install php 7.2:<\/p>\n<pre>yum install mod_php72w.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-intl.x86_64 php72w-mysql.x86_64 php72w-xml.x86_64 php72w-mbstring.x86_64 php72w-cli.x86_64 php72w-process.x86_64<\/pre>\n<p>Check in:<\/p>\n<pre>php --ini |grep Loaded\nLoaded Configuration File:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/etc\/php.ini\nphp -v\nPHP 7.2.22 (cli) (built: Sep 11 2019 18:11:52) ( NTS )\nCopyright (c) 1997-2018 The PHP Group\nZend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies<\/pre>\n<p>In my case, I will use nextcloud as my backup device, so I increase the default upload limit to 200MB.<\/p>\n<pre>sed -i \"s\/post_max_size = 8M\/post_max_size = 200M\/\" \/etc\/php.ini\nsed -i \"s\/upload_max_filesize = 2M\/upload_max_filesize = 200M\/\" \/etc\/php.ini\nsed -i \"s\/memory_limit = 128M\/memory_limit = 512M\/\" \/etc\/php.ini<\/pre>\n<p>Restart web server:<\/p>\n<pre>systemctl restart httpd<\/pre>\n<h1>Installing Nextcloud<\/h1>\n<p>At first, I install wget tool for download and unzip:<\/p>\n<pre>\u00a0yum -y install wget unzip<\/pre>\n<p>Now we can download nextcloud (at this time the latest version is 16.0.4). And extract it from archive to final destination. Then we change ownership of this directory:<\/p>\n<pre>wget https:\/\/download.nextcloud.com\/server\/releases\/nextcloud-16.0.4.zip\n...\nunzip nextcloud-16.0.4.zip -d \/var\/www\/html\/\n...\nchown -R apache:apache \/var\/www\/html\/nextcloud\/<\/pre>\n<p>Check, if you have enabled SELinux by command sestatus:<\/p>\n<pre>sestatus \n\nSELinux status:                 enabled\nSELinuxfs mount:                \/sys\/fs\/selinux\nSELinux root directory:         \/etc\/selinux\nLoaded policy name:             targeted\nCurrent mode:                   enforcing\nMode from config file:          enforcing\nPolicy MLS status:              enabled\nPolicy deny_unknown status:     allowed\nMax kernel policy version:      31<\/pre>\n<p>Refer to nextcloud admin manual, you can run into permissions problems. Run these commands as root to adjust permissions:<\/p>\n<pre>semanage fcontext -a -t httpd_sys_rw_content_t '\/var\/www\/html\/nextcloud\/data(\/.*)?'\nsemanage fcontext -a -t httpd_sys_rw_content_t '\/var\/www\/html\/nextcloud\/config(\/.*)?'\nsemanage fcontext -a -t httpd_sys_rw_content_t '\/var\/www\/html\/nextcloud\/apps(\/.*)?'\nsemanage fcontext -a -t httpd_sys_rw_content_t '\/var\/www\/html\/nextcloud\/.htaccess'\nsemanage fcontext -a -t httpd_sys_rw_content_t '\/var\/www\/html\/nextcloud\/.user.ini'\nrestorecon -Rv '\/var\/www\/html\/nextcloud\/'<\/pre>\n<p>If you see error &#8220;-bash: semanage: command not found&#8221;, install packages:<\/p>\n<pre>yum provides \/usr\/sbin\/semanage<\/pre>\n<pre>yum install policycoreutils-python-2.5-33.el7.x86_64<\/pre>\n<p>And finally, we can access our nextcloud and set up administrators password via our web: https:\/\/you-ip\/nextcloud<br \/>\nNow you must complete the installation via web interface. Set Administrator&#8217;s password and locate to MariaDB with used credentials:<\/p>\n<pre>Database user: nextclouduser\nDatabase password: YOURPASSWORD\nDatabase name: nextcloud\nhost: localhost<\/pre>\n<p>In my case, I must create a DATA folder under out nextcloud and set permissions:<\/p>\n<pre>mkdir \/var\/www\/html\/nextcloud\/data\nchown apache:apache \/var\/www\/html\/nextcloud\/data -R\nsemanage fcontext -a -t httpd_sys_rw_content_t '\/var\/www\/html\/nextcloud\/data(\/.*)?'\nrestorecon -Rv '\/var\/www\/html\/nextcloud\/'<\/pre>\n<p>For easier access, I created a permanent redirect for my IP\/domain Nextcloud root folder. This redirect allow you to open page<\/p>\n<pre>https:\/\/your-ip<\/pre>\n<p>and redirect you to:<\/p>\n<pre>https:\/\/your-ip\/nextcloud<\/pre>\n<p>You must edit httpd.conf file and add this line into directory \/var\/www\/html:<\/p>\n<pre>vim \/etc\/httpd\/conf\/httpd.conf\n...\nRedirectMatch ^\/$ https:\/\/your-ip\/nextcloud\n...\nsystemctl restart httpd.service<\/pre>\n<p>If we see an error like &#8220;Your data directory and files are probably accessible from the Internet. The .htaccess file is not working. &#8221; try edit and change variable<\/p>\n<pre>vim \/etc\/httpd\/conf\/httpd.conf\n....\n&lt;Directory \"\/var\/www\/html\"&gt;\n    AllowOverride <span style=\"color: #ff0000;\">All<\/span>\n    Require all granted\n    Options Indexes FollowSymLinks\n&lt;\/Directory&gt;\n\n<\/pre>\n<h3>Enable updates via the web interface<\/h3>\n<p>To enable updates via the web interface, you may need this to enable writing to the directories:<\/p>\n<div class=\"highlight-python\">\n<div class=\"highlight\">\n<pre>setsebool httpd_unified on\n<\/pre>\n<\/div>\n<\/div>\n<p>When the update is completed, disable write access:<\/p>\n<div class=\"highlight-python\">\n<div class=\"highlight\">\n<pre>setsebool -P httpd_unified off<\/pre>\n<div id=\"disallow-write-access-to-the-whole-web-directory\" class=\"section\">\n<h3>Disallow write access to the whole web directory<\/h3>\n<p>For security reasons it\u2019s suggested to disable write access to all folders in \/var\/www\/ (default):<\/p>\n<div class=\"highlight-python\">\n<div class=\"highlight\">\n<pre>setsebool -P  httpd_unified  off\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<h3>A way to enable enhanced security with own configuration file<\/h3>\n<pre>vim \u00a0\/etc\/httpd\/conf.d\/owncloud.conf\n...\nAlias \/nextcloud \"\/var\/www\/html\/nextcloud\/\"\n&lt;Directory \/var\/www\/html\/nextcloud\/&gt;\n\u00a0 Options +FollowSymlinks\n\u00a0 AllowOverride All\n\u00a0&lt;IfModule mod_dav.c&gt;\n\u00a0 Dav off\n\u00a0&lt;\/IfModule&gt;\n\u00a0SetEnv HOME \/var\/www\/html\/nextcloud\n\u00a0SetEnv HTTP_HOME \/var\/www\/html\/nextcloud\n&lt;\/Directory&gt;<\/pre>\n<\/div>\n<\/div>\n ","protected":false},"excerpt":{"rendered":"<p>At first, please update your centos. Every command I use, is used as root \ud83d\ude09 yum -y update Installing database server MariaDB Next, we install and create empty database for our nextcloud. Then we start it and enable for autostart after boot. If you wish, you can skip installations of MariaDB and you can use &hellip; <a href=\"https:\/\/www.gonscak.sk\/?p=242\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to install nextcloud on centos 7 minimal<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[3,68,69,70],"class_list":["post-242","post","type-post","status-publish","format-standard","hentry","category-centos","tag-centos","tag-https","tag-letsencrypt","tag-nextcloud"],"_links":{"self":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=242"}],"version-history":[{"count":3,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/242\/revisions"}],"predecessor-version":[{"id":485,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/242\/revisions\/485"}],"wp:attachment":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}