码迷,mamicode.com
首页 > 数据库 > 详细

Ubuntu下安装Nginx,PHP5(及PHP-FPM),MySQL

时间:2014-12-08 17:14:38      阅读:375      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   ar   color   os   使用   

Ubuntu 下 nginx , php , mysql 和 golang 的简单安装

我是搞php出身,自然安装lnmp是常规技能。以前的手段还是lnmp安装包,比如军哥的lnmp1.0。随着php和mysql的更新,大多数一键安装都开始版本老化,更新困难的问题。因此,重新研究了一下Ubuntu下lnmp的安装,发现现在简单的多,记录一下。

另外最近在学习golang,Ubuntu下安装自然也是必须的过程。不过golang的安装也有一些奥妙。当然,不是源码安装的啦。

Nginx Stable/Development

Ubuntu下的包管理器是apt-get或者说dpkg。常规的安装命令apt-get install(注意权限sudo apt-get install)。Nginx是这几个软件里最友好的,直接可以添加stable源:

add-apt-repository ppa:nginx/stable

或者development源:

add-apt-repository ppa:nginx/development

如果没有安装命令add-apt-repository,安装:

apt-get install python-software-properties 

之后常规的操作:

apt-get update
apt-get install nginx
service nginx start

PHP 5.4+

PHP的ppa源有个老兄专门在做,Ondrej Sury。有php5.4php5.5php5.6的源,具体的可以看官方页面。 为什么没有5.3?你落伍啦!5.4+性能提高很多,5.5还有内置的ZendOpCache。安装php5.5:

add-apt-repository ppa:ondrej/php5
apt-get update
apt-get install php5 php5-fpm
service php5-fpm start

还有些必要的包,安装一下,记得重启php5-fpm:

apt-get install php5-gd php5-curl php5-sqlite php5-mysqlnd php5-mcrypt
service php5-fpm restart

至于nginx怎么配置php-fpm,一搜一大把,不多说。

MySQL 5.5+ & MariaDB

还是这个老兄,维护着mysql5.5mysql5.6 和 MariaDB5.5。所以,很简单,比如安装MariaDB(不喜欢mysql,被oracle摧残了):

add-apt-repository ppa:ondrej/mariadb-5.5
apt-get update
apt-get install mariadb-server-5.5
service mysql start

这里注意,安装会提示InnoDB Plugin Disabled。不要紧,MariaDB把InnoDB内置进去了,其实是已经启动的。具体的可以:

mysql SHOW ENGINE INNODB STATUS;

Golang

重头戏是golang啦。我搜寻了半天ppa源,只找到一个可以安装golang1.1.1的源,很不爽。其实可以golang官方下载已经编译好的linux.tar.gz。但是需要自己手动设置GOROOT,有点麻烦啊。

终于还是发现了个好工具Godeb。实际上这就是一个deb包构建器。先把官方编译好的tar.gz下载,打包成deb然后执行安装。

以64位安装为例:

wget https://godeb.s3.amazonaws.com/godeb-amd64.tar.gz
tar -zxvf godeb-amd64.tar.gz
./godeb install

就开始安装最新版本。还可查看支持的版本,并安装特定版本:

./godeb list
1.2
1.2rc5
1.2rc4
1.2rc3
1.2rc2
1.2rc1
1.1.2
1.1.1
1.1
(...)

./godeb install 1.1

安装好后,可以用go env查看,是否安装完成。

剩下的设置GOPATH,GOBIN就不赘述了。我是修改在/etc/profile里面的。

写在最后

Ubuntu下很多东西都有源,容易安装,也是好事啊。

 

 

 

 

 

 

 

 

 

 

第一步,安装nginx

apt-get update
apt-get install nginx
即可完成安装

启动nginx:
/etc/init.d/nginx start
然后就可以访问了,http://localhost/ , 一切正常!如果不能访问,先不要继续,看看是什么原因,解决之后再继续。

第二步,安装Php和mysql
安装php和MySQL:
apt-get install php5-cli php5-cgi mysql-server-5.0 php5-mysql

第三步,安装FastCgi和配置
我们需要/usr/bin/spawn-fcgi这个文件,而它是属于lighttpd这个包里面的,所以我们安装lighttpd然后把它设置为开机不启动:

apt-get install lighttpd #我们只要/usr/bin/spawn-fcgi
rcconf #去掉lighttpd开机自启动--------------------------------------------强烈推荐
修改nginx的配置文件:/etc/nginx/sites-available/default
修改 server_name 192.168.200.100;
修改index的一行修改为:
index index.php index.html index.htm;

去掉下面部分的注释并修改为:
location ~ \.php$ {
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
include /etc/nginx/fastcgi_params;

}

 

在server{}内定义日志文件的位置和相应的格式:
access_log /var/log/nginx/localhost_access.log combined;

 

access_log off;//表示关闭

 


重新启动nginx:
/etc/init.d/nginx stop
/etc/init.d/nginx start


启动fastcgi php:
spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi

 
以下步骤我直接运行rcconf设置php-cgi为开机自启动即可,所以跳过
---------------------------------------为了让php-cgi开机自启动:
cd /etc/init.d
cp nginx php-cgi
vim php-cgi

替换nginx为php-cgi

并修改相应部分为:
DAEMON=/usr/bin/spawn-fcgi
DAEMON_OPTS="-a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi"
...
stop)
        echo -n "Stopping $DESC: "
        pkill -9 php-cgi
        echo "$NAME."

-------------------------------------------------

在/var/www/nginx-default/目录下创建一个文件:  /var/www/nginx-default/index.php
文件内容是:

< ?php phpinfo();?>

然后浏览器访问nginx就可以看到一切正常了

 

------------------------------------------------------------END 安装成功

 

配置文件目录 /etc/nginx/    nginx.conf     /sites-available/default

www目录 /var/www/nginx-default/

 

启动fastcgi php:
spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi

 

 

日志文件:

localhost.access.log  /var/log/nginx/localhost.access.log

access.log  /var/log/nginx/access.log

error.log    /var/log/nginx/error.log

 

 

---------------重定向nginx错误页面的方法

error_page 404  /404.html;

这个404.html保证在nginx主目录下的html目录中即可,如果需要在出现404错误后直接跳转到另外一个地址,可以直接设置如下:


error_page 404 http://www.***.net ;


同样的方式可以定义常见的403、500等错误。


特别注意的是404.html文件页面大小要超过512k,不然会被ie浏览器替换为ie默认的错误页面。

 

 

------------------------------虚拟主机配置

server {
    listen   80;
    server_name  localhost; 
    access_log  /var/log/nginx/localhost.access.log;

    location / {
        root   /var/www/nginx-default; 
        index index.php index.html index.htm;
    }

    location /doc {
        root   /usr/share;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    location /images {
        root   /usr/share;
        autoindex on;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/nginx-default$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
}


server {
    listen   80;
    server_name  sdsssdf.localhost.com; 
    access_log  /var/log/nginx/localhost.access.log;

    location / {
        root   /var/www/nginx-default/console; 
        index index.php index.html index.htm;
    }

    location /doc {
        root   /usr/share;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    location /images {
        root   /usr/share;
        autoindex on;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/nginx-default$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
}

 

----------------------监控  

 

location ~ ^/NginxStatus/ { 

stub_status on; #Nginx 状态监控配置     



 

 

 

这样通过 http://localhost/NginxStatus/(最后的/不能掉) 监控到 Nginx 的运行信息:

 

Active connections: 1 
server accepts handled requests
 1 1 5 
Reading: 0 Writing: 1 Waiting: 0

 

 

NginxStatus 显示的内容意思如下:

  • active connections – 当前 Nginx 正处理的活动连接数。
  • server accepts handled requests -- 总共处理了 14553819 个连接 , 成功创建 14553819 次握手 ( 证明中间没有失败的 ), 总共处理了 19239266 个请求 ( 平均每次握手处理了 1.3 个数据请求 )。
  • reading -- nginx 读取到客户端的 Header 信息数。
  • writing -- nginx 返回给客户端的 Header 信息数。
  • waiting -- 开启 keep-alive 的情况下,这个值等于 active - (reading + writing),意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接。

 

-------------------------------静态文件处理

通过正则表达式,我们可让 Nginx 识别出各种静态文件

 

location ~ \.(htm|html|gif|jpg|jpeg|png|bmp|ico|css|js|txt)$ {
        root /var/www/nginx-default/html;
        expires 24h;
        }

对于例如图片、静态 HTML 文件、js 脚本文件和 css 样式文件等,我们希望 Nginx 直接处理并返回给浏览器,这样可以大大的加快网页浏览时的速度。因此对于这类文件我们需要通过 root 指令来指定文件的存放路径,同时因为这类文件并不常修改,通过 expires 指令来控制其在浏览器的缓存,以减少不必要的请求。 expires 指令可以控制 HTTP 应答中的“ Expires ”和“ Cache-Control ”的头标(起到控制页面缓存的作用)。您可以使用例如以下的格式来书写 Expires:

 

 

expires 1 January, 1970, 00:00:01 GMT;
expires 60s;
expires 30m;
expires 24h;
expires 1d;
expires max;
expires off;

 

 

这样当你输入http://192.168.200.100/1.html的时候会自动跳转到var/www/nginx-default/html/1.html

 

例如 images 路径下的所有请求可以写为:

 

 

 

 

location ~ ^/images/ {
    root /opt/webapp/images;
}

 

 

 

 

------------------------动态页面请求处理[集群]

Nginx 本身并不支持现在流行的 JSP、ASP、PHP、PERL 等动态页面,但是它可以通过反向代理将请求发送到后端的服务器,例如 Tomcat、Apache、IIS 等来完成动态页面的请求处理。前面的配置示例中,我们首先定义了由 Nginx 直接处理的一些静态文件请求后,其他所有的请求通过 proxy_pass 指令传送给后端的服务器 (在上述例子中是 Tomcat)。最简单的 proxy_pass 用法如下:

 

location / {
    proxy_pass        http://localhost:8080;
    proxy_set_header  X-Real-IP  $remote_addr;
}

 

 

这里我们没有使用到集群,而是将请求直接送到运行在 8080 端口的 Tomcat 服务上来完成类似 JSP 和 Servlet 的请求处理。

当页面的访问量非常大的时候,往往需要多个应用服务器来共同承担动态页面的执行操作,这时我们就需要使用集群的架构。 Nginx 通过 upstream 指令来定义一个服务器的集群,最前面那个完整的例子中我们定义了一个名为 tomcats 的集群,这个集群中包括了三台服务器共 6 个 Tomcat 服务。而 proxy_pass 指令的写法变成了:

 

 

 

# 集群中的所有后台服务器的配置信息
    upstream tomcats { 
     server 192.168.0.11:8080 weight=10; 
     server 192.168.0.11:8081 weight=10; 
     server 192.168.0.12:8080 weight=10; 
     server 192.168.0.12:8081 weight=10; 
     server 192.168.0.13:8080 weight=10; 
     server 192.168.0.13:8081 weight=10; 
    } 
    location / { 
        proxy_pass http://tomcats;# 反向代理
        include proxy.conf; 
        } 

 

 

----------------------压力测试

wget http://blog.s135.com/soft/linux/webbench/webbench-1.5.tar.gz   
tar zxvf webbench-1.5.tar.gz   
cd webbench-1.5   
make && make install

#webbench -c 100 -t 10 http://192.168.200.100/info.php

参数说明:-c表示并发数,-t表示持续时间(秒)

 

 

root@ubuntu-desktop:/etc/nginx/sites-available# webbench -c 100 -t 10 http://192.168.200.100/info.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.200.100/info.php
100 clients, running 10 sec.

Speed=19032 pages/min, 18074373 bytes/sec.
Requests: 3172 susceed, 0 failed.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

曾经配置过nginx比较高版本的安装方法及流程,这次也是在阿里云服务器ubuntu14.04.1版本安装nginx+php+mysql的方法及流程。

原文地址:http://adminsir.net/Home/Content/index/id/7.html

 

 

1、先更新ubuntu系统

更新命令

sudo apt-get update
sudo apt-get upgrade

2、更新和安装update and install

 

sudo apt-get update
sudo apt-get install nginx

3、启动nginx

 

sudo /etc/init.d/nginx start

4、check version(说明安装成功)

 

nginx -v 

5、配置php+mysql

 

sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql

6、安装FastCgi

 

sudo apt-get install spawn-fcgi

7、配置nginx

7.1、修改nginx的配置文件:/etc/nginx/sites-available/default 修改主机名

server_name localhost;

7.2、修改index的一行,添加index.php

index index.php index.html index.htm;

7.3、去掉下面部分的注释用于支持 php 脚本:

 

location ~ .php$ {
                fastcgi_split_path_info ^(.+.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
                fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
        #       fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        }

8、 重新启动nginx

 

sudo /etc/init.d/nginx restart
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start

 

9、启动fastcgi php

spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi

10、nginx提示502 Bad Gateway错误

nginx 502 Bad Gateway错误之一:Fastcgi没有启动,启动命令是:

 

spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi

 

11、设置php-cgi开机自启动

为了让php-cgi开机自启动:Ubuntu开机之后会执行/etc/rc.local文件中的脚本

所以我们可以直接在/etc/rc.local中添加启动脚本。

 

spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi 
添加到语句:
 exit 0

前面才行

12、no input file specified错误

 

sudo vi /etc/nginx/sites-available/default
location ~ .php$ {
 root html;
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php; 
fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
 include fastcgi_params;
 }

 

location ~ .php$ {
                fastcgi_split_path_info ^(.+.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
                fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
        #       fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

注意

 

 

 

fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;

 

/var/www/nginx-default 改为你的网站根目录,一般就是改成这个。 server 字段下root 目录和网站根目录保持一致

 

 

 

 

 

 

 

 

 

 

 

 

Ubuntu下安装nginx

sudo apt-get install nginx

Ubuntu安装之后的文件结构大致为:

所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下

程序文件在/usr/sbin/nginx

日志放在了/var/log/nginx中

并已经在/etc/init.d/下创建了启动脚本nginx

默认的虚拟主机的目录设置在了/var/www/nginx-default

启动nginx

sudo /etc/init.d/nginx start

然后就可以访问了,http://localhost/ , 一切正常!如果不能访问,先不要继续,看看是什么原因,解决之后再继续。

bubuko.com,布布扣

nginx默认页面

配置php和mysql

安装Php和mysql

安装php和MySQL:

sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql

安装FastCgi

/usr/bin/spawn-fcgi这个文件来管理 FastCgi,它原属于lighttpd这个包里面,但 9.10 后,spawn-fcgi 被分离出来单独成包:

sudo apt-get install spawn-fcgi

配置 nginx

修改nginx的配置文件:/etc/nginx/sites-available/default 修改主机名:

server_name localhost;

修改index的一行修改为:

index index.php index.html index.htm;

去掉下面部分的注释用于支持 php 脚本:

location ~ \.php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;

include /etc/nginx/fastcgi_params;

}

重新启动nginx:

/etc/init.d/nginx stop

/etc/init.d/nginx start

启动fastcgi php:

spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi

为了让php-cgi开机自启动:

cd /etc/init.d

cp nginx php-cgi

vim php-cgi

替换nginx为php-cgi

并修改相应部分为:

DAEMON=/usr/bin/spawn-fcgi

DAEMON_OPTS="-a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi"

...

stop)

echo -n "Stopping $DESC: "

pkill -9 php-cgi

echo "$NAME."

然后运行rcconf设置php-cgi为开机自启动

创建、测试phpinfo:

sudo vi /var/www/nginx-default/info.php

打开 http://localhost/info.php 。

bubuko.com,布布扣
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
环境:ubuntu 12.0.4 LTS
nginx(发音"engine x")是一个自由,开放源码,高性能的HTTP server。Nginx以稳定性,丰富的功能集,简单的配置,和低资源消耗而出名。本文将向你展示怎么在ubuntu 12.0.4 LTS 上安装Nginx,php5(及php-fpm),mysql。
 
 
一:安装前做个简单的说明
我使用的域名为example.com,ip地址是218.198.177.252。你可以视具体情况更改这些设置。在下文中我将使用root权限安装所需软件,所以请先切换到root用户:sudo su
 
 
二:安装MySQL
 
 
apt-get install mysql-server mysql-client
 
安装过程会提示你为MySQL root 用户提供一个密码----这个密码对 root@localhost可用,同时对root@example.com也可用,因此你需要手动为MySQL root用户指定一个密码:
New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword
 
 
三:安装Nginx
 
apt-get install nginx
 
1,启动nginx
/etc/init.d/nginx start
 
2,打开浏览器输入http://127.0.0.1,如果看到Welcome to nginx!,则说明安装成功,ubuntu 12.0.4 LTS上nginx默认的网站根目录在 /usr/share/nginx/www。
 
 
四:安装PHP5
PHP5可以在nginx上通过PHP-FPM(PHP—FPM(FastCGI Process Manager) 是一个可选的 FastCGI,添加了一些了一些很有用的特性,特别是对于繁忙的站点)工作。
说明:Nginx不支持对外部程序的直接调用或解析,所有的外部程序(包括PHP)必须通过FastCGI接口调用。
 
apt-get install php5-fpm
 
PHP-FPM是一个守护进程(init脚本文件在/etc/init.d/php5-fpm),它运行了一个FastCGI server,端口是 9000。
 
 
 
五:配置 nginx,以下是我本机的配置文件。
 
1,nginx的配置文件在/etc/nginx/nginx.conf, vim /etc/nginx/nginx.conf 如下:
 
 
user www-data;        //指定Nginx Worker 进程运行用户及用户组
worker_processes 4;      / /指定Nginx开启的进程数,每个Nginx进程平均耗费10M-20M内存。
pid /var/run/nginx.pid;    //用来指定进程id的存储文件的位置
 
events {                      //用来指定Nginx的工作模式,及连接上限数
           use epoll;       
           worker_connections 768;
           # multi_accept on;
}
 
http {
 
        ##
        # Basic Settings    //基本的设置
        ##
 
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;
 
        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;
 
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
 
        ##
        # Logging Settings   //指定日志的存放路径
        ##
 
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
 
        ##
        # Gzip Settings         //开启Gzip 压缩
        ##
 
        gzip on;
        gzip_disable "msie6";
 
         gzip_vary on;
         gzip_proxied any;
         gzip_comp_level 6;
         gzip_buffers 16 8k;
         gzip_http_version 1.1;
         gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
 
        ##
        # nginx-naxsi config
        ##
        # Uncomment it if you installed nginx-naxsi
        ##
 
        #include /etc/nginx/naxsi_core.rules;
 
        ##
        # nginx-passenger config
        ##
        # Uncomment it if you installed nginx-passenger
        ##
 
        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;
 
        ##
        # Virtual Host Configs      //虚拟主机的配置
        ##
 
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
 
 
}
#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}
 
2,虚拟主机被定义在server{}中,默认文件在/etc/nginx/sites-available/default,vim /etc/nginx/sites-available/default。
 
server {
        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default ipv6only=on; ## listen for ipv6
        root /usr/share/nginx/www;
        index index.php index.html index.htm;
        # Make site accessible from http://localhost/
        server_name _;
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
        }
        location /doc {
                root /usr/share;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }
        location /images {
                root /usr/share;
                autoindex off;
        }
        #error_page 404 /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/www;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #       proxy_pass http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi_params;
        }
        # deny access to .htaccess files, if Apache‘s document root
        # concurs with nginx‘s one
        #
        location ~ /\.ht {
                deny all;
        }
}
 
 
3,保存文件,使配置生效 /etc/init.d/nginx reload
 
 
4,在Nginx的默认网站根目录创建一个PHP的测试文件 vim /usr/share/nginx/www/info.php
 
<? php
phpinfo();
?>
 
5,打开浏览器输入http://127.0.0.1/info.php
 
 
你可以看见PHP5已经通过FPM/FastCGI工作了,具体可看Server API那行。向下滚动可以看见所有的模块在PHP5中都是可用的,MySQL还没有被列出来,意味着MySQL还没支持PHP5。
 
 
 
六:让MySQL支持PHP5
 
1,让MySQL支持PHP5,我们可以安装php5-mysql包。其余的包,我们可以按需安装所需要的包,用apt-cache search php5列出PHP的包,看下那个是你所需要的。
 
2,选择一些你所需要的包,象这样安装:
apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
 
 
3,重启PHP-FPM
/etc/init.d/php5-fpm restart
 
 
4,打开浏览器,输入http://127.0.0.1/info.php,看下你安装的包是不是已经被支持了。
 
 
 七:配置PHP-FPM, vim /etc/php5/fpm/php-fpm.conf 或在 vim /etc/php5/fpm/conf.d/下做更详细的配置,不懂真人的默认就行了 ,也不优化了。
 
  
八:在/etc/nginx/sites-available/default中新增一个虚拟主机,看下效果。
 
我的配置文件:
 
server {
        listen   80 ; ## listen for ipv4; this line is default and implied
#       listen   [::]:80 default ipv6only=on; ## listen for ipv6
 
        root /web/example;
        index index.php index.html index.htm;
 
        # Make site accessible from http://localhost/
        server_name 218.198.177.252 example.com ;   //这个和apache一样的啦,写域名就行了
 
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }
 
        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }
 
        # Only for nginx-naxsi : process denied requests
        #location /RequestDenied {
                # For example, return an error code
                #return 418;
        #}
 
        #error_page 404 /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        #error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /web/example;
        }
 
location ~ \.php$ {     //nginx处理静态的页面,动态的转给FastCGI处理
        #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
                 fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
        #       fastcgi_pass unix:/var/run/php5-fpm.sock;
                 fastcgi_index index.php;
                 include fastcgi_params;
        }
 
        # deny access to .htaccess files, if Apache‘s document root
        # concurs with nginx‘s one
        #
        location ~ /\.ht {
                deny all;
        }
}
 
 

Ubuntu下安装Nginx,PHP5(及PHP-FPM),MySQL

标签:des   style   blog   http   io   ar   color   os   使用   

原文地址:http://www.cnblogs.com/steven9801/p/4151220.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!