Ubuntu之安装Nginx、PHP
来源:互联网 发布:网络推广方法和技巧 编辑:程序博客网 时间:2024/05/18 02:23
前提
如果是Ubuntu,可能默认已经安装了Apache2,要先卸载
$ sudo apt-get remove apache2$ sudo apt-get remove apache*
安装nginx
$ sudo apt-get install nginx
测试nginx
打开浏览器,输入http://127.0.0.1,如果出现
则表示nginx安装成功。
安装配置PHP
安装 PHP for Processing
$ sudo apt-get install php5-fpm php5-mysql
Since Nginx does not contain native PHP processing like some other web servers, we will need to install php5-fpm, which stands for “fastCGI process manager”. We will tell Nginx to pass PHP requests to this software for processing.
We can install this module and will also grab an additional helper package that will allow PHP to communicate with our database backend. The installation will pull in the necessary PHP core files. Do this by typing:
配置 PHP Processor
$ sudo gedit /etc/php5/fpm/php.ini
cgi.fix_pathinfo=0
This is an extremely insecure setting because it tells PHP to attempt to execute the closest file it can find if a PHP file does not match exactly. This basically would allow users to craft PHP requests in a way that would allow them to execute scripts that they shouldn’t be allowed to execute.
We will change both of these conditions by uncommenting the line and setting it to “0” like this:
Save and close the file when you are finished.
重启 PHP processor
$ sudo service php5-fpm restart
让nginx使用PHP Processor
$ sudo gedit /etc/nginx/sites-available/default
按下面修改配置文件
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.php index.html index.htm; server_name server_domain_name_or_IP; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }}
使对php的配置立即生效
$ sudo service nginx restart
建立测试页
$ sudo gedit /usr/share/nginx/html/info.php
内容为:
<?php phpinfo();?>
访问http://127.0.0.1/info.php
如果出现
则表示配置成功
参考资料
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04
- Ubuntu之安装Nginx、PHP
- Ubuntu安装nginx、php
- UBUNTU 安装PHP+MYSQL+NGINX
- ubuntu安装Nginx + PHP + Redmine
- ubuntu 安装nginx和php
- [转] ubuntu+php+nginx 安装
- Ubuntu 安装php+mysql+nginx
- Ubuntu安装nginx+php+mysql
- ubuntu安装PHP+nginx+mongoDB
- Ubuntu Nginx+php+yaf安装
- Ubuntu+Nginx+PHP之配置
- Ubuntu下安装Nginx、Php-fpm、Php
- Ubuntu 9.04 server安装nginx+php(fastcgi)
- ubuntu 10.10 源码安装 nginx php mysql
- Ubuntu下安装Nginx+PHP+MySQL+FastCGI
- ubuntu 安装nginx apache php mysql
- Ubuntu/Debian上安装Nginx+php环境
- ubuntu下nginx+php+mysql安装配置
- 链表、图的相关算法
- windows下memcached安装以及php_memcache.dll扩展
- 自定义ListView的简单使用方法
- Hello world with LUA
- 初入android驱动开发之字符设备(一)
- Ubuntu之安装Nginx、PHP
- QT5可执行程序缺少dll问题
- 有趣的Lua表
- 226.Invert Binary Tree(交换二叉树左右结点)
- pythonwin的安装&解决方案
- 身体从多大年纪开始老化?
- 如何实现基于tcp进行http交互
- ADB命令使用
- 加密与解密