1、LNMP的安裝php
##先要下載,並根據不一樣系統進行安裝: wget -c http://soft.vpser.net/lnmp/lnmp1.3.tar.gz tar zxvf lnmp1.3.tar.gz cd lnmp1.3 ./install.sh #開始進行安裝操做
以上爲下載及進入安裝過程,如下爲安裝前簡易設置,切記輸入個其它域名及牢記mysql密碼:css
+------------------------------------------------------------------------+ | LNMP V1.2 for Ubuntu Linux Server, Written by Licess | +------------------------------------------------------------------------+ | A tool to auto-compile & install LNMP/LNMPA/LAMP on Linux | +------------------------------------------------------------------------+ | For more information please visit http://www.lnmp.org | +------------------------------------------------------------------------+ Please setup root password of MySQL.(Default password: root) Please enter: vpsmm.com #輸入mysql的root密碼 MySQL root password: vpsmm.com =========================== Do you want to enable or disable the InnoDB Storage Engine? Default enable,Enter your choice [Y/n]: n #是否安裝InnoDB You will disable the InnoDB Storage Engine! =========================== You have 5 options for your DataBase install. 1: Install MySQL 5.1.73 2: Install MySQL 5.5.42 (Default) 3: Install MySQL 5.6.23 4: Install MariaDB 5.5.42 5: Install MariaDB 10.0.17 Enter your choice (1, 2, 3, 4 or 5): 3 #選擇mysql版本 You will Install MySQL 5.6.23 =========================== You have 5 options for your PHP install. 1: Install PHP 5.2.17 2: Install PHP 5.3.29 3: Install PHP 5.4.41 (Default) 4: Install PHP 5.5.25 5: Install PHP 5.6.9 Enter your choice (1, 2, 3, 4 or 5): 5 #選擇php版本 You will install PHP 5.6.9 =========================== You have 3 options for your Memory Allocator install. 1: Don't install Memory Allocator. (Default) 2: Install Jemalloc 3: Install TCMalloc Enter your choice (1, 2 or 3): 1 #小夜用不上,因此選擇1 You will install not install Memory Allocator. #按任意鍵,設置完成,正式進入安裝,預計20-40分鐘完成
常見lnmp管理命令:html
#1.2版本之後,不須要再執行/root/lnmp了,能夠在任意位置執行lnmp命令 lnmp #會出現一些提示信息 lnmp restart #重啓 lnmp vhost add #添加網站綁定 lnmp database add #添加數據庫信息
二,域名綁定詳解mysql
其實所謂的域名綁定,就是經過命令的形式,簡易建立一個conf文件到/usr/local/nginx/conf/vhost下面,這個過程徹底能夠手工建立conf,或者,平時修改目錄、域名等,直接修改conf文件,效果徹底同樣:nginx
lnmp vhost add #執行lnmp添加網站命令 +-------------------------------------------+ | Manager for LNMP, Written by Licess | +-------------------------------------------+ Please enter domain(example: www.lnmp.org): vpsmm.com #輸入綁定的主域名 ====================================== Your domain: vpsmm.com ====================================== Do you want to add more domain name? (y/n) y #是否綁定其它域名 Enter domain name(example: lnmp.org *.lnmp.org): www.vpsmm.com #輸入其它域名 domain list: www.vpsmm.com Please enter the directory for the domain: vpsmm.com (Default directory: /home/wwwroot/vpsmm.com): #默認建立的網站文件所在目錄 Virtual Host Directory: /home/wwwroot/vpsmm.com =========================== Allow Rewrite rule? (y/n) =========================== y #是否添加僞靜態文件 Please enter the rewrite of programme: wordpress,discuz,typecho,sablog,dabr rewrite was exist. (Default rewrite: other):typecho #小夜用的typecho程序 =========================== You choose rewrite=typecho =========================== =========================== Allow access_log? (y/n) =========================== n #是否啓用日誌文件 ====================================================== Create database and MySQL user with same name (y/n) ====================================================== y #是否建立mysql數據庫 verify your current MySQL root password: **** #輸入安裝時的mysql數據庫root密碼 Warning: Using a password on the command line interface can be insecure. MySQL root password correct. Enter database name: vpsmm_user #建立數據庫用戶名 Your will create a database and MySQL user with same name: vpsmm_user Please enter password for mysql user vpsmm_user: vpsmmpasswd Your password: vpsmmpasswd #建立相應密碼 Press any key to start create virtul host... Create Virtul Host directory...... set permissions of Virtual Host directory...... You select the exist rewrite rule:/usr/local/nginx/conf/typecho.conf Gracefully shutting down php-fpm . done Starting php-fpm done 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...... Warning: Using a password on the command line interface can be insecure. Warning: Using a password on the command line interface can be insecure. User vpsmm_user create Sucessfully. Warning: Using a password on the command line interface can be insecure. Warning: Using a password on the command line interface can be insecure. Warning: Using a password on the command line interface can be insecure. Database: vpsmm_user create Sucessfully. Warning: Using a password on the command line interface can be insecure. Warning: Using a password on the command line interface can be insecure. GRANT ALL PRIVILEGES ON vpsmm_user Sucessfully. Warning: Using a password on the command line interface can be insecure. FLUSH PRIVILEGES Sucessfully. ================================================ Virtualhost infomation: Your domain: vpsmm.com Home Directory: /home/wwwroot/vpsmm.com Rewrite: typecho Enable log: no Database username: vpsmm_user Database userpassword: vpsmmpasswd Database Name: vpsmm_user Create ftp account: no #以上爲新建立網站的一些信息 ================================================
3、自定義僞靜態規則sql
若是lnmp默認的僞靜態規則不能知足你的須要,或者,你要自行定義僞靜態規則,能夠新建一個conf文件,放置於 /usr/local/nginx/conf 下,在域名配置文件,即:/usr/local/nginx/conf/vhost/legcloud.com.conf 裏引用。shell
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,如下任決命令都同樣:數據庫
/root/lnmp reload #使用lnmp從新載入配置 /etc/init.d/nginx reload #只從新載入nginx配置,我通常用這個
無論是404仍是503等常見錯誤,仍是設置/usr/local/nginx/conf/vhost/legcloud.com.conf文件來完成:wordpress
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;
if ($host != 'vpsmm.com' ) {rewrite ^/(.*)$ http://www.vpsmm.com/$1 permanent;} #判斷當前域名,若是不是則自動301到主域名,放置於error_page ...;上下都可。
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)