LNMP

Linux + niginx + php(fpm) 安装与配置

1、安装nginx   

  更新好源之后,运行     

sudo apt-get install nginx

  nginx运行指令:

sudo /etc/init.d/nginx {start|stop|restart|reload|force-reload|status|configtest} 

  Nginx服务器开启之后在浏览器地址栏输入localhost后出现nginx服务器欢迎语则说明服务器安装成功。 

2、安装MYSQL

sudo apt-get install mysql-server mysql-client

3、安装php   

sudo apt-get install php5-fpm php5-cli php5-mysql

4、配置nginx服务器   

  当php5-fpm安装完成后我们开始配置nginx服务器,在/etc/nginx/nginx.conf文件的http{}部分下添加:

# Upstream to abstract back-end connection(s) for PHP
upstream php {
    server unix:/tmp/php5-fpm.sock;
}

  虚拟主机配置文件的修改(/etc/nginx/sites-enabled/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 localhost;
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
        }

        #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_split_path_info ^(.+\.php)(/.+)$;
           #fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
         include fastcgi_params;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all;   } }

  完成虚拟主机的配置后还需要修改php5-fpm的配置文件(/etc/php5/fpm/pool.d/www.conf):

listen = 127.0.0.1:9000
改为:
listen = /tmp/php5-fpm.sock

 4、完成虚拟主机配置文件的修改后重启nginx服务器以及php5-fpm,运行:

sudo service nginx restart
sudo service php5-fpm restart

 5、测试环境

  //Info.php
  <?php 
    Echo phpinfo();
  ?>

6、安装phpmyadmin

sudo apt-get install phpmyadmin
cd /usr/share/nginx/www
sudo ln -s  /usr/share/phpmyadmin 

 

posted @ 2013-11-18 22:06  boyz  阅读(297)  评论(0编辑  收藏  举报