吸毒的虫子 发表于 2017-12-22 23:12:08

Centos7下PHP的卸载与安装nginx

  Centos7下PHP的卸载与安装nginx
  CentOS上PHP完全卸载,想把PHP卸载干净,直接用yum的remove命令是不行的,需要查看有多少rpm包,然后按照依赖顺序逐一卸载。
  1.首先查看机器上安装的所有php相关的rpm包
# rpm -qa | grep php
  php-cli-5.3.3-22.el6.x86_64
  php-pdo-5.3.3-22.el6.x86_64
  php-gd-5.3.3-22.el6.x86_64
  php-fpm-5.3.3-22.el6.x86_64
  php-common-5.3.3-22.el6.x86_64
  php-5.3.3-22.el6.x86_64
  php-xml-5.3.3-22.el6.x86_64
  php-pear-1.9.4-4.el6.noarch
  2.按依赖顺序进行删除
  rpm -e php-fpm-5.3.3-22.el6.x86_64
  rpm-e php-pdo-5.3.3-22.el6.x86_64
  rpm -e php-pear-1.9.4-4.el6.noarch
  rpm-e php-cli-5.3.3-22.el6.x86_64
  rpm -e php-5.3.3-22.el6.x86_64
  rpm-e php-xml-5.3.3-22.el6.x86_64
  rpm -e php-gd-5.3.3-22.el6.x86_64
  rpm-e php-common-5.3.3-22.el6.x86_64
  ==========================
  centos7安装nginx和php
  nginx安装,参考网址:https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7
  rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
  yum install nginx
  安装PHP和php-fpm
  yum install --enablerepo=remi --enablerepo=remi-php56 phpphp-fpm
  因为我的php安装的是5.6的,所以的指定这个源里面安装php-fpm,不然一直报错
  修改php配置文件
  vi /etc/php.ini
  修改成0(这个配置值说是不安全的设置,参考网址:http://www.laruence.com/2010/05/20/1495.html)
  cgi.fix_pathinfo=0
  修改配置文件
  vim /etc/nginx/conf.d/default.conf
  server {
  listen       80;
  server_namewww.scchary.com;
  root /home/samba1/public_html;
  #charset koi8-r;
  #access_log/var/log/nginx/log/host.access.logmain;
  location / {
  #root   /usr/share/nginx/html;
  #root /home/samba1/public_html;
  indexindex.php index.html index.htm;
  }
  #error_page404            /404.html;
  # redirect server error pages to the static page /50x.html
  #
  error_page   500 502 503 504/50x.html;
  location = /50x.html {
  root   /usr/share/nginx/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
  #
  location ~ \.php$ {
  #root         /home/samba1/public_html;
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_indexindex.php;
  fastcgi_paramSCRIPT_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 {
  #    denyall;
  #}
  }
  修改上面配置文件的时候,运行php文件的时候,老是显示没有找到,后来在这里找到了答案,参考网址http://www.nginx.cn/562.html
  server {
  listen   [::]:80;
  server_nameexample.com www.example.com;
  access_log/var/www/logs/example.com.access.log;
  location / {
  root   /var/www/example.com;
  indexindex.html index.htm index.pl;
  }
  location /images {
  autoindex on;
  }
  location ~ \.php$ {
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_indexindex.php;
  fastcgi_paramSCRIPT_FILENAME/var/www/example.com$fastcgi_script_name;
  include fastcgi_params;
  }
  }
  这个配置中有很多不合理的地方,其中一个明显的问题就是root指令被放到了location / 块。如果root指令被定义在location块中那么该root指令只能对其所在的location生效。其它locaiont中没有root指令,像location /images块不会匹配任何请求,需要在每个请求中重复配置root指令来解决这个问题。因此我们需要把root指令放在server块,这样各个location就会继承父server块定义的$document_root,如果某个location需要定义一个不同的$document_root,则可以在location单独定义一个root指令。
  另一个问题就是fastCGI参数SCRIPT_FILENAME 是写死的。如果修改了root指令的值或者移动文件到别的目录,php-fpm会返回“No input file specified”错误,因为SCRIPT_FILENAME在配置中是写死的并没有随着$doucument_root变化而变化,我们可以修改SCRIPT_FILENAME配置如下:
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  所以我们不能忘记在server块中配置root指令,不然$document_root的值为空,只会传$fastcgi_script_name到php-fpm,这样就会导致“No input file specified”错误。
  最后在测试php文件里面输出phpinfo的时候,出现了一个未定义时区的错误,修改了配置文件还是报错,最后重启了下php-fpm就好了
  ------------------------------
  本人微信公众帐号: 心禅道(xinchandao)
  


  本人微信公众帐号:双色球预测合买(ssqyuce)
页: [1]
查看完整版本: Centos7下PHP的卸载与安装nginx