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
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
相关文章推荐
- centos 7上nginx+uwsgi 性能调优
- apache和nginx
- Nginx源码学习-从零开始(1)
- 使用Nginx+lua返回错误码并且返回自定义内容。
- nginx配置location对thinkphp伪静态影响
- Ubuntu上安装,卸载nginx
- Nginx使用gadyy证书
- Mac OS使用brew安装Nginx、MySQL、PHP-FPM的LAMP开发环境
- 为什么我们使用Nginx而不是Apache?
- Nginx负载均衡的4种方案配置实例
- windows Nginx基本使用方法
- HLS直播点播加密
- 使用nginx与nginx-rtmp-module搭建流媒体服务器
- nginx做web服务器负载均衡
- nginx动态跳转视频播放地址
- nginx配置ssl
- 使用nginx与nginx-rtmp-module搭建流媒体服务器
- nginx设置黑/白名单
- Windows 下 Nginx+IIS 使用
- Nginx日志常用分析命令汇总