LNMP(即Linux+Nginx+MYSQL+PHP)是目前很是熱門的動態網站部署架構,通常是指:php
Linux:如RHEL、Centos、Debian、Fedora、Ubuntu等系統。html
Nginx:高性能、低消耗的HTTP與反向代理服務程序。mysql
MYSQL:熱門經常使用的數據庫管理軟件。linux
PHP:一種可以在服務器端執行的嵌入HTML文檔的腳本語言。nginx
經過將這四種開源軟件部署在一塊兒,便成爲了一個免費、高效、擴展性強、資源消耗低的動態網站環境了。c++
1. 下載軟件和編譯git
1.1 下載全部須要使用的軟件包到/usr/local/src目錄(17個文件):正則表達式
[root@larry ~]# cd /usr/local/src [root@larry src]# wget -i download.txt
1.2. 安裝編譯工具及庫文件(須要安裝的程序比較多,請複製全!):算法
[root@larry ~]# 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-devel
執行後效果以下:sql
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. ………………省略部分安裝過程……………… Installing: apr x86_64 1.4.8-3.el7 rhel7 103 k apr-devel x86_64 1.4.8-3.el7 rhel7 188 k apr-util x86_64 1.5.2-6.el7 rhel7 92 k apr-util-devel x86_64 1.5.2-6.el7 rhel7 76 k autoconf noarch 2.69-11.el7 rhel7 701 k automake noarch 1.13.4-3.el7 rhel7 679 k bison x86_64 2.7-4.el7 rhel7 578 k bzip2-devel x86_64 1.0.6-12.el7 rhel7 218 k compat-dapl x86_64 1:1.2.19-3.el7 rhel7 109 k compat-db-headers noarch 4.7.25-27.el7 rhel7 48 k compat-db47 x86_64 4.7.25-27.el7 rhel7 795 k compat-gcc-44 x86_64 4.4.7-8.el7 rhel7 10 M compat-gcc-44-c++ x86_64 4.4.7-8.el7 rhel7 6.3 M compat-glibc x86_64 1:2.12-4.el7 rhel7 1.2 M compat-glibc-headers x86_64 1:2.12-4.el7 rhel7 452 k compat-libcap1 x86_64 1.10-7.el7 rhel7 19 k compat-libf2c-34 x86_64 3.4.6-32.el7 rhel7 155 k compat-libgfortran-41 x86_64 4.1.2-44.el7 rhel7 142 k compat-libtiff3 x86_64 3.9.4-11.el7 rhel7 135 k compat-openldap x86_64 1:2.3.43-5.el7 rhel7 174 k cpp x86_64 4.8.2-16.el7 rhel7 5.9 M fontconfig-devel x86_64 2.10.95-7.el7 rhel7 128 k freetype-devel x86_64 2.4.11-9.el7 rhel7 355 k gcc x86_64 4.8.2-16.el7 rhel7 16 M gcc-c++ x86_64 4.8.2-16.el7 rhel7 7.1 M gettext-devel x86_64 0.18.2.1-4.el7 rhel7 315 k kernel-headers x86_64 3.10.0-123.el7 rhel7 1.4 M keyutils-libs-devel x86_64 1.5.8-3.el7 rhel7 37 k krb5-devel x86_64 1.11.3-49.el7 rhel7 611 k libXpm-devel x86_64 3.5.10-5.1.el7 rhel7 36 k libcom_err-devel x86_64 1.42.9-4.el7 rhel7 30 k libcurl-devel x86_64 7.29.0-19.el7 rhel7 296 k libjpeg-turbo-devel x86_64 1.2.90-5.el7 rhel7 99 k libpng-devel x86_64 2:1.5.13-5.el7 rhel7 122 k libselinux-devel x86_64 2.2.2-6.el7 rhel7 174 k libsepol-devel x86_64 2.1.9-3.el7 rhel7 71 k libstdc++-devel x86_64 4.8.2-16.el7 rhel7 1.5 M libtiff-devel x86_64 4.0.3-14.el7 rhel7 471 k libtool x86_64 2.4.2-20.el7 rhel7 588 k libtool-ltdl-devel x86_64 2.4.2-20.el7 rhel7 167 k libxml2-devel x86_64 2.9.1-5.el7 rhel7 1.0 M mpfr x86_64 3.1.1-4.el7 rhel7 203 k nasm x86_64 2.10.07-7.el7 rhel7 402 k ncurses-devel x86_64 5.9-13.20130511.el7 rhel7 713 k ncurses-term noarch 5.9-13.20130511.el7 rhel7 543 k ntp x86_64 4.2.6p5-18.el7 rhel7 539 k openssl-devel x86_64 1:1.0.1e-34.el7 rhel7 1.2 M patch x86_64 2.7.1-8.el7 rhel7 110 k pcre-devel x86_64 8.32-12.el7 rhel7 477 k php-common x86_64 5.4.16-21.el7 rhel7 559 k php-gd x86_64 5.4.16-21.el7 rhel7 122 k t1lib x86_64 5.1.2-14.el7 rhel7 166 k telnet x86_64 1:0.17-59.el7 rhel7 63 k zlib-devel x86_64 1.2.7-13.el7 rhel7 49 k Installing for dependencies: cyrus-sasl-devel x86_64 2.1.26-17.el7 rhel7 309 k expat-devel x86_64 2.1.0-8.el7 rhel7 56 k gettext-common-devel noarch 0.18.2.1-4.el7 rhel7 368 k git x86_64 1.8.3.1-4.el7 rhel7 4.3 M glibc-devel x86_64 2.17-55.el7 rhel7 1.0 M glibc-headers x86_64 2.17-55.el7 rhel7 650 k libX11-devel x86_64 1.6.0-2.1.el7 rhel7 979 k libXau-devel x86_64 1.0.8-2.1.el7 rhel7 14 k libdb-devel x86_64 5.3.21-17.el7 rhel7 38 k libmpc x86_64 1.0.1-3.el7 rhel7 51 k libverto-devel x86_64 0.2.5-4.el7 rhel7 12 k libxcb-devel x86_64 1.9-5.el7 rhel7 1.0 M libzip x86_64 0.10.1-8.el7 rhel7 49 k m4 x86_64 1.4.16-9.el7 rhel7 256 k openldap-devel x86_64 2.4.39-3.el7 rhel7 796 k perl-Data-Dumper x86_64 2.145-3.el7 rhel7 47 k perl-Error noarch 1:0.17020-2.el7 rhel7 32 k perl-Git noarch 1.8.3.1-4.el7 rhel7 52 k perl-TermReadKey x86_64 2.30-20.el7 rhel7 31 k perl-Test-Harness noarch 3.28-2.el7 rhel7 302 k perl-Thread-Queue noarch 3.02-2.el7 rhel7 17 k xorg-x11-proto-devel noarch 7.7-8.el7.1 rhel7 281 k xz-devel x86_64 5.1.2-8alpha.el7 rhel7 44 k ………………省略部分安裝過程……………… Complete!
1.3. 安裝cmake編譯工具(解壓與編譯過程已省略):
[root@larry ~]# cd /usr/local/src [root@larry src]# ls zlib-1.2.8.tar.gz libmcrypt-2.5.8.tar.gz pcre-8.35.tar.gz cmake-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 [root@larry src]# tar xzvf cmake-2.8.11.2.tar.gz [root@larry src]# cd cmake-2.8.11.2/ [root@larry cmake-2.8.11.2]# ./configure [root@larry cmake-2.8.11.2]# make [root@larry cmake-2.8.11.2]# make install
2. 配置Mysql服務
2.1. 建立用於執行mysql服務程序的賬號:
[root@larry cmake-2.8.11.2]# cd .. [root@larry src]# useradd mysql -s /sbin/nologin
2.2. 建立數據庫程序和文件的目錄,並設置目錄的所屬與所組:
[root@larry src]# mkdir -p /usr/local/mysql/var [root@larry src]# chown -Rf mysql:mysql /usr/local/mysql
2.3. 安裝Mysql服務程序(解壓與編譯過程已省略,大約須要30分鐘):
[root@larry src]# tar xzvf mysql-5.6.19.tar.gz [root@larry src]# cd mysql-5.6.19/ [root@larry mysql-5.6.19]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/var -DSYSCONFDIR=/etc [root@larry mysql-5.6.19]# make [root@larry mysql-5.6.19]# make install
2.4. 刪除系統默認的配置文件:
[root@larry mysql-5.6.19]# rm -rf /etc/my.cnf
2.5. 生成系統數據庫(生成信息已省略,大約須要15分鐘):
[root@larry mysql-5.6.19]# cd /usr/local/mysql [root@larry mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var
2.6. 建立配置文件的軟鏈接文件:
[root@larry mysql]# ln -s my.cnf /etc/my.cnf
2.7. 將mysqld服務程序添加到開機啓動項:
[root@larry mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld [root@larry mysql]# chmod 755 /etc/init.d/mysqld [root@larry mysql]# chkconfig mysqld on
2.8. 編輯啓動項的配置文件:
[root@larry mysql]# vi /etc/rc.d/init.d/mysqld //分別修改第46與47行,basedir爲程序安裝路徑,datadir爲數據庫存放目錄。 basedir=/usr/local/mysql datadir=/usr/local/mysql/var
2.9. 重啓mysqld服務程序:
[root@larry mysql]# service mysqld start Starting MySQL. SUCCESS!
2.10. 把mysql服務程序命令目錄添加到環境變量中(永久生效):
[root@larry mysql]# vi /etc/profile //在配置文件的最下面追加: export PATH=$PATH:/usr/local/mysql/bin [root@larry mysql]# source /etc/profile
2.11. 將mysqld服務程序的庫文件連接到默認的位置:
[root@larry mysql]# mkdir /var/lib/mysql [root@larry mysql]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql [root@larry mysql]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql [root@larry mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
2.12. 初始化mysqld服務程序:
[root@larry mysql]# mysql_secure_installation NOTE: 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 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...
3. 配置Nginx服務
Nginx是一款至關優秀的用於部署動態網站的服務程序,Nginx最初是爲俄羅斯門戶站點而設計的網站服務軟件,做爲做爲一款輕量級的網站服務軟件,因其穩定性和豐富的功能而深受信賴,但最最最被承認的是低系統資源、佔用內存少且併發能力強,目前國內如新浪、網易、騰訊等門戶站均在使用,市場佔有份額一直保持在15-16%左右(2015年最新數據)。
Nginx程序的穩定性來自於它採用了分階段的資源分配技術,使得CPU與內存佔用率會很是低,因此使用Nginx程序部署動態網站環境不只十分的穩定、高效,並且消耗更少的系統資源,豐富的模塊功能也幾乎與Apache程序數量相同,如今已經徹底的支持了proxy、rewrite、mod_fcgi、ssl、vhosts等經常使用模塊。並且還支持了熱部署技術,即可以能夠7*24不間斷提供服務,即使運行數月也無須重啓,並且還能夠在不暫停服務的狀況下直接對Nginx服務程序進行升級。
3.1. 安裝PCRE(Perl兼容的正則表達式庫,解壓與編譯過程已省略):
[root@larry ~]# cd /usr/local/src [root@larry src]# mkdir /usr/local/pcre [root@larry src]# tar xzvf pcre-8.35.tar.gz [root@larry src]# cd pcre-8.35 [root@larry pcre-8.35]# ./configure --prefix=/usr/local/pcre [root@larry pcre-8.35]# make [root@larry pcre-8.35]# make install
3.2. 安裝openssl服務程序(解壓與編譯過程已省略):
[root@larry pcre-8.35]# cd /usr/local/src [root@larry src]# mkdir /usr/local/openssl [root@larry src]# tar xzvf openssl-1.0.1h.tar.gz [root@larry src]# cd openssl-1.0.1h [root@larry openssl-1.0.1h]# ./config --prefix=/usr/local/openssl [root@larry openssl-1.0.1h]# make [root@larry openssl-1.0.1h]# make install
3.3. 把openssl服務程序命令目錄添加到環境變量中(永久生效):
[root@larry pcre-8.35]# vi /etc/profile //將配置文件最下面的參數追加參數爲: export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin [root@larry pcre-8.35]# source /etc/profile
3.4. 安裝zlib數據壓縮函數庫(解壓與編譯過程已省略):
[root@larry pcre-8.35]# cd /usr/local/src [root@larry src]# mkdir /usr/local/zlib [root@larry src]# tar xzvf zlib-1.2.8.tar.gz [root@larry src]# cd zlib-1.2.8 [root@larry zlib-1.2.8]# ./configure --prefix=/usr/local/zlib [root@larry zlib-1.2.8]# make [root@larry zlib-1.2.8]# make install
3.5. 建立用於執行nginx服務的用戶:
[root@larry zlib-1.2.8]# cd .. [root@larry src]# useradd www -s /sbin/nologin
3.6. 安裝nginx服務程序(openssl,zlib,pcre要寫成源碼解壓路徑!!!):
[root@larry src]# tar xzvf nginx-1.6.0.tar.gz [root@larry src]# cd nginx-1.6.0/ [root@larry 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 [root@larry nginx-1.6.0]# make [root@larry nginx-1.6.0]# make install
3.7. 建立nginx程序腳本(將下面的參數直接複製進去便可):
[root@larry nginx-1.6.0]# vi /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 directories user=`$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 fi options=`$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 fi done } start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 make_dirs echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { #configtest || return $? stop sleep 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" in start) 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 esac
更改nginx文件的權限爲755
[root@larry nginx-1.6.0]# chmod 755 /etc/rc.d/init.d/nginx
3.8. 重啓nginx服務程序並添加到開機啓動項:
[root@larry nginx-1.6.0]# /etc/rc.d/init.d/nginx restart Stopping nginx: [FAILED] Starting nginx: [ OK ] [root@larry nginx-1.6.0]# chkconfig nginx on
3.9. 此時能夠經過訪問IP來判斷nginx服務是否順利運行:
4. 配置php服務
4.1. 安裝yasm彙編器(解壓與編譯過程已省略):
[root@larry nginx-1.6.0]# cd /usr/local/src [root@larry src]# tar zxvf yasm-1.2.0.tar.gz [root@larry src]# cd yasm-1.2.0 [root@larry yasm-1.2.0]# ./configure [root@larry yasm-1.2.0]# make [root@larry yasm-1.2.0]# make install
安裝yasm彙編器(解壓與編譯過程已省略):
[root@linuxprobe nginx-1.6.0]# cd /usr/local/src [root@linuxprobe src]# tar zxvf yasm-1.2.0.tar.gz [root@linuxprobe src]# cd yasm-1.2.0 [root@linuxprobe yasm-1.2.0]# ./configure [root@linuxprobe yasm-1.2.0]# make [root@linuxprobe yasm-1.2.0]# make install
安裝libmcrypt加密算法擴展庫(解壓與編譯過程已省略):
[root@linuxprobe yasm-1.2.0]# cd /usr/local/src [root@linuxprobe src]# tar zxvf libmcrypt-2.5.8.tar.gz [root@linuxprobe src]# cd libmcrypt-2.5.8 [root@linuxprobe libmcrypt-2.5.8]# ./configure [root@linuxprobe libmcrypt-2.5.8]# make [root@linuxprobe libmcrypt-2.5.8]# make install
安裝libvpx視頻編碼器(解壓與編譯過程已省略):
[root@linuxprobe libmcrypt-2.5.8]# cd /usr/local/src [root@linuxprobe src]# tar xjvf libvpx-v1.3.0.tar.bz2 [root@linuxprobe src]# cd libvpx-v1.3.0 [root@linuxprobe libvpx-v1.3.0]# ./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9 [root@linuxprobe libvpx-v1.3.0]# make [root@linuxprobe libvpx-v1.3.0]# make install
安裝Tiff標籤圖像文件格式(解壓與編譯過程已省略):
[root@linuxprobe libvpx-v1.3.0]# cd /usr/local/src [root@linuxprobe src]# tar zxvf tiff-4.0.3.tar.gz [root@linuxprobe src]# cd tiff-4.0.3 [root@linuxprobe tiff-4.0.3]# ./configure --prefix=/usr/local/tiff --enable-shared [root@linuxprobe tiff-4.0.3]# make [root@linuxprobe tiff-4.0.3]# make install
安裝libpng圖片(png格式)函數庫(解壓與編譯過程已省略):
[root@linuxprobe tiff-4.0.3]# cd /usr/local/src [root@linuxprobe src]# tar zxvf libpng-1.6.12.tar.gz [root@linuxprobe src]# cd libpng-1.6.12 [root@linuxprobe libpng-1.6.12]# ./configure --prefix=/usr/local/libpng --enable-shared [root@linuxprobe libpng-1.6.12]# make [root@linuxprobe libpng-1.6.12]# make install
安裝freetype字體引擎(解壓與編譯過程已省略):
[root@linuxprobe libpng-1.6.12]# cd /usr/local/src [root@linuxprobe src]# tar zxvf freetype-2.5.3.tar.gz [root@linuxprobe src]# cd freetype-2.5.3 [root@linuxprobe freetype-2.5.3]# ./configure --prefix=/usr/local/freetype --enable-shared [root@linuxprobe freetype-2.5.3]# make [root@linuxprobe freetype-2.5.3]# make install
安裝jpeg圖片(jpeg格式)函數庫(解壓與編譯過程已省略):
[root@linuxprobe freetype-2.5.3]# cd /usr/local/src [root@linuxprobe src]# tar zxvf jpegsrc.v9a.tar.gz [root@linuxprobe src]# cd jpeg-9a [root@linuxprobe jpeg-9a]# ./configure --prefix=/usr/local/jpeg --enable-shared [root@linuxprobe jpeg-9a]# make [root@linuxprobe jpeg-9a]# make install
安裝libgd圖像處理程序(解壓與編譯過程已省略):
[root@linuxprobe jpeg-9a]# cd /usr/local/src [root@linuxprobe src]# tar zxvf libgd-2.1.0.tar.gz [root@linuxprobe src]# cd libgd-2.1.0 [root@linuxprobe 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 [root@linuxprobe libgd-2.1.0]# make [root@linuxprobe libgd-2.1.0]# make install
安裝t1lib圖片生成函數庫(解壓與編譯過程已省略):
[root@linuxprobe cd libgd-2.1.0]# cd /usr/local/src [root@linuxprobe src]# tar zxvf t1lib-5.1.2.tar.gz [root@linuxprobe src]# cd t1lib-5.1.2 [root@linuxprobe t1lib-5.1.2]# ./configure --prefix=/usr/local/t1lib --enable-shared [root@linuxprobe t1lib-5.1.2]# make [root@linuxprobe t1lib-5.1.2]# make install
將函數庫文件放至合適的位置:
[root@linuxprobe t1lib-5.1.2]# cd /usr/local/src [root@linuxprobe src]# ln -s /usr/lib64/libltdl.so /usr/lib/libltdl.so [root@linuxprobe src]# cp -frp /usr/lib64/libXpm.so* /usr/lib/
安裝php服務程序(命令比較長,請必定要複製完整!!!):
[root@linuxprobe src]# tar -zvxf php-5.5.14.tar.gz [root@linuxprobe src]# cd php-5.5.14 [root@linuxprobe php-5.5.14]# export LD_LIBRARY_PATH=/usr/local/libgd/lib [root@linuxprobe 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 [root@linuxprobe php-5.5.14]# make [root@linuxprobe php-5.5.14]# make install
複製php服務程序的配置文件到安裝目錄:
[root@linuxprobe php-5.5.14]# cp php.ini-production /usr/local/php/etc/php.ini
刪除默認的php配置文件:
[root@linuxprobe php-5.5.14]# rm -rf /etc/php.ini
建立php配置文件的軟鏈接到/etc/目錄中:
編輯php服務程序的配置文件:
[root@linuxprobe php-5.5.14]# vim /usr/local/php/etc/php-fpm.conf //將第25行參數前面的分號去掉。 pid = run/php-fpm.pid //修改第148和149行,將user與group修改成www。 user = www group = www
添加php-fpm服務程序到開機啓動項:
[root@linuxprobe php-5.5.14]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm [root@linuxprobe php-5.5.14]# chmod +x /etc/rc.d/init.d/php-fpm [root@linuxprobe php-5.5.14]# chkconfig php-fpm on
爲了保障網站的安全性,禁用掉不安全的功能:
[root@linuxprobe php-5.5.14]# vim /usr/local/php/etc/php.ini //修改第305行的disable_functions參數,追加參數爲: disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_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_uname
配置nginx服務程序支持php:
[root@linuxprobe php-5.5.14]# vim /usr/local/nginx/conf/nginx.conf //將第2行前面的#號去掉並修改成user www www ; //將第45行參數修改成index index.html index.htm index.php; //將第65-71行前面的#號去掉,修改成: location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
重啓nginx與php-fpm服務程序:
[root@linuxprobe php-5.5.14]# systemctl restart nginx [root@linuxprobe php-5.5.14]# systemctl restart php-fpm