From: https://www.jianshu.com/p/04e8ad506ad7
更新软件到最新
yum update
下载php源码并解压
wget https://www.php.net/distributions/php-8.0.0.tar.gz
tar-xvzf php-8.0.0.tar.gz
cd php-8.0.0
安装gcc软件
yum install gcc gcc-c++ make
安装php依赖软件
yum install libxml2 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软件
yum install https://rpms.remirepo.net/enterprise/8/remi/x86_64/oniguruma5php-6.9.8-1.el8.remi.x86_64.rpm
yum install https://rpms.remirepo.net/enterprise/8/remi/x86_64/oniguruma5php-devel-6.9.8-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 #指定同时运行的作业数量,让尽可能多的作业同时运行。如果有一个以上的“-j”选项,最后一个选项是有效的。
安装php
make install
添加php.ini配置文件
cp php.ini-production /usr/local/php/lib/php.ini
以下操作为配置php
添加用户
useradd www
修改php-fpm.conf
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d
cp www.conf.default www.conf
编辑www.conf文件,根据自己的服务器配置修改以下配置
pm.max_children=10
pm.start_servers=5
pm.min_spare_servers=4
pm.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/lib
vim php.ini
修改内存限制
memory_limit=512M
修改上传文件限制
post_max_size=512M
upload_max_filesize=512M
启用OPcache 和 JIT; OPcache [1] 通过将 PHP 脚本预编译的字节码存储到共享内存中来提升 PHP 的性能, 存储预编译字节码的好处就是 省去了每次加载和解析 PHP 脚本的开销。
移除注释
;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
在[opcache]添加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=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm –nodaemonize –fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
保存退出后执行
systemctl enable php-fpm
systemctl start php-fpm
查看运行状态
systemctl status php-fpm
Linux命令行
ln -s /usr/local/php/bin/php /usr/bin/php
安装libphp.so
sudo yum install http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/php-common-8.0.20-1.module_el8.7.0+1191+c110972c.x86_64.rpm
sudo yum install http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/php-embedded-8.0.20-1.module_el8.7.0+1191+c110972c.x86_64.rpm
接着安装和配置httpd