Chinaunix首页 | 论坛 | 博客
  • 博客访问: 274878
  • 博文数量: 72
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 276
  • 用 户 组: 普通用户
  • 注册时间: 2014-07-28 23:52
文章分类

全部博文(72)

文章存档

2017年(20)

2014年(52)

分类: PHP

2017-06-11 13:47:38

一,安装Nginx
  apt-get install nginx
  1,配置nginx
    nginx所有的配置在 /etc/nginx/nginx.conf中
    nginx.conf配置里面包括了
      include /etc/nginx/conf.d/*.conf;
           include /etc/nginx/sites-enabled/*;
        这两个配置,所以这里面的配置也是有效的。
       错误日志 error_log /var/log/nginx/error.log;
 
  这里我们把配置写在 /etc/nginx/sites-available/default中
  修改  root /usr/share/nginx/html;   这是网页的根目录,默认里面有一个index.html页面
     index  index.html index.htm修改成index index.php index.html index.htm;
     增加  
       
  location ~ \.php$ {
                  try_files $uri $uri/ =404; #16.04默认安装1.10.0,配置指令有所修改
                  fastcgi_pass 127.0.0.1:9000;
                  fastcgi_index index.php;
                  include fastcgi_params;
          }
 
  2,保存文件,使配置生效 /etc/init.d/nginx reload
 
  3,启动nginx
    /etc/init.d/nginx start
   4,在 /usr/share/nginx/html下新建index.php,注意?和php直接不能有空格,否则不会正常执行其中的函数的。
                        phpinfo();
  ?>

二 安装php
sudo apt-get install php-fpm
sudo apt-get install php-gd # Popular image manipulation library; used extensively by Wordpress and it's plugins.
sudo apt-get install php-cli # Makes the php7 command available to the terminal for php7 scripting
sudo apt-get install php-curl # Allows curl (file downloading tool) to be called from PHP7
sudo apt-get install php-mcrypt # Provides encryption algorithms to PHP scripts
sudo apt-get install php-mysql # Allows PHP7 scripts to talk to a MySQL Database
sudo apt-get install php-readline # Allows PHP7 scripts to use the readline function 查看php运行进程
ps -waux | grep php 打开关闭php5进程

/etc/ini.d/php/7.0/php-fpm stop
/etc/ini.d/php/7.0/php-fpm start
/etc/ini.d/php/7.0/php-fpm restart
/etc/ini.d/php/7.0/php-fpm reload


配置php7监听端口  /etc/php/7.0/fpm/pool.d/



listen = /run/php/php7-fpm.sock  改为
listen = 127.0.0.1:9000 重新运行php进程
在浏览器中输入 localhost就可以看到了

PS:
 1,16.04存在如下问题。可以测试index.html 和 index.php 输出不同。
    
OS: Ubuntu 15.04
由于nginx与PHP-fpm之间的一个小bug,会导致这样的现象: 网站中的静态页面 *.html 都能正常访问,而 *.php 文件虽然会返回200状态码, 但实际输出给浏览器的页面内容却是空白。 简而言之,原因是nginx无法正确的将 *.php 文件的地址传递给php-fpm去解析, 相当于php-fpm接受到了请求,但这请求却指向一个不存在的文件,于是返回空结果。 为了解决这个问题,需要改动nginx默认的fastcgiparams配置文件: vi /etc/nginx/fastcgi_params 在文件的最后增加两行: 
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;   
fastcgi_param PATH_INFO                $fastcgi_script_name;   
然后重启一下服务:
service php5-fpm reload service nginx reload            //重新加载各项配置改动。    

阅读(2279) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~