1. 程式人生 > >lnmp一鍵腳本以及相關配置

lnmp一鍵腳本以及相關配置

eat home 安裝使用 l數據庫 rul 相關 inno 執行 ubun

lnmp一鍵腳本以及相關配置

下面是來自lnmp腳本官方的說明:
系統需求:

CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian/Deepin/Aliyun/Amazon/Mint Linux發行版
需要5GB以上硬盤剩余空間,MySQL 5.7,MariaDB 10至少9GB剩余空間
需要128MB以上內存(128MB小內存VPS,Xen需有SWAP,OpenVZ至少要有128MB以上的vSWAP或突發內存),註意小內存請勿使用64位系統!
安裝MySQL 5.6或5.7及MariaDB 10必須1G以上內存!。
VPS或服務器必須已經聯網且必須設置的是網絡源不能是光盤源,同時VPS/服務器DNS要正常!
Linux下區分大小寫,輸入命令時請註意!
如有通過yum或apt-get安裝的MySQL/MariaDB請自行備份數據等相關文件!
CentOS 5,Debian 6及之前版本其官網已經結束支持無法使用!
一、LNMP的安裝

一鍵安裝,直接命令行運行下面命令:
wget http://soft.vpser.net/lnmp/lnmp1.5.tar.gz -cO lnmp1.5.tar.gz && tar zxf lnmp1.5.tar.gz && cd lnmp1.5 && ./install.sh lnmp

以下為安裝前簡易設置,切記牢記mysql密碼:

  +------------------------------------------------------------------------+
    |          LNMP V1.5 for CentOS Linux Server, Written by Licess          |
    +------------------------------------------------------------------------+
    |        A tool to auto-compile & install LNMP/LNMPA/LAMP on Linux       |
    +------------------------------------------------------------------------+
    |           For more information please visit https://lnmp.org           |
    +------------------------------------------------------------------------+
    You have 10 options for your DataBase install.
    1: Install MySQL 5.1.73
    2: Install MySQL 5.5.60 (Default)
    3: Install MySQL 5.6.40
    4: Install MySQL 5.7.22
    5: Install MySQL 8.0.11
    6: Install MariaDB 5.5.60
    7: Install MariaDB 10.0.35
    8: Install MariaDB 10.1.33
    9: Install MariaDB 10.2.14
    0: DO NOT Install MySQL/MariaDB
    Enter your choice (1, 2, 3, 4, 5, 6, 7, 8, 9 or 0): #選擇mysql版本 默認為5.5.60
    No input,You will install MySQL 5.5.60
    ===========================
    Please setup root password of MySQL.
    Please enter: maizim.com #輸入mysql的密碼
    ===========================
    Do you want to enable or disable the InnoDB Storage Engine?
    Default enable,Enter your choice [Y/n]: n #是否安裝InnoDB環境 默認不需要 whmcs之類特殊程序需求
    You will disable the InnoDB Storage Engine!
    ===========================
    You have 8 options for your PHP install.
    1: Install PHP 5.2.17
    2: Install PHP 5.3.29
    3: Install PHP 5.4.45
    4: Install PHP 5.5.38
    5: Install PHP 5.6.36 (Default)
    6: Install PHP 7.0.30
    7: Install PHP 7.1.18
    8: Install PHP 7.2.6
    Enter your choice (1, 2, 3, 4, 5, 6, 7 or 8): 8 #默認php版本 這裏選擇最新
    You will install PHP 7.2.6
    ===========================
    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 這個默認選擇不安裝即可
    You will install not install Memory Allocator.

按任意鍵,設置完成,正式進入安裝,預計20-40分鐘完成

二、安裝完成

如果顯示Nginx: OK,MySQL: OK,PHP: OK
技術分享圖片
並且Nginx、MySQL、PHP都是running,80和3306端口都存在,並提示安裝使用的時間及Install lnmp V1.5 completed! enjoy it.的話,說明已經安裝成功。

三、常見lnmp管理命令:

1.2版本以後,不需要再執行/root/lnmp了,可以在任意位置執行lnmp命令
lnmp #會出現一些提示信息
lnmp restart #重啟
lnmp vhost add #添加網站綁定
lnmp database add #添加數據庫信息

四,域名綁定:
lnmp vhost add #執行lnmp添加網站命令
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
Please enter domain(example: www.lnmp.org): maizim.com #輸入綁定的主域名
======================================
 Your domain: maizim.com
======================================
Do you want to add more domain name? (y/n) y #是否綁定其它域名
Enter domain name(example: lnmp.org *.lnmp.org): www.maizim.com #輸入其它域名
domain list: www.maizim.com
Please enter the directory for the domain: maizim.com
(Default directory: /data/webroot/maizim.com): #默認創建的網站文件所在目錄
Virtual Host Directory: /data/webroot/maizim.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: maizim_user #創建數據庫用戶名
Your will create a database and MySQL user with same name: maizim_user
Please enter password for mysql user maizim_user: maizimpasswd
Your password: maizimpasswd #創建相應密碼

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 maizim_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: maizim_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 maizim_user Sucessfully.
Warning: Using a password on the command line interface can be insecure.
FLUSH PRIVILEGES Sucessfully.
================================================
Virtualhost infomation:
Your domain: maizim.com
Home Directory: /data/webroot/maizim.com
Rewrite: typecho
Enable log: no
Database username: maizim_user
Database userpassword: maizimpasswd
Database Name: maizim_user
Create ftp account: no

================================================

五、自定義偽靜態規則

如果你要自行定義偽靜態規則,可以新建一個conf文件,放置於 /usr/local/nginx/conf 下,在域名配置文件,即:/usr/local/nginx/conf/vhost/maizim.com.conf 裏引用。

server
  {
    listen       80;
    server_name maizim.com www.maizim.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;
  }

修改設置以後,重新載入nginx,或者重新載入lnmp,效果是一樣的:

只重新載入nginx配置

/etc/init.d/nginx reload 

或者lnmp整個重新載入配置

/root/lnmp reload 

六、自定義404、503等常見錯誤
</blockquote>

不管是404還是503等常見錯誤,還是設置/usr/local/nginx/conf/vhost/maizim.com.conf文件來完成:

   listen       80;
    server_name maizim.com www.maizim.com;
    index index.html index.htm index.php default.html default.htm default.php;
    root  /data/webroot/maizim.com;
    error_page 404 /404.php; #放在這裏,可自定義文件名,再重載nginx就可以了
    include typecho.conf;
七、判斷當前域名並自動301到主域名
if ($host != ‘maizim.com‘ ) {rewrite ^/(.*)$ http://www.maizim.com/$1 permanent;}
八、關閉或開啟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

九、升級PHP和NGINX版本

升級nginx,只要輸入你要升級的版本即可(可見nginx.org)
cd lnm0.9 #進入lnmp安裝目錄
./upgrade_nginx.sh
升級php,只要輸入你要升級的版本即可(可見php.net)
./upgrade_php.sh

原文鏈接:https://www.maizim.com/103.html

lnmp一鍵腳本以及相關配置