您的位置:首页 > 运维架构 > Nginx

Ubuntu下用apt安装Nginx和PHP

2016-12-28 18:31 495 查看
====== 安装Nginx ======

1.加入nginx的repository
$ cd /tmp/
$ wget http://nginx.org/keys/nginx_signing.key $ sudo apt-key add nginx_signing.key

$ cd /etc/apt/sources.list.d/
$ sudo vim nginx.list

将下面2行复制粘贴到这个文件
deb http://nginx.org/packages/ubuntu/ lucid nginx
deb-src http://nginx.org/packages/ubuntu/ lucid nginx

2.用apt安装
$ sudo apt-get update
$ sudo apt-get install nginx

3.配置文件位置
/etc/nginx/nginx.conf
这个配置文件会包含/etc/nginx/conf.d/*.conf
默认主目录:/usr/share/nginx/html/

4.管理nginx服务
启动:$ sudo service nginx start
停止:$ sudo service nginx stop
重启:$ sudo service nginx restart

====== 安装PHP(FastCGI) ======

$ apt-get install php5-dev php5-cli php5-fpm php5-cgi

测试
1.修改Nginx默认服务器默认主目录的拥有者,并把自己加入到www-data组
$ cd /usr/share/nginx
$ sudo chown -R www-data:www-data ./html/
$ sudo chmod -R g+w ./html/
$ sudo usermod -a -G www-data<username>
点击桌面右上角的齿轮图标,选择注销

2.重新登录后,在/usr/share/nginx/html/中,新建一个phpinfo.php文件,内容如下:
<?php
phpinfo();

2.编辑/etc/nginx/conf.d/default.conf,对“pass the PHP scripts toFastCGI server listening on127.0.0.1:9000”(28行)下面的location做如下修改
    location ~ \.php${
       root         html;
       fastcgi_pass  127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
       include       fastcgi_params;
    }
也就是,将每行前面的#号删除;SCRIPT_FILENAME后面的“/scripts”改为“/usr/share/nginx/html”

3.重启nginx。
$ sudo service nginx restart

4.在浏览器打开http://localhost/phpinfo.php
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: