linux 安装多个PHP版本(php5.6 php7.1 php7.2 php7.3 php7.4 php8.0)nginx配置php多版本
1、下载php下载PHP对应版本:https://www.php.net/releases/本次我测试的7.4和8.07.4:https://www.php.net/distributions/php-7.4.16.tar.gz8.0:https://www.php.net/distributions/php-8.0.3.tar.gz$ cd /down$ wget https://www.php
·
1、下载php
下载PHP对应版本:https://www.php.net/releases/
本次我测试的7.4和8.0
7.4:https://www.php.net/distributions/php-7.4.16.tar.gz
8.0: https://www.php.net/distributions/php-8.0.3.tar.gz
$ cd /down
$ wget https://www.php.net/distributions/php-7.4.16.tar.gz
$ wget https://www.php.net/distributions/php-8.0.3.tar.gz
2、 安装7.4
$ cd /down
$ tar -xzvf php-7.4.16.tar.gz
$ cd /down/php-7.4.16/
$ ./configure --prefix=/usr/local/php74 --with-config-file-scan-dir=/usr/local/php74/etc/ --enable-opcache --enable-session --enable-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mhash --with-openssl --enable-bcmath --enable-soap --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --with-bz2 --with-readline
$ make && make install
./configure 编译 PHP 时需要 --enable-fpm 配置选项来激活 FPM 支持;官方安装目录https://www.php.net/manual/zh/install.fpm.install.php
$ cp /down/php-7.4.16/php.ini-development /usr/local/php74/php.ini
$ vim /usr/local/php74/php.ini
display_error = On 注释删除
3、配置php-fpm.conf
$ cp /usr/local/php74/etc/php-fpm.conf.default /usr/local/php74/etc/php-fpm.conf
$ vim /usr/local/php74/etc/php-fpm.conf
pid = run/php-fpm.pid # 打开该注释,该文件在/usr/local/php74/var/run/php-fpm.pid
error_log = log/php-fpm.log #打开该注释, 该文件在/usr/local/php74/var/log/php-fpm.log
daemonize = yes #打开该注释 该行打开后php-fpm -start -D 可以在后台启动
include=/usr/local/php74/etc/php-fpm.d/*.conf
保存退出
4、配置www.conf
$ cp /usr/local/php74/etc/php-fpm.d/www.conf.default /usr/local/php74/etc/php-fpm.d/www.conf
$ vim /usr/local/php74/etc/php-fpm.d/www.conf
user = nginx
group = nginx
;listen = 127.0.0.1:9000 # 改行注释掉
listen = /run/php74-fpm/php-fpm.sock # php-fpm.sock会自动生成,提前创建好/run/php74-fpm/目录并授权属主属组
保存退出
5、配置php-fpm.sock权限
$ mkdir /run/php74-fpm
$ chown -R nginx:nginx /run/php74-fpm #很重要,不设置nginx没办法启动php-fpm
$ ll /run/php74-fpm/php-fpm.sock #查看权限是否改变
6、安装nginx (不再赘述)
6.1 nginx 属主属组添加不再赘述
7、配置nginx.conf
$ nginx -t # 查看nginx.conf配置目录
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
$ vim /etc/nginx/nginx.conf
按照以下配置,没有在以下里面的注释
user nginx nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
}
8、配置php74.com
$ touch /etc/nginx/conf.d/php74_com.conf
$ vim /etc/nginx/conf.d/php74_com.conf
server {
listen 80;
server_name php74.com;
root "/home/vagrant/Code/php74";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/php74.com-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php74-fpm/php-fpm.sock; # 该配置决定了项目使用哪个PHP版本;该配置有两种链接方式:tcp方式和UNIX Domain Socket方式:
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
}
保存退出
9、配置php74 项目目录
$ mkdir /home/vagrant/Code/php74
$ touch /home/vagrant/Code/php74/index.php
$ chown -R nginx:nginx /home/vagrant/Code/php74
$ vim /home/vagrant/Code/php74/index.php
/home/vagrant/Code/php74/index.php
<?php
phpinfo();
?>
10、 重启nginx
$ ps -ef | grep nginx
$ kill 67181 # 杀掉nginx进程
$ /usr/sbin/nginx -c /etc/nginx/nginx.conf #重启nginx.conf主配置文件
$ ps -ef | grep nginx # 查看nginx是否启动
11、配置hosts
192.168.40.63 php74.com
12、打开浏览器测试php74.com
看一下现在是不是PHP7.4版本
13、安装PHP8.0
和上面步骤一样不再赘述
14、错误解决办法
权限:网站权限、/run/php74-fpm/php-fpm.sock 权限
查看nginx.conf 错误日志:
$ vim /etc/nginx/nginx.conf
$ tail -f /var/log/nginx/error.log
查看php74.com错误日志
$ vim /etc/nginx/conf.d/php74_com.conf
$ tail -f /var/log/nginx/php74.com-error.log error
还是解决不了给我留言
更多推荐
已为社区贡献1条内容
所有评论(0)