Ubuntu版本:22.04.2 LTS
Nginx版本:1.22.0
PHP版本:7.2.34
tar -zxf openssl-1.1.1l.tar.gz
tar -zxf php-7.2.34.tar.gz
tar -zxf nginx-1.22.0.tar.gz
apt -y install gcc make g++ libtool-bin libexpat1-dev build-essential
apt install libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev -y
apt install libxml2-dev libcurl4-openssl-dev -y
apt install pkg-config -y
apt install pkgconf -y
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module && make && make install
./config --prefix=/usr/local/openssl && make && make install
./configure --prefix=/usr/local/php --enable-fpm --with-curl --with-openssl=/usr/local/openssl --with-mysqli --with-pdo-mysql && make && make install
cp php.ini-production /usr/local/php/etc/php.ini
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
vim /usr/local/nginx/conf/nginx.conf
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
mv /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
vim /usr/local/nginx/conf/fastcgi_params
#末尾添加如下内容
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
groupadd nobody
systemctl start php-fpm.service
systemctl start nginx.service