[CentOS 7] 整合 Nginx、MariaDB、PHP 7 組成 LEMP Server


加入 EPEL 套件庫
sudo yum -y install epel-release


Remi 套件庫
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm



別忘了更新一下所有套件庫的快取資料。
sudo yum -y update



安裝Nginx 

建立
/etc/yum.repos.d/nginx.repo

[nginx] 
name=nginx repo 
baseurl=http://nginx.org/packages/centos/7/$basearch/ 
gpgcheck=0 

yum install nginx 
systemctl start nginx
systemctl enable nginx 
firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --reload


安裝php7

-------------(可忽略本段)-----------

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
yum-config-manager –enable remi-php72 
//現在是7.2.11
yum install php php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-curl php-mbstring

--------(換最新版本)---------
查看當前 PHP 版本

php -v

查看當前 PHP 相關的安装包

yum list installed | grep php


關閉php-fpm 和 nginx 服務

service php-fpm stop 

删除已經安装的 PHP 相關

yum remove php*

#CentOs 7.X: 
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm


CentOs 7.x 的 RPM 源中有 7.2

yum install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-fpm php71w-gd php71w-mbstring php71w-mysqlnd php71w-opcache php71w-pdo php71w-xml php71w-ldap php71w-mcrypt


重新啟動服務
service php-fpm start


------------------------
安裝與設定php-fpm
yum install php-fpm

設定php-fpm


修改 /etc/php-fpm.d/www.conf
修改user和group,為nginx
user = nginx
group = nginx

將以下設定:
user = apache
group = apache
listen = 127.0.0.1:9000
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0660
改為:
user = nginx
group = nginx
listen = /var/run/php-fpm/www.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
建立相關目錄及啟動php-fpm
chown -R nginx.nginx /var/lib/php/session/
若沒有,建立
mkdir /var/run/php-fpm/
chown -R nginx.nginx /var/run/php-fpm/
systemctl start php-fpm
systemctl enable php-fpm

設定Nginx

修改 /etc/nginx/conf.d/default.conf ,以連接php-fpm
server {
listen 80;
server_name localhost;
charset utf-8;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
# deny all;
#}
}
測試語法
nginx -t
重新載入
nginx -s reload
安裝mariadb
yum install mariadb mariadb-server
systemctl start mariadb
systemctl enable mariadb
設定mariadb密碼
mysql_secure_installation
設定 php.ini將cgi.fix_pathinfo=1 改為 cgi.fix_pathinfo=0





留言

這個網誌中的熱門文章

LDAP log紀錄

LDAP 存取控制 slapd.conf(伺服器設定檔)

透過python爬蟲, LINE Notify 通知 (股票) win10排程