使用LNMP常見問題解答

使用LNMP常見問題解答

1、LNMP的安裝過程詳解,注:綠色文字爲註釋,實際使用過程當中沒有。php

##先要下載,並根據不一樣系統進行安裝:
tar zxvf lnmp1.0.tar.gz
cd lnmp1.0
./centos.sh #若是您是其它系統,則命令改成:./ubuntu.sh 或 debian.sh

以上爲下載及進入安裝過程,如下爲安裝前簡易設置,切記輸入個其它域名及牢記mysql密碼:css

=========================================================================
LNMP V1.0 for CentOS/RadHat Linux VPS  Written by Licess
=========================================================================
A tool to auto-compile & install Nginx+MySQL+PHP on Linux
 
For more information please visit http://www.lnmp.org/
=========================================================================
===========================
Please input the root password of mysql:
(Default password: root):vpsmm.com #請輸入mysql密碼
===========================
MySQL root password:vpsmm.com
===========================
===========================
Do you want to install the InnoDB Storage Engine?
(Default no,if you want please input: y ,if not please press the enter button):
INPUT error,The InnoDB Storage Engine will NOT install! #是否安裝InnoDB
===========================
Install PHP 5.3.17,Please input y
Install PHP 5.2.17,Please input n or press Enter
(Please input y or n):y #選擇php版本
You will install PHP 5.3.17
===========================
Install MySQL 5.5.27,Please input y
Install MySQL 5.1.60,Please input n or press Enter
(Please input y or n):y #選擇mysql版本
You will install MySQL 5.5.27
Press any key to start...or Press Ctrl+c to cancel
CentOS release 6.3 (Final)#按任意鍵,設置完成,正式進入安裝,預計20-40分鐘完成

二,域名綁定詳解html

其實所謂的域名綁定,就是經過命令的形式,簡易建立一個conf文件到/usr/local/nginx/conf/vhost下面,這個過程徹底能夠手工建立conf,或者,平時修改目錄、域名等,直接修改conf文件,效果徹底同樣:mysql

/root/vhost.sh #lnmp域名綁定命令
=========================================================================
Add Virtual Host for LNMP V0.9  ,  Written by Licess
=========================================================================
LNMP is a tool to auto-compile & install Nginx+MySQL+PHP on Linux
This script is a tool to add virtual host for nginx
For more information please visit http://www.lnmp.org/
=========================================================================
Please input domain:
(Default domain: www.lnmp.org):legcloud.com #輸入你要綁定的域名,legcould和www.legcloud要分別綁定
===========================
domain=legcloud.com
===========================
Do you want to add more domain name? (y/n)
y #是否添加子域名,能夠輸入y或n,這裏輸入y
Type domainname,example(bbs.vpser.net forums.vpser.net luntan.vpser.net):
www.legcloud.com #輸入你要綁定的其它域名,支持泛解析,例如:*.legcloud.com
===========================
domain list=www.legcloud.com
===========================
Please input the directory for the domain:legcloud.com :
(Default directory: /home/wwwroot/legcloud.com):/home/legcloud.com #網站存放目錄,可默認或自行輸入
===========================
Virtual Host Directory=/home/legcloud.com
===========================
===========================
Allow Rewrite rule? (y/n)
===========================
y #是否添加僞靜態規則,這裏輸入是
Please input the rewrite of programme :
wordpress,discuz,typecho,sablog,dabr rewrite was exist.
(Default rewrite: other):wordpress #輸入wordpress就能夠
===========================
You choose rewrite=wordpress
===========================
===========================
Allow access_log? (y/n)
===========================
n #是否建立日誌文件,若是不須要可不用
Press any key to start create virtul host...
#按任意建繼續,如下爲一些相關信息,包括建立目錄,測試nginx等,若是有錯誤提示,請必定要認真分析
Create Virtul Host directory......
set permissions of Virtual Host directory......
You select the exist rewrite rule:/usr/local/nginx/conf/wordpress.conf
Test Nginx configure file......
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Restart Nginx......
=========================================================================
Add Virtual Host for LNMP V0.9  ,  Written by Licess
=========================================================================
For more information please visit http://www.lnmp.org/
Your domain:legcloud.com
Directory of legcloud.com:/home/legcloud.com
=========================================================================

3、自定義僞靜態規則nginx

若是lnmp默認的僞靜態規則不能知足你的須要,或者,你要自行定義僞靜態規則,能夠新建一個conf文件,放置於 /usr/local/nginx/conf 下,在域名配置文件,即:/usr/local/nginx/conf/vhost/legcloud.com.conf 裏引用。sql

server
{
listen       80;
server_name legcloud.com www.legcloud.com; #綁定的域名
index index.html index.htm index.php default.html default.htm default.php; #首頁文件
root  /home/legcloud.com; #網站存放目錄
include wordpress.conf; #僞靜態規則文件,可自定義成你須要的
location ~ .*\.(php|php5)?$
{
try_files $uri =404;
fastcgi_pass  unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires      30d;
}
location ~ .*\.(js|css)?$
{
expires      12h;
}
access_log off;
}

修改設置之後,必定要從新載入lnmp或者,從新載入nginx,如下任決命令都同樣:ubuntu

/root/lnmp reload #使用lnmp從新載入配置
/etc/init.d/nginx reload #只從新載入nginx配置,我通常用這個

4、自定義40四、503等常見錯誤centos

無論是404仍是503等常見錯誤,仍是設置/usr/local/nginx/conf/vhost/legcloud.com.conf文件來完成:dom

listen       80;
server_name legcloud.com www.legcloud.com;
index index.html index.htm index.php default.html default.htm default.php;
root  /home/legcloud.com;
error_page 404 /404.php; #放在這裏,可自定義文件名,再重載nginx就能夠了
include wordpress.conf;

5、判斷當前域名並自動301到主域名wordpress

if ($host != 'vpsmm.com' ) {rewrite ^/(.*)$ http://www.vpsmm.com/$1 permanent;}
#判斷當前域名,若是不是則自動301到主域名,放置於error_page ...;上下都可。

6、關閉或開啓FSO等php函數

lnmp最新版,默認禁用了一些函數,例如fso等,可修改/usr/local/php/etc/php.ini

disable_functions = passthru,exec,system,chroot,scandir....
#----這是禁用函數,把不想禁用的刪除便可----若是自用主機,最簡單的修改方案:
disable_functions =
; passthru,exec,system,chroot,scandir....
#----設置爲所有開啓

修改後,使用/etc/init.d/php-fpm restart,從新啓動php

7、升級PHP和NGINX版本

cd lnm0.9 #進入lnmp安裝目錄
./upgrade_nginx.sh #升級nginx,只要輸入你要升級的版本便可(可見nginx.org)
./upgrade_php.sh #升級php,只要輸入你要升級的版本便可(可見php.net)
相關文章
相關標籤/搜索