下载安装包以及组件
wget https://www.php.NET/distributions/php-8.0.0.tar.bz2
wget https://github.com/phpredis/phpredis/archive/5.3.2.tar.gz -O phpredis-5.3.2.tar.gz
wget https://github.com/swoole/swoole-src/archive/v4.5.9.tar.gz -O swoole-src-4.5.9.tar.gz
wget http://pecl.php.net/get/mcrypt-1.0.3.tgz
wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
wget https://github.com/Kitware/CMake/releases/download/v3.16.0/cmake-3.17.2.tar.gz
wget https://libzip.org/download/libzip-1.5.2.tar.xz
wget https://github.com/Kitware/CMake/releases/download/v3.19.4/cmake-3.19.4.tar.gz
分别解压安装
------- 安装cmake -------
tar -zxvf cmake-3.17.2.tar.gz && cd cmake-3.17.2
./bootstrap && gmake && gmake install
cmake -version
------- 安装libiconv -----
tar zxvf libiconv-1.16.tar.gz && cd libiconv-1.16 && ./configure --prefix=/usr/local/libiconv && make && make install
ln -s /usr/local/libiconv/lib/libiconv.so.2 /usr/lib64/libiconv.so.2
------ 安装libzip ------
tar xvJf libzip-1.5.2.tar.xz && cd libzip-1.5.2
mkdir build && cd build/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/libzip ..
make && make install
------ 安装PHP8.0 ------
./configure
--prefix=/usr/local/php8 --exec-prefix=/usr/local/php8 --bindir=/usr/local/php8/bin --sbindir=/usr/local/php8/sbin
--includedir=/usr/local/php8/include --libdir=/usr/local/php8/lib/php --mandir=/usr/local/php8/php/man
--with-config-file-path=/usr/local/php8/etc
--with-MySQL-sock=/dev/shm/mysql.sock --with-mysqli=shared,mysqlnd --with-mhash
--with-openssl --with-curl
--with-pdo-mysql=shared,mysqlnd --with-iconv --with-zlib
--enable-inline-optimization
--disable-debug --disable-rpath --enable-shared
--enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp
--enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session
--enable-opcache --enable-fpm --without-gdbm --disable-fileinfo --with-fpm-user=www --with-fpm-group=www
make && make install
复制配置文件
cp php.ini-production /usr/local/php8/etc/php.ini
cp sapi/fpm/php-fpm.service /lib/systemd/system/php-fpm.service
cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
配置php-fpm.conf文件
pid = /run/php-fpm.pid
error_log = /var/log/php/fpm-error.log
include=/usr/local/php8/etc/php-fpm.d/*.conf
配置php-fpm.d/www.conf文件
######设置用户和用户组
user = www
group = www
######根据Nginx.conf中的配置fastcgi_pass unix:/dev/shm/php-fpm.sock;设置PHP监听
;listen = 127.0.0.1:9000 #####不建议使用
listen = /dev/shm/php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0777
listen.allowed_clients = /dev/shm/php-fpm.sock
######使用静态进程数max_children=内存/512
pm = static
pm.max_children = 200
pm.max_requests = 0
pm.status_path = /FpmStatus
######开启慢日志
slowlog = /var/log/php/fpm-$pool-slow.log
request_slowlog_timeout = 30s
request_slowlog_trace_depth = 20
request_terminate_timeout = 0
配置php.ini文件
######避免PHP信息暴露在http头中
expose_php = Off
######常用配置
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
display_errors = Off
log_errors = On
html_errors = Off
error_log = /var/log/php/cli-error.log
ignore_repeated_errors = On
ignore_repeated_source = On
memory_limit = 512M
max_execution_time = 600 (0为不限制)
max_input_time = -1
post_max_size = 128M
max_input_vars = 1000000
file_uploads = On
upload_tmp_dir = /tmp/www
upload_max_filesize = 100M
session.gc_maxlifetime = 14400
default_socket_timeout = 600 (-1为不限制)
######设置PHP的扩展
extension_dir = "/usr/local/php8/lib/php/extensions/以安装目录为准"
zend_extension=opcache.so
extension=mcrypt.so
extension=mysqli.so
extension=pdo_mysql.so
extension=redis.so
extension=swoole.so
######设置PHP的时区
date.timezone = "Asia/Shanghai"
######开启opcache
[opcache]
opcache.enable=1
opcache.enable_cli=1
#####开启JIT
opcache.jit_buffer_size=128M
opcache.jit=1205
opcache.huge_code_pages=1
opcache.file_cache=/tmp
######设置PHP脚本允许访问的目录(需要根据实际情况配置)
;open_basedir = /usr/share/nginx/html;
----- 使用redis的session才需要配置 ----
session.save_handler = redis
session.save_path = "tcp://*****.aliyuncs.com:6379?
auth=******"
[MySQLi]
mysqli.reconnect = On
最后配置文件权限
mkdir -p /var/log/php/
mkdir -p /var/log/php-fpm/
mkdir -p /run/php-fpm/
mkdir -p /var/lib/php/session
touch /dev/shm/php-fpm.sock
touch /run/php-fpm.pid
chown www:www /dev/shm/php-fpm.sock
chmod 777 /dev/shm/php-fpm.sock
chown -R www:www /var/lib/php
######配置PHP连接MySQL的端口监听文件(没有安装MySQL的可以先不监听)
touch /dev/shm/mysql.sock
chmod 777 /dev/shm/mysql.sock
测试php-fpm配置,设置开机自启动
######测试配置
/usr/local/php8/sbin/php-fpm -t
######修改文件权限
chmod 745 /lib/systemd/system/php-fpm.service
######设置为开机启动
systemctl enable php-fpm.service
######启动php-fpm
systemctl start php-fpm.service
把PHP加入环境变量
vi /etc/profile 底部加入
export PATH=$PATH:/usr/local/php8/bin
source /etc/profile