Ubuntu 22.04.2 LTS编译安装PHP-7.2.34与Nginx1.22.0

Ubuntu 22.04.2 LTS编译安装PHP-7.2.34与Nginx1.22.0

  • 环境介绍
  • 所需文件
  • 安装步骤
    • 解压
    • 安装编译所需环境
    • 编译安装Nginx
    • 编译安装openssl
    • 编译安装php
    • 复制php.ini-production到/usr/local/php/etc/php.ini
  • 配置nginx与php
    • 将nginx与php加入到systemctl
      • php
      • nginx
      • 重新加载systemd配置文件
    • 取消注释location段并添加index.php
    • 修改php-fpm.conf.default为php-fpm.conf
    • 修改www.conf.default为www.conf
    • 修改fastcgi_params
    • 创建nobody用户组
    • 开启nginx和php-fpm服务

环境介绍

Ubuntu版本:22.04.2 LTS
Nginx版本:1.22.0
PHP版本:7.2.34

所需文件

Ubuntu 22.04.2 LTS编译安装PHP-7.2.34与Nginx1.22.0_第1张图片

安装步骤

解压

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

编译安装Nginx

./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

编译安装openssl

./config --prefix=/usr/local/openssl && make && make install

编译安装php

./configure --prefix=/usr/local/php --enable-fpm --with-curl --with-openssl=/usr/local/openssl --with-mysqli --with-pdo-mysql && make && make install

复制php.ini-production到/usr/local/php/etc/php.ini

cp php.ini-production /usr/local/php/etc/php.ini

配置nginx与php

将nginx与php加入到systemctl

php

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

nginx

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

重新加载systemd配置文件

systemctl daemon-reload

取消注释location段并添加index.php

vim /usr/local/nginx/conf/nginx.conf

Ubuntu 22.04.2 LTS编译安装PHP-7.2.34与Nginx1.22.0_第2张图片
Ubuntu 22.04.2 LTS编译安装PHP-7.2.34与Nginx1.22.0_第3张图片

修改php-fpm.conf.default为php-fpm.conf

mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

修改www.conf.default为www.conf

mv /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

修改fastcgi_params

vim /usr/local/nginx/conf/fastcgi_params
#末尾添加如下内容
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

创建nobody用户组

groupadd nobody

开启nginx和php-fpm服务

systemctl start php-fpm.service
systemctl start nginx.service

你可能感兴趣的:(服务器部署,php,ubuntu,linux)