Installation Environment
- Nextcloud 14.0.0
- CentOS 7.5
- Apache 2.4.6
- PHP 7.1 SCL (minimal: 7.0+)
- MariaDB 10.3 (minimal:5.5+)
- VirtualBox 5.2.18
Let’s get started.
Linux
安裝CentOS Linux 7 (Software Selection: Minimal Install)。
安裝主機資訊。
主機名稱 | nextcloud.local |
IP | 192.168.56.101 |
更新patch。
1 |
yum update |
Installation
安裝所需系統套件。
1 |
yum install curl wget unzip policycoreutils-python |
Apache
Installation
安裝Apache 2.4。
1 2 |
yum install httpd systemctl enable httpd |
安裝SSL模組。
1 |
yum install mod_ssl |
設定https.conf,啟用mod_rewrite。
1 |
sed -i /etc/httpd/conf/httpd.conf -e 's/AllowOverride None/AllowOverride All/g' |
如果網站通過reverse proxy,啟用X-Forwarded-For後,才能取得存取來源IP記錄。
1 |
sed -i /etc/httpd/conf/httpd.conf -e 's/%h/%{X-Forwarded-For}i/g' |
啟動Apache。
1 |
systemctl start httpd |
Firewall
開放對外http/https連線。
1 2 3 |
firewall-cmd --add-service=http --permanent firewall-cmd --add-service=https --permanent systemctl restart firewalld |
MariaDB
Installation
新增MariaDB 10 YUM repo。
1 |
vi /etc/yum.repos.d/MariaDB10.repo |
1 2 3 4 5 6 7 |
# MariaDB 10.3 RedHat repository list - created 2018-05-29 19:40 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name=MariaDB baseurl=http://yum.mariadb.org/10.3/rhel7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 |
安裝MariaDB 10。
1 2 |
yum --enablerepo="mariadb" install MariaDB-server MariaDB-client systemctl enable mariadb |
啟動MariaDB,設定root密碼以及資料庫安全設定。
1 2 |
systemctl start mariadb mysql_secure_installation |
登入MariaDB。
1 |
mysql -u root -p |
建立資料庫及應用程式帳號。
資料庫名稱 | nextcloud |
使用者帳號 | nextcloud@localhost |
使用者密碼 | password |
資料庫權限 | 對nextcloud資料庫所有操作權限(除了GRANT OPTION權限) |
1 2 3 4 5 |
create user nextcloud; create database nextcloud; GRANT ALL PRIVILEGES ON nextcloud.* To 'nextcloud'@'localhost' IDENTIFIED BY 'password'; flush privileges; quit; |
Firewall
本機連線,不需設定。
PHP
Installation
安裝PHP 7。
1 2 3 4 5 6 7 8 9 |
yum install centos-release-scl yum install rh-php71 scl enable rh-php71 bash yum install rh-php71-php rh-php71-php-pear rh-php71-php-gd rh-php71-php-mbstring \ rh-php71-php-mysqlnd rh-php71-php-odbc rh-php71-php-soap rh-php71-php-xml rh-php71-php-xmlrpc \ rh-php71-php-snmp rh-php71-php-ldap rh-php71-php-intl rh-php71-php-gmp \ rh-php71-php-opcache rh-php71-php-pecl-apcu |
設定PHP 7。
1 2 3 |
ln -s /opt/rh/httpd24/root/etc/httpd/conf.d/rh-php71-php.conf /etc/httpd/conf.d/ ln -s /opt/rh/httpd24/root/etc/httpd/conf.modules.d/15-rh-php71-php.conf /etc/httpd/conf.modules.d/ ln -s /opt/rh/httpd24/root/etc/httpd/modules/librh-php71-php7.so /etc/httpd/modules/ |
重新啟動Apache。
1 |
systemctl restart httpd |
Nextcloud
Installation
下載Nextcloud及設定網站根目錄至/var/www/html/nextcloud。
1 2 3 4 |
wget https://download.nextcloud.com/server/releases/nextcloud-14.0.0.zip unzip nextcloud-14.0.0.zip -d /var/www/html chown apache:apache -R /var/www/html/nextcloud sed -i /etc/httpd/conf/httpd.conf -e 's/DocumentRoot \"\/var\/www\/html/&\/nextcloud/g' |
重新啟動Apache。
1 |
systemctl restart httpd |
設定Nextcloud目錄及讀寫權限。
1 2 3 4 5 6 7 8 |
mkdir /var/www/html/nextcloud/data chown apache:apache /var/www/html/nextcloud/data semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/data(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/config(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/3rdparty/aws/aws-sdk-php/src/data/logs(/.*)?' restorecon -Rv '/var/www/html/nextcloud' |
暫時開放Apache可讀寫/var/www/html/nextcloud權限。
1 2 3 4 |
chcon -t httpd_sys_rw_content_t '/var/www/html/nextcloud/' chcon -t httpd_sys_rw_content_t '/var/www/html/nextcloud/apps/' chcon -t httpd_sys_rw_content_t '/var/www/html/nextcloud/.htaccess' chcon -t httpd_sys_rw_content_t '/var/www/html/nextcloud/.user.ini' |
開啟並設定Nextcloud網站。
1 |
http://nextcloud.local/ |
設定完成後,config.php會產生於/var/www/html/nextcloud/config目錄。
重置Apache讀寫權限。
1 |
restorecon -Rv /var/www/html/nextcloud/ |
Cache
設定Opcatch。
1 |
vi /etc/opt/rh/rh-php71/php.d/10-opcache.ini |
設定以下參數。
1 2 3 4 5 6 7 |
opcache.enable=1 opcache.enable_cli=1 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=10000 opcache.memory_consumption=128 opcache.save_comments=1 opcache.revalidate_freq=1 |
設定APCu
1 |
vi /var/www/html/nextcloud/config/config.php |
新增以下參數。
1 |
'memcache.local' => '\OC\Memcache\APCu', |
SSL
設定SSL。
新增自簽憑證。
1 2 3 4 5 6 7 8 |
mkdir /etc/ssl/private chmod 700 /etc/ssl/private/ openssl genrsa -des3 -passout pass:put_your_password -out nextcloud.key 2048 openssl rsa -passin pass:put_your_password -in nextcloud.key -out /etc/ssl/private/nextcloud.local.key chmod 400 /etc/ssl/private/nextcloud.local.key openssl req -new -key nextcloud.local.key -out nextcloud.local.csr openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nextcloud.local.key -out /etc/ssl/certs/nextcloud.local.crt openssl x509 -in /etc/ssl/certs/nextcloud.local.crt -noout -subject |
設定SSL。
1 |
vi /etc/httpd/conf.d/ssl.conf |
設定以下參數。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Listen 443 https <VirtualHost _default_:443> # General setup for the virtual host, inherited from global configuration DocumentRoot "/var/www/html/nextcloud" ServerName nextcloud.local:443 SSLEngine on SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH SSLHonorCipherOrder on SSLCertificateFile /etc/ssl/certs/nextcloud.local.crt SSLCertificateKeyFile /etc/ssl/private/nextcloud.local.key |
新增以下參數。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<Directory "/var/www/html/nextcloud"> Options +FollowSymlinks AllowOverride All <IfModule mod_dav.c> Dav off </IfModule> <IfModule mod_headers.c> Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload" Header always set Referrer-Policy "no-referrer" Header always set Referrer-Policy "no-referrer-when-downgrade" Header always set Referrer-Policy "strict-origin" Header always set Referrer-Policy "strict-origin-when-cross-origin" Header set X-Content-Type-Options "nosniff" </IfModule> SetEnv HOME /var/www/nextcloud SetEnv HTTP_HOME /var/www/nextcloud </Directory> |
Done!
Reference
- Nextcloud 14 Administration Manual
https://docs.nextcloud.com/server/14/admin_manual/