国产银河麒麟服务器版(Host)V10 编译安装PHP8.2
本文记录了国产银河麒麟操作系统服务器版V10编译安装PHP8.2的过程
软件准备
国产银河麒麟操作系统服务器版: 下载地址
PHP8.2源码包
PHP使用8.2非线程安全版:下载地址
系统基础软件
#更新系统
yum update -y
#安装常用软件
yum install vim htop lrzsz nc \
wget curl mtr bash-completion -y
#编译软件
yum install gcc make libzip autoconf -y
#这些是编译PHP扩展时依赖的组件,提前安装好
yum -y install libzip \
libzip-devel \
libxml2-devel \
openssl-devel \
sqlite-devel \
bzip2-devel \
libcurl-devel \
gmp-devel \
oniguruma-devel \
readline-devel \
libxslt-devel \
libpng-devel \
libjpeg-devel \
freetype-devel
编译安装PHP8.2
cd /usr/local/src
wget https://www.php.net/distributions/php-8.2.26.tar.gz
tar -zxvf php-8.2.26.tar.gz
cd php-8.2.26
./configure --prefix=/usr/local/php82 --with-config-file-path=/etc/php82 --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --disable-debug --disable-rpath --enable-shared --enable-soap --with-openssl --with-mhash --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --enable-ftp --enable-gd --with-jpeg --with-gettext --with-freetype --with-openssl-dir=/usr/bin/openssl --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-mbstring --enable-mbregex --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-xsl --with-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache
make && make install
设置PHP环境变量路径
#安装完成后拷贝和修改php.ini文件
cp /usr/local/src/php-8.2.26/php.ini-development /usr/local/php82/etc/php.ini
ln -s /usr/local/php82/etc /etc/php82
设置php-fpm systemctl开机启动项
cat > /lib/systemd/system/php-fpm.service<<EOF
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
#Type=notify
Type=forking
PIDFile=/usr/local/php82/var/run/php-fpm.pid
#ExecStart=/usr/local/php82/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php82/etc/php-fpm.conf
ExecStart=/usr/local/php82/sbin/php-fpm --fpm-config /usr/local/php82/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
EOF
systemctl enable php-fpm
systemctl start php-fpm
其中需要注意的是:/usr/local/php82/var/run/php-fpm.pid
这个需要和你自己的PHP安装路径保持一致
拷贝和生成php-fpm.conf文件,以及 php-fpm.d/www.conf文件
cd /usr/local/php82/etc
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
- 配置php-fpm.conf文件中的pid路径,使其和 /lib/systemd/system/php-fpm.service 文件中的 PIDFile 值保持一致
- 配置 php-fpm.d/www.conf
对接设置nginx,使之能够调用php-fpm处理php请求
location ~ \.php$ {
fastcgi_pass php-fpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
设置 nginx配置文件中的 php-fpm.conf
cat /etc/nginx/conf.d/php-fpm.conf
upstream php-fpm {
server unix:/usr/local/php82/var/run/www.sock;
}
#修改完成后重载 nginx
nginx -t && nginx -s reload
至此配置完毕。请自行测试。
评论 (0)