Ubuntu编译安装php7.4
[root@ubuntu2004 php-7.4.30]#apt install gcc libssl-dev libxml2-dev libsqlite3-dev libcurl3-dev libxml2 sqlite3
[root@ubuntu2004 php-7.4.30]#./configure --prefix=/apps/php74 --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-zlib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfo
[root@ubuntu2004 php-7.4.30]#make clean #如果出错,最好清除下编译信息,在重新编译
[root@ubuntu2004 php-7.4.30]#make && make install
[root@ubuntu2004 php-7.4.30]#/apps/php74/bin/php --version #测试 能看到版本表示已安装成功
PHP 7.4.30 (cli) (built: Oct 22 2022 09:37:13) ( ZTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
[root@ubuntu2004 php-7.4.30]#cp php.ini-production /apps/php74/etc/php.ini #生成php.ini
[root@ubuntu2004 php-7.4.30]#cd /apps/php74/etc/php-fpm.d/
[root@ubuntu2004 php-fpm.d]#cp www.conf.default www.conf #生成www.conf
[root@ubuntu2004 php-fpm.d]#vim /apps/php74/etc/php-fpm.d/www.conf #配置用户
user = nginx #指定用户为nginx
group = nginx
[root@ubuntu2004 php-fpm.d]#useradd -r -u 888 nginx
[root@ubuntu2004 php-fpm.d]#cd /apps/php74/etc
[root@ubuntu2004 etc]#cp php-fpm.conf.default php-fpm.conf #生成php-fpm.conf
#生成启动文件
[root@ubuntu2004 etc]#cp /usr/local/src/php-7.4.30/sapi/fpm/php-fpm.service /usr/lib/systemd/system/
#做一下修改
[root@ubuntu2004 etc]#vim /usr/lib/systemd/system/php-fpm.service
# Mounts the /usr, /boot, and /etc directories read-only for processes invoked by this unit.
#ProtectSystem=full
ProtectSystem=false
#说明:把 ProtectSystem=full修改为: ProtectSystem=false 如果不做修改会报错
[root@ubuntu2004 etc]#systemctl daemon-reload
[root@ubuntu2004 etc]#systemctl start php-fpm.service
[root@ubuntu2004 etc]#systemctl status php-fpm.service
[root@ubuntu2004 php-fpm.d]#ps aux | grep php
出现的错误
checking for libxml-2.0 >= 2.7.6... no
configure: error: in `/usr/local/src/php-7.4.30':
configure: error: The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.
解决办法:
[root@ubuntu2004 php-7.4.30]#apt install pkg-config Libxml2-dev -y
#如果libxml2无法安装,需要到官网下载自行编译:
https://gitlab.gnome.org/GNOME/libxml2/-/releases
tar -zxvf v2.9.9.tar.gz -C /usr/local/src
cd /usr/local/src/
./autogen.sh
./configure --prefix=/usr/local/libxml2 && make -j4 && make install
出现的错误
configure: error: Package requirements (zlib >= 1.2.0.4) were not met:
No package 'zlib' found
解决办法:
[root@ubuntu2004 php-7.4.30]#apt install zlib1g-dev -y
出现的错误
checking for oniguruma... no
configure: error: Package requirements (oniguruma) were not met:
No package 'oniguruma' found
解决办法:
[root@ubuntu2004 php-7.4.30]#apt install libonig-dev -y标签:fpm,ubuntu2004,--,php7.4,编译,7.4,Ubuntu,php,root From: https://blog.51cto.com/dayu/5785678