Centos8编译安装PHP8

更新软件到最新

yum update

下载php源码并解压

wgethttps://www.php.net/distributions/php-8.0.0.tar.gztar-xvzf php-8.0.0.tar.gzcdphp-8.0.0

安装gcc软件

yuminstallgcc gcc-c++make

安装php依赖软件

yuminstalllibxml2 libxml2-devel openssl openssl-devel freetype freetype-devel libzip libzip-devel sqlite sqlite-devel gd gd-devel libcurl-devel libicu libicu-devel libxslt libxslt-devel

安装oniguruma软件

yuminstallhttps://rpms.remirepo.net/enterprise/8/remi/x86_64/oniguruma5php-6.9.6-1.el8.remi.x86_64.rpmyuminstallhttps://rpms.remirepo.net/enterprise/8/remi/x86_64/oniguruma5php-devel-6.9.6-1.el8.remi.x86_64.rpm

配置编译

./configure\--prefix=/usr/local/php\--with-zlib-dir\--enable-mbstring\--enable-soap\--enable-calendar\--with-curl\--disable-rpath\--enable-gd\--enable-gd-jis-conv\--with-bz2\--with-zlib\--enable-sockets\--enable-sysvsem\--enable-sysvshm\--enable-pcntl\--enable-mbregex\--enable-exif\--enable-bcmath\--with-mhash\--with-pdo-mysql\--with-mysqli\--with-openssl\--with-fpm-user=www\--with-fpm-group=www\--with-libdir=/lib/x86_64-linux-gnu/\--enable-ftp\--with-gettext\--with-xsl\--enable-opcache\--enable-fpm\--with-iconv\--with-zip\--with-pear\--with-freetype\--enable-intl

开始编译

make-j4

安装php

makeinstall

添加php.ini配置文件

cpphp.ini-production /usr/local/php/lib/php.ini

以下操作为配置php

添加用户

useraddwww

修改php-fpm.conf

cd/usr/local/php/etccpphp-fpm.conf.default php-fpm.confcdphp-fpm.dcpwww.conf.default www.conf

编辑www.conf文件,根据自己的服务器配置修改以下配置

pm.max_children=10pm.start_servers=5pm.min_spare_servers=4pm.max_spare_servers=7

移除前面的注释

;env[HOSTNAME] = $HOSTNAME;env[PATH] = /usr/local/bin:/usr/bin:/bin;env[TMP] = /tmp;env[TMPDIR] = /tmp;env[TEMP] = /tmp

修改php配置文件

cd/usr/local/php/libvimphp.ini

修改内存限制

memory_limit=512M

修改上传文件限制

post_max_size=512Mupload_max_filesize=512M

启用OPcache 和 JIT

;zend_extension=opcache[opcache]opcache.enable=1;opcache.memory_consumption=128;opcache.interned_strings_buffer=8;opcache.max_accelerated_files=10000;opcache.validate_timestamps=1

添加jit支持

opcache.jit_buffer_size=128M

注意:虚拟机里可能启动时报错。

设置php-fpm开机启动

vim/usr/lib/systemd/system/php-fpm.service

其内容为

[Unit]Description=The PHP FastCGI Process ManagerAfter=network.target[Service]Type=simplePIDFile=/usr/local/php/var/run/php-fpm.pidExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.confExecReload=/bin/kill -USR2 $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target

保存退出后执行

systemctlenablephp-fpmsystemctl start php-fpm

查看运行状态

systemctl status php-fpm

https://www.z1xz.com/article/unzyhcwtoyzhallv86ouoakmjztc7iec.html

你可能感兴趣的:(Centos8编译安装PHP8)