centos7 卸载 安装 php 环境,以及nginx 部署配置php项目

前言

最近在部署php项目中,遇到了很多很多的错,头皮发麻,因此做个记录,往后回顾,仅作为个人笔记记录

先说php 在linux 中的安装与卸载,当然部署php 项目,可能还需要mysql,以及nginx ,这个些相关软件安装,就不在此说明了。

首先说php 卸载

因为之前安装过php7.2版本,不过经测试,此版本与项目不兼容,会报错,切回7.0版本,一切正常,因此首先卸载7.2,然后安装7.0版本

此卸载方式适用yml 安装

php -v 查看php 版本

rpm -qa|grep php 找到所有 php 软件包,然后删除即可

命令 rpm -e

例如:# rpm -e php72w-mysql-7.1.23-1.w7.x86_64

全部删除之后 php -v 查看php 版本

注意!!! 在删除软件包时,可能会因为其它包依赖导致无法删除,
解决办法:根据错误提示,先删除依赖包,接着在删除

php 安装

安装源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm     
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装php7.0 如何要安装其它版本,直接将下面70 改为72 73 等。。

yum -y install php70w php70w-cli php70w-common php70w-devel php70w-embedded php70w-fpm php70w-gd php70w-mbstring php70w-mysqlnd php70w-opcache php70w-pdo php70w-xml php70w-ldap

启动php

systemctl start php-fpm

设置开机自启

systemctl enable php-fpm

**默认php-fpm 端口为9000,启动失败,(我服务器9000端口已经用了)*检查端口是否被占用,默认配置在/etc/php-fpm.conf 引用了/etc/php-fpm.d/,www.conf 文件修改端口即可

安装完成之后遇到的问题,php连接不上mysql,以及php入库报错
**解决方式,修改mysql配置文件,my.conf 文件,写入如下 **

#解决 php 添加修改数据,传入 value:''  报错
sql_mode=ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

#解决php mysql 连接报错 ,这个错可能是mysql默认使用 caching_sha2_password,作为默认的身份验证插件,而不再是 mysql_native_password ,但是客户端暂时不支持这个插件导致的。
default_authentication_plugin=mysql_native_password

php-v 查看版本 ,安装好之后,就可以在nginx 配置php了,具体如下

nginx php 配置 注意!不要参考宝塔ssl 配置

	
	server {
			#listen       80;
			listen     443 ssl ;
			server_name  你的域名;
			#ssl 证书路径
			ssl_certificate    /usr/local/nginx/ssl/1_lr.femzh.crt;
			ssl_certificate_key    /usr/local/nginx/ssl/2_lr.com.key;
			
			#SSL 相关配置
			ssl_session_cache    shared:SSL:1m;
			ssl_session_timeout  10m;
			#这个不用瞎改,否则会出现意象不到的bug,ios手机无法访问静态资源,安卓可以,具体什么原因,暂时没有深究
			ssl_ciphers  HIGH:!aNULL:!MD5;
			ssl_prefer_server_ciphers  on;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/local/nginx/html/lrzhsh/;
            index index.php index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
		#php 的关键配置,这里的端口就是php-fpm 的端口,默认为9000
        location ~ \.php$ {
            root           /usr/local/nginx/html/lrzhsh/;
            fastcgi_pass   127.0.0.1:8999;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
	

其它问题

由于php 项目文件,图片都是存储在服务器的,会存在 文件权限问题,相关读写文件目录,注意权限是否够

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值