1 Create dedicated users for PHP-FPM and Nginx
groupadd www
useradd -s /sbin/nologin www -g www -M-s parameter means that login is not allowed, -g parameter is assigned to www group, and -M means that user directory is not created.
2 Install php
CentOS8 comes with PHP7.2 version, which is relatively new. It does not require the help of a third-party source to install it. Moreover, the PHP modules that CentOS8 come with are relatively sufficient. Use the following command to see all PHP-related packages:
yum search php installation module
yum -y install php php-mysqlnd php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-zip php-cli php-fpm php-gd php-mysqlnd php-mbstring php-opcache php-pdo php-json
Configure PHP-FPM
After installation, we need to configure PHP-FPM a little to make it work better with Nginx.
Edit the /etc/php-fpm.d/www.conf file. There are two things to note about in this file. One of them is the user running PHP-FPM and the corresponding user group:
vim /etc/php-fpm.d/www.conf
user=www
group=www
listen=/run/php-fpm/www.sock modify the above file and change the user and group fields from apache to the www we created above.
Another one is the configuration item listen=/run/php-fpm/www.sock. This line configures PHP-FPM running mode and corresponding file directory. We will use it when configuring Nginx later.
start up:
systemctl start php-fpm
Nginx installation and configuration
Installing Nginx is very simple. The CentOS8 system comes with it and only requires one line of commands to install it:
yum install nginx starts:
The basic configuration of systemctl start nginx is also very simple. At this point, we only need to slightly change the Nginx configuration file. The Nginx configuration file is in /etc/nginx/nginx.conf. This configuration file can configure all functions of Nginx, including other configuration files that are also loaded through this file. Open its configuration file, modify the user field, and add a few lines of configuration that may be used:
vim /etc/nginx/nginx.conf
user=www www;
//Turn on gzip compression
gzip on;
//Close the display of Nginx version number
server_tokens off;
//Increase the maximum upload file size
client_max_body_size 8M;
MySQL 8 installation
Install MySQL8 and corresponding tools:
yum install mysql mysql-server starts MySQL server:
systemctl start mysqld
Initialization Command
mysql_secure_installation
Add a separate Nginx configuration file for the website
In fact, each distribution of the Nginx configuration file for placing the website has its own methods, some are placed in /etc/nginx/conf.d/
vim /etc/nginx/conf.d/ln.conf
server
{
listen 80;
listen 8085;
listen [:]:8085;
listen [:]:80;
server_name 192.168.123.98;
index index.php index.html index.htm default.php default.htm default.html;
root /var/www/ln/public; #Run directory
include /etc/nginx/default.d/*.conf;
index index.php index.html index.htm;
location ~ \.(php|phar)(/.*)?$ { #php access configuration
fastcgi_split_path_info ^(.+\.(?php|phar))(/.*)$;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/run/php-fpm/www.sock;
}
#Pseudo-static configuration
location/{
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
access_log /var/log/nginx/ln.log;
error_log /var/log/nginx/ln-error.log;
}
The website file directory gives readable and write permissions
chown -R www.www /var/www/ln
FAQ
Cannot parse php file
Configure ln.conf file
include /etc/nginx/default.d/*.conf;
index index.php index.html index.htm;
location ~ \.(php|phar)(/.*)?$ {
fastcgi_split_path_info ^(.+\.(?php|phar))(/.*)$;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/run/php-fpm/www.sock;
}
502
cd /var//run/php-fpm/
chmod -R 777 www.sock
/var/lib/php/session
nginx cannot start
setenforce 0
Recommended Comments