编译安装PHP8
Cenots7 编译安装 PHP8.0
1. 安装依赖
yum -y install libxml2-devel sqlite-devel bzip2-devel libcurl-devel libpng-devel libjpeg-devel freetype-devel libicu-devel oniguruma-devel libxslt-devel
libzip 可能会报错
1.1 编译安装libzip-devel依赖包
1. 下载包
mkdir /usr/local/soft/
cd /usr/local/soft/php-8.0.0
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
2. 解压
tar -zxvf libzip-1.2.0.tar.gz
3. 编译安装
cd libzip-1.2.0
./configure
make && make install
4. 配置环境变量
vim /etc/profile.d/libzip.sh
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
source /etc/profile
2. 安装php8.0
1. 下载 解压
wget https://www.php.net/distributions/php-8.0.0.tar.gz
tar -zxvf php-8.0.0.tar.gz
2. 编译安装 (安装目录可以自己替换 )
cd /php-8.0.0
./configure --prefix=/usr/local/php-8.0.0 --with-config-file-path=/usr/local/php-8.0.0/etc --with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xsl --with-zlib --with-zip -with-bz2 --with-iconv --enable-fpm --enable-pdo --enable-bcmath --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-sysvsem --enable-cli --enable-opcache --enable-intl --enable-calendar --enable-static --enable-mysqlnd --disable-fileinfo
make
make install
3. 配置php环境变量
vim /etc/profile
(新增一行)
alias php8.0.0='/usr/local/php-8.0.0/bin/php'
(载入)
source /etc/profile
4. 查看版本
php8.0.0 -v
3. 配置PHP文件
1. 配置php.ini 目前在php-8.0.0 目录下
cd /usr/local/soft/php-8.0.0
cp php.ini-production /usr/local/php-8.0.0/etc/php.ini
2. 配置www.conf
cd /usr/local/php-8.0.0/etc/php-fpm.d/
cp www.conf.default www.conf
3. 配置php-fpm
cd /usr/local/php-8.0.0/etc/
cp php-fpm.conf.default php-fpm.conf
4. 修改php-fpm启动端口
4. 配置PHP-FPM 开启自启动
1. 新增文件 (php8.0.0-fpm 这个就是服务启动的名称)
touch /usr/lib/systemd/system/php8.0.0-fpm.service
2. 打开文件新增并保持
vim /usr/lib/systemd/system/php8.0.0-fpm.service
3. 新增内容
# It's not recommended to modify this file in-place, because it
# # will be overwritten during upgrades. If you want to customize,
# # the best way is to use the "systemctl edit" command.
#
[Unit]
Description=The PHP8.0.0 FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/usr/local/php-8.0.0/var/run/php-fpm.pid
ExecStart=/usr/local/php-8.0.0/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php-8.0.0/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
4. 开启启动,启动,ti
systemctl daemon-reload
systemctl enable php8.0.0-fpm
systemctl start php8.0.0-fpm
systemctl status php8.0.0-fpm