参考链接: http://www.lvtao.net/server/499.html
http://www.ha97.com/5194.html (Nginx配置中文详解)
下午配置nginx简直坑=。=,网上的教程参差不齐,试了好几个都失败了。皇天不负有心人:最后按照本文开始的链接配成功了。
1、 安装nginx
sudo apt-get update
sudo apt-get intsall nginx
安装完成后,启动nginx看看是否安装成功:
sudo /etc/init.d/nginx start
打开浏览器,查看http://localhost/ 看看是否看到了”Welcome to nginx!” 如果看到了,说明安装成功.
2、安装php
sudo apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-sqlite php5-xsl
3、安装spawn-fcgi
nginx比较轻量,需要spawn-fcgi来解析?
sudo apt-get install spawn-fcgi
4、
4.1 配置
(1)在/etc/nginx/fastcgi_params文件最后添加"fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;"
(2)sudo sed -i '$ i fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' /etc/nginx/fastcgi_params
(3)修改php-cgi的配置文件,把cgi.fix_pathinfo设置为1
终端输入:sudo sed -i '/cgi.fix_pathinfo=/ c cgi.fix_pathinfo=1;' /etc/php5/cgi/php.ini
4.2 开启fastcgi并设置开机启动
(1)sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
(2)设置开机启动,即在/etc/rc.local中添加"/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid"
(3)sudo sed -i '/^exit/ i /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid' /etc/rc.local
4.3 nginx中虚拟主机配置
(1)sudo vim /etc/nginx/sites-available/default
(2)修改default配置文件,内容如下
#默认
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
# Make site accessible from http://localhost/
server_name localhost;
root /var/www/nginx-default;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
# 之前没有把这个放在location /中,被坑了好久
root /var/www/nginx-default;
index index.php index.html index.htm;
}
}
#添加虚拟主机
#Nginx中的server_name指令主要用于配置基于名称的虚拟主机,服务器会根据请求的host自动匹配目录
#匹配顺序的参考链接:http://onlyzq.blog.51cto.com/1228/535279
server {
listen 80; #auyoumi.net
server_name au.youmi.net www.au.youmi.net; #主机名称,绑定的域名
root /home/fental/vhost/au; #虚拟主机根目录
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
5、
安装mysql
1
|
sudo apt-get install mysql-server mysql-client
|
中间会提示输入Root用户密码,依次输入即可.
启动MySQL
1
|
sudo /etc/init.d/mysql start
|
测试mysql服务是否正常:
运行
1
|
mysql -uroot -p
|
输入mysql密码
1
|
show databases;
|
如果看到下面的内容
| Database |
| information_schema |
| mysql |
则mysql已正确安装了.
至此,ubuntu下的nginx+php+mysql就安装完成了.
遇到的问题:
nginx运行php"No input file specified"错误的解决方法:http://www.jbxue.com/article/5649.html
根据上述链接可以解决大部分问题,但是我遇到这个问题是因为我在配置的时候使用了$document_root,但是却又没有指明$document_root的目录,所以一直找不到指定文件!!