CentOS8.0编译安装PHP7.3.10

下载PHP7.3.10:

wget https://www.php.net/distributions/php-7.3.10.tar.gz

解压缩然后进入源码目录:

tar zxf php-7.3.10.tar.gz
cd php-7.3.10

编译安装:

./configure --prefix=/usr/local/php --with-mysql-sock=/dev/shm/mysql.sock --enable-fpm --with-fpm-user=nobody --with-fpm-group=nobody --with-openssl --with-zlib --with-curl --enable-bcmath --enable-mbstring --enable-exif --with-mysqli --with-jpeg-dir --with-png-dir --with-freetype-dir --with-gd --with-pcre-dir --with-iconv-dir && make && make install

整个过程出现以下报错信息:

configure: error: in `/root/php-7.3.10':
configure: error: no acceptable C compiler found in $PATH
configure: error: libxml2 not found. Please check your libxml2 installation.
configure: error: Cannot find OpenSSL's <evp.h>
configure: error: cURL version 7.15.5 or later is required to compile php with cURL support
configure: error: jpeglib.h not found.
configure: error: png.h not found.
configure: error: freetype-config not found.
-bash: make: command not found

这都是因为缺少相关依赖组件导致的,安装依赖即可:

yum install gcc libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel make

还有这个报错信息:

virtual memory exhausted: Cannot allocate memory
make: *** [Makefile:921: ext/fileinfo/libmagic/apprentice.lo] Error 1

这是因为可用内存不足,分配适当大小的SWAP分区即可:

fallocate -l 512M /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

编译安装完成后,复制/重命名必要的文件:

cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d
cp www.conf.default www.conf
cp /root/php-7.3.10/php.ini-production /usr/local/php/lib/php.ini

编辑www.conf配置文件:

vi www.conf

listen = 127.0.0.1:9000更改为listen = /dev/shm/php-fpm.sock

再找到以下三行,把前面的分号去掉

;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0660

编辑php.ini配置文件,加上一行zend_extension=opcache.so,开启OPcache

vi /usr/local/php/lib/php.ini

启动PHP-FPM

/usr/local/php/sbin/php-fpm

留下评论

电子邮件地址不会被公开。 必填项已用*标注

回到顶部