1. 程式人生 > >Ubuntu14.04搭建LNMP平臺

Ubuntu14.04搭建LNMP平臺

soc filename 平臺 com 新源 splay oot location rgb

更新源:

apt-get install update

關閉apache2:

/etc/init.d/apache2 stop

安裝nginx:

apt-get install nginx

安裝MYSQL:

apt-get install mysql-server #連續輸入兩次相同密碼,密碼為mysql管理賬戶所使用

安裝PHP:

apt-get install php5-fpm php5-mysql

配置PHP,修改php.ini文件:

cp /etc/php5/fpm/php.ini /etc/php5/fpm/php.ini.back #備份php.ini文件

vim /etc/php5/fpm/php.ini

cgi.fix_pathinfo=0 #取消有安全隱患的pathinfo模式

啟動php-fpm

service php5-fpm restart

配置nginx,讓其使用php5-fpm進程

cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.back

vim /etc/nginx/sites-available/default

server {

listen 80 default_server;

listen [::]:80 default_server ipv6only=on;


root /usr/share/nginx/html;

index index.html index.htm;


server_name localhost;


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

}

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)(/.+)$;

# # 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;

# fatcgi_param SCRITP_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

}

重啟nginx服務:

service nginx restart

建立info.php測試文件:

vim /usr/share/nginx/html/info.php

<?php

phpinfo();

?>

瀏覽器測試:

http://IP/info.php


將制作的php網頁頁面原文件上傳至/usr/share/nginx/html/目錄下即可


Ubuntu14.04搭建LNMP平臺