# LNMP(Nginx、MariaDB、PHP7 組成 LNMP Server) * 加入EPEL套件(上次有做) ``` sudo yum -y install epel-release ``` * Remi 套件庫 ``` sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm ``` * Nginx 套件庫 ``` sudo vi /etc/yum.repos.d/nginx.repo ```  * 允許防火牆讓 HTTP、HTTPS 封包通過 ``` sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload ``` * 直接啟動服務,並讓它在開機後自動啟動 ``` sudo systemctl restart nginx sudo systemctl enable nginx ``` * 修改預設主站台設定檔 ``` sudo vi /etc/nginx/conf.d/default.conf ``` 改成下列內容,啟用 PHP 的支援。 server { listen **8080**;//這裡修改成網路登入的port server_name localhost; charset utf-8; access_log /var/log/nginx/access.log main; root /usr/share/nginx/html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } * 打開主目錄的存取權限 ``` sudo chcon -R -t httpd_sys_rw_content_t /usr/share/nginx/html ``` * 讓新的設定值生效 `sudo systemctl reload nginx` 因為Nginx 跟 Apache 不同,必須配合 PHP-FPM 來啟用 PHP 的支援。 * 修改 PHP 的主設定檔 `sudo vi /etc/opt/remi/php70/php.ini` cgi.fix_pathinfo=1,將 1 改成 0 * 修改 PHP-FPM 的主設定檔 `sudo vi /etc/opt/remi/php70/php-fpm.d/www.conf` * 啟動 PHP-FPM,並讓它在開機後自動啟動 `sudo systemctl restart php70-php-fpm sudo systemctl enable php70-php-fpm` * 預設站台的根目錄 /usr/share/nginx/html 下面,建立一個 PHP 檔案 `sudo vi /usr/share/nginx/html/info.php` 就加入這一行指令即可 `<?php phpinfo(); ?>` MariaDB也在上一次做了,但這裡需要做相容設定 * 為了讓 PHP 可以連接 MariaDB,要再額外安裝 PHP 的模組 `sudo yum -y install php70-php-mysqlnd` * 重新啟動 PHP-FPM `sudo systemctl restart php70-php-fpm` * 照理來講到這裡就可以開啟了 http:// ip addr :8080(port)/info.php  * 但假如網頁跑不出來,可能是防火牆的問題 `firewall-cmd --permanent --add-port=8080/tcp` * 然後重啟防火牆 ``` systemctl restart firewalld ``` 就可以了
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up