CentOS 7 安裝 Nginx、MySQL/MariaDB、PHP5.6,架設 LEMP 網頁伺服器

架設 LEMP 網頁伺服器安裝紀錄

1)時區設定

查看本機時區

date 

設定時區為亞洲的台北:

sudo timedatectl set-timezone Asia/Taipei

[root@localhost /]# date
Mon Jun  1 18:30:14 EDT 2020
[root@localhost /]# sudo timedatectl set-timezone Asia/Taipei
[root@localhost /]# date
Tue Jun  2 06:55:28 CST 2020


2)更新系統套件

sudo yum upgrade


3)啟用 EPEL

建議啟用,有許多的套件只有 EPEL 中才有。

sudo yum install epel-release

sudo yum update


4)安裝 Nginx

安裝 Nginx 伺服器

sudo yum install nginx

or

sudo yum install nginx -y

啟動 Nginx 服務

sudo systemctl start nginx

檢查 Nginx 是否正常啟動

sudo systemctl status nginx

永久啟用 Nginx 服務,讓重新開機後可自動啟動

sudo systemctl enable nginx

5)測試Nginx是否正常

/usr/share/nginx/html

5-1)查看本機 IP

hostname -I

5-2)在本機安裝瀏覽器(文字界面下,如何瀏覽網頁?)

CentOS下使用控制台Web瀏覽器Links

5-2-1)安裝Links

yum install links

5-2-2)使用Links

links 連結網址

例如 : links 192.168.1.50

5-2-3)Links的基本操作

Esc鍵

調出Links頂部選單。

方向鍵

選擇不同的項目,展示下拉選單或者翻頁。

Q鍵

退出Links。


6)安裝 MySQL/MariaDB

6-1)安裝 MariaDB

yum install mariadb-server mariadb

or

sudo yum install mariadb-server -y

6-2)啟動 MariaDB 服務,並設定開機自動啟動

systemctl start mariadb

systemctl enable mariadb

6-3)強化 MySQL/MariaDB 資料庫設定的安全性

mysql_secure_installation

6-4)

安裝好 MariaDB 資料庫之後,檢查一下 /etc/my.cnf 設定檔,看看 bind-address 是否有指定為 127.0.0.1,如果沒有這行的話,就自己加上去。

若沒有指定 bind-address 的話,MariaDB 預設會傾聽所有的 IP 位址,如果系統又沒有設定防火牆,就會有被攻擊的風險,所以這一行一定要加。


7)安裝 PHP 5.6 PHP 7

7-1)安裝 SCL

you must use the Software Collections (SCL)

sudo yum install centos-release-scl

7-2)安裝 RedHat 官方提供的 PHP 5.6 PHP 7

sudo yum install rh-php56 rh-php56-php rh-php56-php-gd rh-php56-php-mbstring

This collection is EOL since April 2018.

rh-php56 have reached its end of life in April 2018

PHP5.6已經無法下載安裝

sudo yum install rh-php71 rh-php71-php-fpm rh-php71-php-mysqlnd

7-3)設定 PHP-FPM

編輯 /etc/opt/rh/rh-php71/php-fpm.d/www.conf 

確認 listen 的設定

sudo vi /etc/opt/rh/rh-php71/php-fpm.d/www.conf 

7-4)啟動 PHP-FPM 服務,並設定開機自動啟動

sudo systemctl start rh-php71-php-fpm

sudo systemctl enable rh-php71-php-fpm

編輯 /etc/opt/rh/rh-php71/php.ini 設定檔,修正 cgi.fix_pathinfo 漏洞,將 cgi.fix_pathinfo 設為 0。


8)設定 Nginx 與 PHP 7

設定 /etc/nginx/nginx.conf 設定檔

所有設定都調整好之後,重新啟動 PHP-FPM 與 Nginx 服務

sudo systemctl restart rh-php71-php-fpm

sudo systemctl restart nginx


0 條回復   |  直到 2020-6-2 | 1141 次瀏覽




熱門評論


登入後才可發表內容