当前位置: 首页 > 工具软件 > Pho-PHP > 使用案例 >

PHP源码编译

龙俊美
2023-12-01

1.安装编译环境

yum -y install gcc gcc-c++ glibc automake autoconf libtool make 

2.创建安装目录

mkdir -p /usr/local/php7

3.安装编译php的依赖库

yum -y install libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs  e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel 

4.创建安装包目录

mkdir -p /usr/local/src/php7

5.安装cmake

cd /usr/local/src/php7
yum insatll -y wget  
wget https://github.com/kitware/CMake/releases/download/v3.14.5/cmake-3.14.5.tar.gz
tar -zxvf cmake-3.14.5.tar.gz
cd cmake-3.14.5
./bootstrap
gmake
gmake install
cmake -version

6.安装libzip

cd /usr/local/src/php7
wget --no-check-certificate https://libzip.org/download/libzip-1.8.0.tar.gz
tar -zxvf libzip-1.8.0.tar.gz
cd libzip-1.8.0
mkdir build
cd build
cmake ..
make -j2
make test
make install

7.编译安装php

cd /usr/local/src/php7
wget https://www.php.net/distributions/php-7.3.33.tar.gz
tar -zxvf php-7.3.33.tar.gz
cd php-7.3.33
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7 --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
make && make install
/usr/local/php7/sbin/php-fpm    #启动会报错,需要修改配置文件

8.修改配置文件

cp /usr/local/src/php7/php-7.3.33/php.ini-production  /usr/local/php7/etc/php.ini
cd /usr/local/php7/etc/php-fpm.conf.default  /usr/local/php7/etc/php-fpm.conf
vi /usr/local/php7/etc/php-fpm.conf
搜索pid并修改成如下内容
pid = /usr/local/php7/var/run/php-fpm.pid
保存,退出
cd /usr/local/php7/etc/php-fpm.d
cp www.conf.default nginx.conf
useradd nginx
vi nginx.conf 

检查用户,组是否是nginx。不是,就进行修改。
检查是否在监听本机的9000端口。

/usr/local/php7/sbin/php-fpm   #启动php
lsof -i:9000         #再次检查服务是否起来

9.配置php-fpm系统环境变量

vi /etc/profile
export PHP_HOME=/usr/local/php7
export PATH=$PATH:$PHP_HOME/bin:$PHP_HOME/sbin

10.重载环境变量

source /etc/profile

11.系统配置systemctl版的启动与自启

vi /lib/systemd/system/php-fpm.service
[Unit]
Description=php-fpm
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/php7/sbin/php-fpm             
ExecStop=/bin/pkill -9 php-fpm
PrivateTmp=true

[Install]
WantedBy=multi-user.target
保存,退出
systemctl daemon-reload
pkill php-fpm
systemctl start php-fpm
systemctl enable php-fpm
systemctl list-units --type=service   #查看所有已开启的服务

感谢大家,点赞,收藏,关注,评论!

 类似资料: