下载地址:https://www.php.net/downloads.php
下载 tar.gz 包。
上传到服务器
解压
tar -xzvf php-8.0.0.tar.gz
之前没安装过php的先安装依赖
yum install openssl-devel gcc gcc-++ gcc-c++ wget make libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel bison autoconf sqlite-devel oniguruma-devel
安装php8.0(选择你们自己的安装位置)
cd php-8.0.0
#选择安装位置等配置
./configure --prefix=/www/server/php/80/ --with-config-file-path=/www/server/php/80/etc --enable-fpm --enable-mysqlnd --enable-opcache --enable-pcntl --enable-mbstring --enable-soap --enable-zip --enable-calendar --enable-bcmath --enable-exif --enable-ftp --enable-intl --with-mysqli --with-pdo-mysql --with-openssl --with-curl --with-gd --with-gettext --with-mhash --with-openssl --with-mcrypt --with-tidy --enable-wddx --with-xmlrpc --with-zlib
#安装
make && make install
这样就安装好了
安装后创建php.ini文件(在解压后的文件里复制)
cp /www/server/php/php-8.0.0/php.ini-production /www/server/php/80/etc/php.ini
运行
/www/server/php/80/bin/php -v
安装成功
开启 php-fpm 使nginx能连上(因为我服务器有多个版本php所以监听的sock)
/www/server/php/80/etc 下创建 php-fpm.config文件
[global]
pid = /www/server/php/80/var/run/php-fpm.pid
error_log = /www/server/php/80/var/log/php-fpm.log
log_level = notice
[www]
listen = /tmp/php-cgi-80.sock
listen.backlog = 8192
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.status_path = /phpfpm_80_status
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
request_terminate_timeout = 100
request_slowlog_timeout = 30
slowlog = var/log/slow.log
运行 php-fpm
/www/server/php/80/sbin/php-fpm
没报错就是成功了
nginx配置监听
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi-80.sock;
fastcgi_index index.php;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
重启nginx没报错基本就成功了
修改php.ini开启jit
1,搜索 “zend_extension=opcache” 去掉注释
2,[opcache]下添加
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=128M
opcache.jit=1255
3,重启php-fpm,配置成功