centos6系统已经被官网停止维护,要安装软件必须用第三方的RPM包,下面使用yum安装php7.4正式版,当前基于WLNMP提供的一键安装包来安装
1、添加epel源
yum install epel-release
yum install epel-release
2、添加WLNMP一键安装包源
rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
3、安装php7.4
yum clean all
yum install wphp74
yum clean all
yum install wphp74
在centos6系统安装完php7.4,默认会通过php-fpm方式自动启动,并且已经设置好了开机自启,只需要配置下nginx即可。
4、配置nginx
如果使用WLNMP提供的nginx,只需要在安装后取消include enable-php71.conf;注释即可
WLNMP安装nginx方法
yum install wnginx
如果当前使用的是非WLNMP提供的nginx,只需要在nginx中配置以下内容即可(fastcgi_pass unix:/tmp/php-fpm74.sock; 是关键AbiaoOK)
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-fpm74.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
更多相关内容可参考:https://www.wlnmp.com/
可以支持两种不同版本的php(5.6版本和7.4版本):
fastcgi_pass 127.0.0.1:9000; (php56w)
fastcgi_pass unix:/tmp/php-fpm74.sock; (wphp74)
在centos6系统安装完php7.4,默认会通过php-fpm方式自动启动,并且已经设置好了开机自启,只需要配置下nginx即可。
centos6安装了wphp74后, 原先php56w-gd不能用了,安装会提示冲突,那么后续版本智能用7.4啦? gd库冲突,暂时无法解决,只能2选一,那么就全部用PHP7.4吧!!
支持THINKPHP6伪静态规则,nginx配置代码(虚拟主机路径 /usr/local/nginx/conf/vhost):
server {listen 443 ssl;server_name testapp.com www.testapp.com;#ssl on;ssl_certificate /data/ssl/www.testapp.com;.pem; ssl_certificate_key /data/ssl/www.testapp.com.key; ssl_session_timeout 5m;#ssl_protocols TLSv1 TLSv1.1 TLSv1.2;#ssl_prefer_server_ciphers on; root /myweb/new/testapp.com; location / { index index.php index.html index.htm;if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } }location ~ \.php/?.*$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;set $temp_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") { set $temp_script_name $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$temp_script_name; fastcgi_param SCRIPT_NAME $temp_script_name; }location ~ /\.ht {deny all; }
}server {listen 80;server_name testapp.com www.testapp.com;client_max_body_size 80m; #error_page 404 /data/ymg280/404.html;#error_page 500 502 503 504 /errors/default/50x.html;if ($host != 'www.testapp.com'){rewrite ^/(.*)$ http://www.testapp.com/$1 permanent;}root /myweb/new/qingmi.link;location / {index index.php index.html index.htm;if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } }location ~ \.php/?.*$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php; include fastcgi_params; set $temp_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") { set $temp_script_name $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$temp_script_name; fastcgi_param SCRIPT_NAME $temp_script_name; }location ~ /\.ht {deny all; }
}
安装过程可能遇到的问题,做了粗略的笔记:
安装redis扩展??
https://blog.csdn.net/u010227042/article/details/118766460
安装php-redis扩展
下载redis扩展
首先和redis一样,也需要下载php-redis的扩展。
在php官方redis扩展地址https://pecl.php.net/package/redis/找到我们所需要的扩展,下载即可。比如我们要安装5.2.1版本的php-redis扩展,执行命令:
#下载
wget http://pecl.php.net/get/redis-5.2.1.tgz
#解压
tar xzf redis-5.2.1.tgz
#进入目录
cd redis-5.2.1
编译安装
在刚刚下载redis扩展的源码目录下执行phpize(如果不知道phpize请往下看分解)
/usr/local/php/bin/phpize
执行 ./configure --with-php-config=/usr/local/php/bin/php-config
生成配置文件
编译 make && make install
记得make test 看一下编译过程的问题已经文件的存储路径
autoconf-2.6版本太低,不支持,要先安装autoconf-2.69
linux安装autoconf-2.69
————————————————
检查是否有安装autoconf其他版本:
rpm -qf /usr/bin/autoconf
如有安装,则先卸载相应版本,否则不用处理。执行以下命令卸载:
rpm -e --nodeps autoconf-2.63
wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
解压安装:
tar zxvf autoconf-2.69.tar.gz
编译源文件:
cd autoconf-2.69
./configure --prefix=/usr/
make && make install
检查版本:
/usr/bin/autoconf -V
最后再: vim /usr/local/php/etc/php.ini
添加扩展: extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/redis.so
重启php-fpm74:
service php-fpm74 restart
重启nginx:
service nginx restart
PHP输出的弱发现状态码不是200,而是500,那么很可能是权限设置的问题:
vim /usr/local/php/etc/php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm74.pid
error_log = /usr/local/php/var/log/php-fpm74_error.log
log_level = notice
;alert,error,warning,notice,debug[www]
listen.owner = nginx
listen.group = nginx
listen = /tmp/php-fpm74.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.mode = 0666
user = nginx
group = nginx
pm = dynamic
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 20
pm.max_children = 20
pm.max_requests = 1000
;pm = static
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = /var/log/php_slow.log
设置用户和用户组都为nginx, 跟文件夹所属用户组保持一致,另外可以设置文件夹权限为:777
[root@iZuf63qiu57nxc0lmplkxbZ redis-5.2.1]# chmod 777 /myweb/qmq -R
[root@iZuf63qiu57nxc0lmplkxbZ redis-5.2.1]# chown nginx:nginx /myweb/qmq -R
重启php-fpm74:
service php-fpm74 restart
重启nginx:
service nginx restart