ubuntu24.04 编译安装PHP7.4
先安装依赖包(原本是centos上安装依赖,让chatgpt转换了下对应的ubutnu下包名,如果编译过程有缺失,按报错提示再安装下)
apt install zlib1g zlib1g-dev libpcre3 libpcre3-dev libfreetype6 \
libfreetype6-dev libssl-dev libcurl4-openssl-dev libxslt1-dev libgd-dev libc6-dev \
libglib2.0-0 libglib2.0-dev libmcrypt-dev libmhash-dev libicu-dev libncurses5-dev \
libjpeg-dev libpng-dev libxml2-dev libbz2-dev libsqlite3-dev libonig-dev \
imagemagick libmagickwand-dev unixodbc unixodbc-dev
安装liviconv 1.17(ubuntu24.04可略过)
wget https://jinchuang.org/novel/php/libiconv-1.17.tar.gz
tar xf libiconv-1.17.tar.gz
cd libiconv-1.17/
./configure --prefix=/usr/lcoal/libiconv && make && make install
echo "/usr/local/libiconv/lib" >>/etc/ld.so.conf
ldconfig
安装openss(系统自带的3.0不行,安装3.3里面包含1.1的库)
wget https://github.com/openssl/openssl/releases/download/openssl-3.3.1/openssl-3.3.1.tar.gz
tar -xvf openssl-3.3.1.tar.gz
cd openssl-3.3.1/
./Configure --prefix=/opt/openssl --openssldir=/opt/openssl -fPIC -shared linux-x86_64
make -j4 && make install
设置pkgconfig,为默认openssl.cnf设置ENV
echo 'export PKG_CONFIG_PATH=/opt/openssl/lib/pkgconfig' >>/etc/profile
echo 'export OPENSSL_CONF=/usr/lib/ssl/openssl.cnf' >>/etc/profile
source /etc/profile
php安装
wget https://www.php.net/distributions/php-7.4.33.tar.bz2
解压进入php-7.4.33目录
./configure --prefix=/usr/local/php --enable-fpm --enable-gd --with-webp --with-jpeg --with-freetype --enable-intl --enable-pcntl --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-curl --enable-soap --with-openssl-dir=/opt/openssl --with-zip --enable-ftp --enable-xml --with-zlib --enable-sockets --enable-mbstring --with-fpm-user=www --with-fpm-group=web
配置文件
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
cp php.ini-production /usr/local/php74/etc/php.ini
cd /usr/local/php74/etc/
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d/
cp www.conf.default www.conf
增加启动服务
systemctl enable php-fpm
启停命令
systemctl start php-fpm
systemctl stop php-fpm
systemctl status php-fpm
修改启动器设置
nano /usr/lib/systemd/system/php-fpm.service
把
ProtectSystem=full
改成
ProtectSystem=false
然后重新加载服务
systemctl daemon-reload
systemctl stop php-fpm
systemctl start php-fpm
systemctl status php-fpm
补充
如果安装完成后openssl扩展不能正常启用,说明php编译安装时调用的openssl-3.3.1也没能正常编译成功
请看:ubuntu24.04 php7.4.33编译安装openssl(动态扩展)