ติดตั้งและคอนฟิก nginx+php บน CentOS 8
ทดสอบติดตั้งบน centos 8.1.1911
ลง nginx
yum install nginx จากนั้น มีคำสั่ง start enable status ดังนี้
# systemctl enable nginx # systemctl start nginx # systemctl status nginx จากนั้นเปิด firewall
# firewall-cmd --permanent --zone=public --add-service=http # firewall-cmd --permanent --zone=public --add-service=https # firewall-cmd --reload หรือจะ disable ไปเลยด้วยคำสั่ง systemctl stop firewalld systemctl disable firewalld
ต่อมาติดตั้ง php
yum install php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring
แล้วไปตั้งค่า
/etc/php-fpm.d/www.conf ที่ แก้ตามนี้
user = nginx group = nginx
listen = /run/php-fpm/www.sock
จากนั้น restart ทั้ง 2 service
systemctl restart nginx php-fpm จากนั้นทดสอบ
echo "<?php phpinfo() ?>" > /usr/share/nginx/html/info.php แล้วก็ลองเข้าหน้า เว็บดูนะ เบื้องต้นจะติดปัญหาเรื่อง เปิด index.php ไม่ได้ให้ไปทำที่
vi /etc/nginx/nginx.conf แล้วไปที่
location / {
index index.php index.html index.htm;
try_files $uri $uri/ =404;
}
ตอนนี้พึ่งเริ่มเล่น centos 8 หากมีอะไรเพิ่มเติมจะมา up นะ
เคยเจอ error ของ session php ว่า PHP message: PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0" while reading upstream, client: 10.254.172.52, server: _, request: "GET /phpPgAdmin/redirect.php?subject=server&server=127.0.0.1%3A5432%3Aallow HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "10.254.172.6", referrer: "http://10.254.172.6/phpPgAdmin/browser.php" เจอใน log /var/log/nginx/error.log วิธีแก้คือ ไปสร้าง var/lib/php/session เพราะไม่มีอยู่ จากนั้น ให้ chmod 777 session ด้วย และทดสอบใช้อีกที ในส่วนของ log error ดูที่ php-fpm ไม่ได้ ต้องดูที่ nginx อยู่ที่ /var/log/nginx/error.log