Lnmp網站的發佈

LNMP

LNMP表明的就是:Linux系統下Nginx+MySQL+PHP這種網站服務器架構。php

Linux是一類Unix計算機操做系統的統稱,是目前最流行的免費操做系統。表明版本有:debian、centos、ubuntu、fedora、gentoo等。html

Nginx是一個高性能的HTTP和反向代理服務器,也是一個IMAP/POP3/SMTP代理服務器。mysql

Mysql是一個小型關係型數據庫管理系統linux

PHP是一種在服務器端執行的嵌入HTML文檔的腳本語言。nginx

這四種軟件均爲免費開源軟件,組合到一塊兒,成爲一個免費、高效、擴展性強的網站服務系統。c++

LNMP特色

LNMP動態網站部署架構是一套由Linux + Nginx + MySQL + PHP組成的動態網站系統解決方案,具備免費、高效、擴展性強且資源消耗低等優良特性。算法

Nginx是一款至關優秀的用於部署動態網站的輕量級服務程序,它最初是爲俄羅斯門戶站點而開發的,因其穩定性、功能豐富、佔用內存少且併發能力強而備受用戶的信賴。目前國內諸如新浪、網易、騰訊等門戶站點均已使用了此服務。sql

Nginx服務程序的穩定性源自於採用了分階段的資源分配技術,下降了CPU與內存的佔用率,因此使用Nginx程序部署的動態網站環境不只十分穩定、高效,並且消耗的系統資源也不多。此外,Nginx具有的模塊數量與Apache具有的模塊數量幾乎相同,並且如今已經徹底支持proxy、rewrite、mod_fcgi、ssl、vhosts等經常使用模塊。更重要的是,Nginx還支持熱部署技術,能夠7×24不間斷提供服務,還能夠在不暫停服務的狀況下直接對Nginx服務程序進行升級。docker

坦白來說,雖然Nginx程序的代碼質量很是高,代碼很規範,技術成熟,模塊擴展也很容易,但依然存在很多問題,好比是由俄羅斯人開發的,因此在資料文檔方面還並不完善,中文資料的質量更是魚龍混雜。可是Nginx服務程序在近年來增加勢頭迅猛,相信會在輕量級Web服務器市場具備不錯的將來。shell


PHP(Hypertxt Preprocessor,超文本預處理器)是一種通用的開源腳本語言,發明於1995年,它吸收了C語言、Java語言及Perl語言的不少優勢,具備開源、免費、快捷、跨平臺性強、效率高等優良特性,是目前Web開發領域最經常使用的語言之一。

LNMP優勢

做爲 Web 服務器:相比 Apache,Nginx 使用更少的資源,支持更多的併發鏈接,體現更高的效率。

做爲負載均衡服務器:Nginx 既能夠在內部直接支持RailsPHP,也能夠支持做爲 HTTP代理服務器對外進行服務。Nginx 用C編寫,不管是系統資源開銷仍是CPU使用效率都比Perlbal要好的多。

做爲郵件代理服務器:Nginx同時也是一個很是優秀的郵件代理服務器(最先開發這個產品的目的之一也是做爲郵件代理服務器),Last/fm 描述了成功而且美妙的使用經驗。

Nginx 安裝很是的簡單,配置文件很是簡潔(還可以支持perl語法)。Nginx支持平滑加載新的配置,還可以在不間斷服務的狀況下進行軟件版本的升級。

源碼包安裝

在使用源碼包安裝服務程序以前,首先要讓安裝主機具有編譯程序源碼的環境,他須要具有C語言、C++語言、Perl語言的編譯器,以及各類常見的編譯支持函數庫程序。所以請先配置穩當Yum軟件倉庫

配置yum倉庫

[root@server222 ~]# tail -n 1 /etc/fstab/dev/cdrom      /mnt/cdrom      iso9660                 defaults        0 0[root@server222 ~]# mount -a[root@server222 ~]# vim /etc/yum.repos.d/bendi.repo[root@server222 ~]# cat /etc/yum.repos.d/bendi.repo[bendi]name=///mnt/cdrom
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=012345678910

安裝軟件包

[root@server222 ~]# yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel1

下載源碼包以及系統軟件包

而後咱們安裝LNMP動態網站部署架構所需的16個軟件源碼包和1個用於檢查效果的論壇網站系統軟件包

此處建議把要安裝的軟件包存放在/usr/local/src目錄中。

首先咱們建立/usr/local/src目錄

[root@server222 ~]# mkdir /usr/local/src1

源碼包文件已經放到百度雲盤裏面,下載下來傳到Linux系統裏面/usr/local/src目錄便可

連接:https://pan.baidu.com/s/1X-eh_SRBbpXcVuxcu62VTA
提取碼:ox0w
複製這段內容後打開百度網盤手機App,操做更方便哦

[root@server222 ~]# cd /usr/local/src[root@server222 src]# lscmake-2.8.11.2.tar.gz   libpng-1.6.12.tar.gz   php-5.5.14.tar.gz
Discuz_X3.2_SC_GBK.zip  libvpx-v1.3.0.tar.bz2  t1lib-5.1.2.tar.gz
freetype-2.5.3.tar.gz   mysql-5.6.19.tar.gz    tiff-4.0.3.tar.gz
jpegsrc.v9a.tar.gz      nginx-1.6.0.tar.gz     yasm-1.2.0.tar.gz
libgd-2.1.0.tar.gz      openssl-1.0.1h.tar.gz  zlib-1.2.8.tar.gz
libmcrypt-2.5.8.tar.gz  pcre-8.35.tar.gz12345678

若是是17個包就算OK,差一個都不行

安裝編譯工具

cmake是Linux系統中一款經常使用的編譯工具。

[root@server222 src]# tar xzvf cmake-2.8.11.2.tar.gz[root@server222 src]# cd cmake-2.8.11.2/[root@server222 cmake-2.8.11.2]# ./configure ; make ; make install123

此處命令./configure ; make ; make install

格式爲 命令A ; 命令B ; 命令C

這裏意思是先執行命令A再執行命令B最後執行命令C

配置MySQL服務

在使用Yum軟件倉庫安裝服務程序時,系統會自動根據RPM軟件包中的指令集完整軟件配置等工做。可是一旦選擇使用源碼包的方式來安裝,這一切就須要本身來完成了。針對MySQL數據庫來說,咱們須要在系統中建立一個名爲mysql的用戶,專門用於負責運行MySQL數據庫。請記得要把這類帳戶的Bash終端設置成nologin解釋器,避免***經過該用戶登陸到服務器中,從而提升系統安全性。

[root@server222 cmake-2.8.11.2]# cd ..[root@server222 src]# useradd mysql -s /sbin/nologin12

建立一個用於保存MySQL數據庫程序和數據庫文件的目錄,並把該目錄的全部者和所屬組身份修改成mysql。其中,/usr/local/mysql是用於保存MySQL數據庫服務程序的目錄,/usr/local/mysql/var則是用於保存真實數據庫文件的目錄。

[root@server222 src]# mkdir -p /usr/local/mysql/var[root@server222 src]# chown -Rf mysql:mysql /usr/local/mysql12

接下來解壓、編譯、安裝MySQL數據庫服務程序。在編譯數據庫時使用的是cmake命令

-DCMAKE_INSTALL_PREFIX參數用於定義數據庫服務程序的保存目錄

-DMYSQL_DATADIR參數用於定義真實數據庫文件的目錄

-DSYSCONFDIR則是定義MySQL數據庫配置文件的保存目錄

[root@server222 src]# tar xzvf mysql-5.6.19.tar.gz[root@server222 src]# cd mysql-5.6.19/[root@server222 mysql-5.6.19]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/var -DSYSCONFDIR=/etc ; make ; make install123

爲了讓MySQL數據庫程序正常運轉起來,須要先刪除/etc目錄中的默認配置文件,而後在MySQL數據庫程序的保存目錄scripts內找到一個名爲mysql_install_db的腳本程序,執行這個腳本程序並使用–user參數指定MySQL服務的對應帳號名稱(在前面步驟已經建立),使用–basedir參數指定MySQL服務程序的保存目錄,使用–datadir參數指定MySQL真實數據庫的文件保存目錄,這樣便可生成系統數據庫文件,也會生成出新的MySQL服務配置文件。

[root@server222 mysql-5.6.19]# rm -rf /etc/my.cnf[root@server222 mysql-5.6.19]# cd /usr/local/mysql[root@server222 mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var123

把系統新生成的MySQL數據庫配置文件連接到/etc目錄中,而後把程序目錄中的開機程序文件複製到/etc/rc.d/init.d目錄中,以便經過service命令來管理MySQL數據庫服務程序。記得把數據庫腳本文件的權限修改爲755以便於讓用戶有執行該腳本的權限

[root@server222 mysql]# ln -s my.cnf /etc/my.cnf[root@server222 mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld[root@server222 mysql]# chmod 755 /etc/rc.d/init.d/mysqld123

編輯剛複製的MySQL數據庫腳本文件,把第4六、47行的basedir與datadir參數分別修改成MySQL數據庫程序的保存目錄和真實數據庫的文件內容。

[root@server222 mysql]# vim /etc/rc.d/init.d/mysqld
 45 
 46 basedir=/usr/local/mysql
 47 datadir=/usr/local/mysql/var
 48 
12345

:set nu 查看行

配置好腳本文件後即可以用service命令啓動mysqld數據庫服務了。mysqld是MySQL數據庫程序的服務名稱,注意不要寫錯。順帶再使用chkconfig命令把mysqld服務程序加入到開機啓動項中。

[root@server222 mysql]# service mysqld startStarting MySQL. SUCCESS![root@server222 mysql]# chkconfig mysqld on123

MySQL數據庫程序自帶了許多命令,可是Bash終端的PATH變量並不會包含這些命令所存放的目錄,所以咱們也沒法順利地對MySQL數據庫進行初始化,也就不能使用MySQL數據庫自帶的命令了。想要把命令所保存的目錄永久性地定義到PATH變量中,須要編輯/etc/profile文件並寫入追加的命令目錄,這樣當物理設備在下一次重啓時就會永久生效了。若是不想經過重啓設備的方式來生效,也可使用source命令加載一下/ect/profile文件,此時新的PATH變量也能夠當即生效了。

[root@server222 mysql]# vim /etc/profile
 73 done
 74 export PATH=$PATH:/usr/local/mysql/bin
 75 unset i
 76 unset -f pathmunge[root@server222 mysql]# source /etc/profile123456

MySQL數據庫服務程序還會調用到一些程序文件和函數庫文件。因爲當前是經過源碼包方式安裝MySQL數據庫,所以如今也必須以手動方式把這些文件連接過來。

[root@server222 mysql]# mkdir /var/lib/mysql[root@server222 mysql]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql[root@server222 mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock[root@server222 mysql]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql1234

如今,MySQL數據庫服務程序已經啓動,調用的各個函數文件已經就位,PATH環境變量中也加入了MySQL數據庫命令的所在目錄。接下來準備對MySQL數據庫進行初始化

[root@server222 mysql]# mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y  (要爲root管理員設置數據庫的密碼)
New password:  輸入要爲root管理員設置的數據庫密碼
Re-enter new password:   再輸入一次密碼
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y  (刪除匿名帳戶)
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y (禁止root管理員從遠程登陸)
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y (刪除test數據庫並取消對其的訪問權限)
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y (刷新受權表,讓初始化後的設定當即生效)
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!Cleaning up...1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768

配置Nginx服務

在正式安裝Nginx服務程序以前,咱們還須要爲其解決相關的軟件依賴關係,下面來解壓、編譯、生成、安裝Nginx服務程序的源碼文件:

[root@server222 mysql]# cd /usr/local/src[root@server222 src]# tar xzvf pcre-8.35.tar.gz[root@server222 src]# cd pcre-8.35[root@server222 pcre-8.35]# ./configure --prefix=/usr/local/pcre ;make ; make install1234

openssl軟件包是用於提供網站加密證書服務的程序文件,在安裝該程序時須要自定義服務程序的安裝目錄,以便於稍後調用它們的時候更可控。

[root@server222 pcre-8.35]# cd /usr/local/src[root@server222 src]# tar xzvf openssl-1.0.1h.tar.gz[root@server222 src]# cd openssl-1.0.1h[root@server222 openssl-1.0.1h]# ./config --prefix=/usr/local/openssl ; make ; make install1234

openssl軟件包安裝後默認會在/usr/local/openssl/bin目錄中提供不少的可用命令,咱們須要像前面的操做那樣,將這個目錄添加到PATH環境變量中,並寫入到配置文件中,最後執行source命令以便讓新的PATH環境變量內容能夠當即生效:

[root@server222 openssl-1.0.1h]# vim /etc/profile
 73 done
 74 export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin
 75 unset i
 76 unset -f pathmunge[root@server222 openssl-1.0.1h]# source /etc/profile123456

使用:set nu 命令顯示數字

zlib軟件包是用於提供壓縮功能的函數庫文件。

[root@server222 openssl-1.0.1h]# cd /usr/local/src[root@server222 src]# tar xzvf zlib-1.2.8.tar.gz[root@server222 src]# cd zlib-1.2.8[root@server222 zlib-1.2.8]# ./configure --prefix=/usr/local/zlib ; make ; make install1234

在安裝部署好具備依賴關係的軟件包以後,建立一個用於執行Nginx服務程序的帳戶。帳戶名稱能夠自定義,但必定別忘記,由於在後續須要用到

[root@server222 zlib-1.2.8]# cd ..[root@server222 src]# useradd www -s /sbin/nologin12

在使用命令編譯Nginx服務程序時,須要設置特別多的參數

–prefix參數用於定義服務程序稍後安裝到的位置

–user與–group參數用於指定執行Nginx服務程序的用戶名和用戶組

[root@server222 src]# tar xzvf nginx-1.6.0.tar.gz[root@server222 src]# cd nginx-1.6.0/[root@server222 nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.35 ; make ; make install123

要想啓動Nginx服務程序以及將其加入到開機啓動項中,也須要有腳本文件。惋惜的是,在安裝完Nginx軟件包以後默認並無爲用戶提供腳本文件

此處代碼複製粘貼便可

[root@server222 nginx-1.6.0]# vim /etc/rc.d/init.d/nginx[root@server222 nginx-1.6.0]# cat /etc/rc.d/init.d/nginx#!/bin/bash# nginx - this script starts and stops the nginx daemon# chkconfig: - 85 15# description: Nginx is an HTTP(S) server, HTTP(S) reverse \# proxy and IMAP/POP3 proxy server# processname: nginx# config: /etc/nginx/nginx.conf# config: /usr/local/nginx/conf/nginx.conf# pidfile: /usr/local/nginx/logs/nginx.pid# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"prog=$(basename $nginx)NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {# make required directoriesuser=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
        if [ -z "`grep $user /etc/passwd`" ]; then
                useradd -M -s /bin/nologin $user
        fioptions=`$nginx -V 2>&1 | grep 'configure arguments:'`for opt in $options; do
        if [ `echo $opt | grep '.*-temp-path'` ]; then
                value=`echo $opt | cut -d "=" -f 2`
                if [ ! -d "$value" ]; then
                        # echo "creating" $value
                        mkdir -p $value && chown -R $user $value
                fi
        fidone}start() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6
make_dirsecho -n $"Starting $prog: "daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval}stop() {echo -n $"Stopping $prog: "killproc $prog -QUIT
retval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval}restart() {#configtest || return $?stopsleep 1
start}reload() {#configtest || return $?echo -n $"Reloading $prog: "killproc $nginx -HUP
RETVAL=$?echo}force_reload() {restart}configtest() {$nginx -t -c $NGINX_CONF_FILE}rh_status() {status $prog}rh_status_q() {rh_status >/dev/null 2>&1}case "$1" instart)
        rh_status_q && exit 0        $1
        ;;stop)
        rh_status_q || exit 0        $1
        ;;restart|configtest)$1;;reload)
        rh_status_q || exit 7        $1
        ;;force-reload)
        force_reload        ;;status)
        rh_status        ;;condrestart|try-restart)
        rh_status_q || exit 0        ;;*)echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"exit 2
esac123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112

保存腳本文件後記得爲其賦予755權限,以便可以執行這個腳本

而後以絕對路徑的方式執行這個腳本,經過restart參數重啓Nginx服務程序

最後再使用chkconfig命令將Nginx服務程序添加至開機啓動項中

[root@server222 nginx-1.6.0]# chmod 755 /etc/rc.d/init.d/nginx[root@server222 nginx-1.6.0]# /etc/rc.d/init.d/nginx restartReloading systemd:                                         [  肯定  ]Restarting nginx (via systemctl):                          [  肯定  ][root@server222 nginx-1.6.0]# chkconfig nginx on12345

Nginx服務程序在啓動後就能夠在瀏覽器中輸入服務器的IP地址來查看到默認網頁了。相較於Apache服務程序的紅色默認頁面,Nginx服務程序的默認頁面顯得更加簡潔。

配置PHP服務

解決PHP的程序包和其餘軟件的依賴關係。

須要先安裝部署將近十個用於搭建網站頁面的軟件程序包,而後才能正式安裝PHP程序。

yasm libmcrypt libvpx tiff libpng freetype jpeg libgd t1lib

yasm源碼包是一款常見的開源彙編器

[root@server222 nginx-1.6.0]# cd ..[root@server222 src]# tar zxvf yasm-1.2.0.tar.gz[root@server222 src]# cd yasm-1.2.0[root@server222 yasm-1.2.0]# ./configure ; make ; make install1234

libmcrypt源碼包是用於加密算法的擴展庫程序

[root@server222 yasm-1.2.0]# cd ..[root@server222 src]# tar zxvf libmcrypt-2.5.8.tar.gz[root@server222 src]# cd libmcrypt-2.5.8[root@server222 libmcrypt-2.5.8]# ./configure ; make ; make install1234

libvpx源碼包是用於提供視頻編碼器的服務程序

[root@server222 libmcrypt-2.5.8]# cd ..[root@server222 src]# tar xjvf libvpx-v1.3.0.tar.bz2[root@server222 src]# cd libvpx-v1.3.0[root@server222 libvpx-v1.3.0]# ./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9 ; make ; make install1234

tiff源碼包是用於提供標籤圖像文件格式的服務程序

[root@server222 libvpx-v1.3.0]# cd ..[root@server222 src]# tar zxvf tiff-4.0.3.tar.gz[root@server222 src]# cd tiff-4.0.3[root@server222 tiff-4.0.3]# ./configure --prefix=/usr/local/tiff --enable-shared ; make ; make install1234

libpng源碼包是用於提供png圖片格式支持函數庫的服務程序

[root@server222 tiff-4.0.3]# cd ..[root@server222 src]# tar zxvf libpng-1.6.12.tar.gz[root@server222 src]# cd libpng-1.6.12[root@server222 libpng-1.6.12]# ./configure --prefix=/usr/local/libpng --enable-shared ;make ; make install1234

freetype源碼包是用於提供字體支持引擎的服務程序

[root@server222 libpng-1.6.12]# cd ..[root@server222 src]# tar zxvf freetype-2.5.3.tar.gz[root@server222 src]# cd freetype-2.5.3[root@server222 freetype-2.5.3]# ./configure --prefix=/usr/local/freetype --enable-shared ; make ; make install1234

jpeg源碼包是用於提供jpeg圖片格式支持函數庫的服務程序

[root@server222 freetype-2.5.3]# cd ..[root@server222 src]# tar zxvf jpegsrc.v9a.tar.gz[root@server222 src]# cd jpeg-9a[root@server222 jpeg-9a]# ./configure --prefix=/usr/local/jpeg --enable-shared ; make ; make install1234

libgd源碼包是用於提供圖形處理的服務程序

[root@server222 jpeg-9a]# cd ..[root@server222 src]# tar zxvf libgd-2.1.0.tar.gz[root@server222 src]# cd libgd-2.1.0[root@server222 libgd-2.1.0]# ./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx ; make ; make install1234

t1lib源碼包是用於提供圖片生成函數庫的服務程序

[root@server222 libgd-2.1.0]# cd ..[root@server222 src]# tar zxvf t1lib-5.1.2.tar.gz[root@server222 src]# cd t1lib-5.1.2[root@server222 t1lib-5.1.2]# ./configure --prefix=/usr/local/t1lib --enable-shared ; make ; make install[root@server222 t1lib-5.1.2]# ln -s /usr/lib64/libltdl.so /usr/lib/libltdl.so[root@server222 t1lib-5.1.2]# cp -frp /usr/lib64/libXpm.so* /usr/lib/123456

在開始編譯php源碼包以前,先定義一個名爲LD_LIBRARY_PATH的全局環境變量,該環境變量的做用是幫助系統找到指定的動態連接庫文件,這些文件是編譯php服務源碼包的必須元素之一。編譯php服務源碼包時,除了定義要安裝到的目錄之外,還須要依次定義配置php服務程序配置文件的保存目錄、MySQL數據庫服務程序所在目錄、MySQL數據庫服務程序配置文件所在目錄,以及libpng、jpeg、freetype、libvpx、zlib、t1lib等服務程序的安裝目錄路徑,並經過參數啓動php服務程序的諸多默認功能

[root@server222 t1lib-5.1.2]# cd ..[root@server222 src]# tar -zvxf php-5.5.14.tar.gz[root@server222 src]# cd php-5.5.14[root@server222 php-5.5.14]# export LD_LIBRARY_PATH=/usr/local/libgd/lib[root@server222 php-5.5.14]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype ; make ; make install12345

在php源碼包程序安裝完成後,須要刪除當前默認的配置文件,而後將php服務程序目錄中相應的配置文件複製過來

[root@server222 php-5.5.14]# rm -rf /etc/php.ini[root@server222 php-5.5.14]# ln -s /usr/local/php/etc/php.ini /etc/php.ini[root@server222 php-5.5.14]# cp php.ini-production /usr/local/php/etc/php.ini[root@server222 php-5.5.14]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf[root@server222 php-5.5.14]# ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf12345

php-fpm.conf是php服務程序重要的配置文件之一,咱們須要啓用該配置文件中第25行左右的pid文件保存目錄,而後分別將第148和149行的user與group參數分別修改成www帳戶和用戶組名稱

[root@server222 php-5.5.14]# vim /usr/local/php/etc/php-fpm.conf24 ; Default Value: none
25 pid = run/php-fpm.pid
26 


147 ; will be used.
148 user = www
149 group = www
150 
12345678910

:set nu 可查看行數

配置穩當後即可把用於管理php服務的腳本文件複製到/etc/rc.d/init.d中了。爲了可以執行腳本,請記得爲腳本賦予755權限。最後把php-fpm服務程序加入到開機啓動項中

[root@server222 php-5.5.14]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm[root@server222 php-5.5.14]# chmod 755 /etc/rc.d/init.d/php-fpm[root@server222 php-5.5.14]# chkconfig php-fpm on123

因爲php服務程序的配置參數直接會影響到Web服務服務的運行環境,所以,若是默認開啓了一些沒必要要且高危的功能(如容許用戶在網頁中執行Linux命令),則會下降網站被***的難度,***人員甚至能夠拿到整臺Web服務器的管理權限。所以咱們須要編輯php.ini配置文件,在305行的disable_functions參數後面追加上要禁止的功能。

[root@server222 php-5.5.14]# vim /usr/local/php/etc/php.ini304 ; http://php.net/disable-functions
305 disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restor e,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,g etservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,po six_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_ getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_ setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname12345

這樣就把php服務程序配置穩當了。最後,還須要編輯Nginx服務程序的主配置文件,把第2行的井號(#)刪除,而後在後面寫上負責運行Nginx服務程序的帳戶名稱和用戶組名稱;在第45行的index參數後面寫上網站的首頁名稱。

最後是將第65~71行參數前的井號(#)刪除來啓用參數,主要是修改第69行的腳本名稱路徑參數,其中$document_root變量即爲網站信息存儲的根目錄路徑,若沒有設置該變量,則Nginx服務程序沒法找到網站信息,所以會提示「404頁面未找到」的報錯信息。在確認參數信息填寫正確後即可重啓Nginx服務與php-fpm服務。

[root@server222 php-5.5.14]# vim /usr/local/nginx/conf/nginx.conf
 1 
 2 user www www;
 3 worker_processes 1;
 4 
 
 44 	root html;
 45 	index index.html index.htm index.php forum.php;
 46 }
 47 
 
 64         #
 65         location ~ \.php$ {
 66             root           html;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 70             include        fastcgi_params;
 71         }
 72
 73         # deny access to .htaccess files, if Apache's document root[root@server222 php-5.5.14]# systemctl restart nginx[root@server222 php-5.5.14]# systemctl restart php-fpm123456789101112131415161718192021222324

從65行到71行的註釋須要去掉

至此,LNMP動態網站環境架構的配置實驗所有結束。

搭建Discuz!論壇

爲了檢驗LNMP動態網站環境是否配置穩當,可使用在上面部署Discuz!系統,而後查看結果。若是可以在LNMP動態網站環境中成功安裝使用Discuz!論壇系統,也就意味着這套架構是可用的。Discuz! X3.2是國內最多見的社區論壇系統,在通過十多年的研發後已經成爲了全球成熟度最高、覆蓋率最廣的論壇網站系統之一。

Discuz! X3.2軟件包的後綴是.zip格式,所以應當使用專用的unzip命令來進行解壓。解壓後會在當前目錄中出現一個名爲upload的文件目錄,這裏面保存的就是Discuz!論壇的系統程序。咱們把Nginx服務程序網站根目錄的內容清空後,就能夠把這些這個目錄中的文件都複製進去了。記得把Nginx服務程序的網站根目錄的全部者和所屬組修改成本地的www用戶,併爲其賦予755權限以便於可以讀、寫、執行該論壇系統內的文件。

[root@server222 php-5.5.14]# cd /usr/local/src/[root@server222 src]# unzip Discuz_X3.2_SC_GBK.zip[root@server222 src]# rm -rf /usr/local/nginx/html/{index.html,50x.html}*[root@server222 src]# mv upload/* /usr/local/nginx/html/[root@server222 src]# chown -Rf www:www /usr/local/nginx/html[root@server222 src]# chmod -Rf 755 /usr/local/nginx/html123456

以後在瀏覽器輸入192.168.176.222/install

依次按照傻瓜式步驟下一步

使用admin管理員帳戶登陸

到此結束LNMP動態網站部署,若是您以爲不懂,可私信給我,後期將寫一些部署docker容器虛擬化平臺

相關文章
相關標籤/搜索