和LAMP不同的是,LNMP中的N指的是Nginx(類似于Apache的一種web服務軟體),并且php是作為一個獨立服務存在的,這個服務叫做php-fpm,Nginx直接處理靜态請求,動态請求會轉發給php-fpm。
目前LNMP環境的應用非常多。在靜态頁面的處理上,Nginx比Apache更強;但在動态頁面的處理上,Nginx并不占優勢。
安裝順序nginx -- php --- mysql
安裝php-5.6.30:
1 環境準備
yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel jemalloc jemalloc-devel
yum install libpng
yum install libpng-devel
yum -y install libjpeg-devel
yum install freetype-devel
cd /usr/local
mkdir php-fpm
cd /usr/local/src
wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
tar zvxf php-5.6.30.tar.gz
cd php-5.6.30
groupadd www
useradd -g www -s /sbin/nologin www

2 編譯安裝 (##編譯參數)
./configure --prefix=/usr/local/php-fpm \
--with-config-file-path=/usr/local/php-fpm/etc \
--enable-inline-optimization --disable-debug \
--disable-rpath --enable-shared --enable-opcache \
--enable-fpm --with-fpm-user=www \
--with-png-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-gd \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir=/usr/ \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl --with-zlib \
--enable-zip \
--with-bz2 \
--with-readline
<code>##參數解釋</code>
<code>""</code><code>" 安裝路徑 "</code><code>""</code>
<code>--prefix=</code><code>/usr/local/php56</code> <code>\</code>
<code>""</code><code>" php.ini 配置檔案路徑 "</code><code>""</code>
<code>--with-config-</code><code>file</code><code>-path=</code><code>/usr/local/php56/etc</code> <code>\</code>
<code>""</code><code>" 優化選項 "</code><code>""</code>
<code>--</code><code>enable</code><code>-inline-optimization \</code>
<code>--disable-debug \</code>
<code>--disable-rpath \</code>
<code>--</code><code>enable</code><code>-shared \</code>
<code>""</code><code>" 啟用 opcache,預設為 ZendOptimizer+(ZendOpcache) "</code><code>""</code>
<code>--</code><code>enable</code><code>-opcache \</code>
<code>""</code><code>" FPM "</code><code>""</code>
<code>--</code><code>enable</code><code>-fpm \</code>
<code>--with-fpm-user=www \</code>
<code>--with-fpm-group=www \</code>
<code>""</code><code>" MySQL "</code><code>""</code>
<code>--with-mysql=mysqlnd \</code>
<code>--with-mysqli=mysqlnd \</code>
<code>--with-pdo-mysql=mysqlnd \</code>
<code>""</code><code>" 國際化與字元編碼支援 "</code><code>""</code>
<code>--with-gettext \</code>
<code>--</code><code>enable</code><code>-mbstring \</code>
<code>--with-iconv \</code>
<code>""</code><code>" 加密擴充 "</code><code>""</code>
<code>--with-mcrypt \</code>
<code>--with-mhash \</code>
<code>--with-openssl \</code>
<code>""</code><code>" 數學擴充 "</code><code>""</code>
<code>--</code><code>enable</code><code>-bcmath \</code>
<code>""</code><code>" Web 服務,soap 依賴 libxml "</code><code>""</code>
<code>--</code><code>enable</code><code>-soap \</code>
<code>--with-libxml-</code><code>dir</code> <code>\</code>
<code>""</code><code>" 程序,信号及記憶體 "</code><code>""</code>
<code>--</code><code>enable</code><code>-pcntl \</code>
<code>--</code><code>enable</code><code>-shmop \</code>
<code>--</code><code>enable</code><code>-sysvmsg \</code>
<code>--</code><code>enable</code><code>-sysvsem \</code>
<code>--</code><code>enable</code><code>-sysvshm \</code>
<code>""</code><code>" socket & curl "</code><code>""</code>
<code>--</code><code>enable</code><code>-sockets \</code>
<code>--with-curl \</code>
<code>""</code><code>" 壓縮與歸檔 "</code><code>""</code>
<code>--with-zlib \</code>
<code>--</code><code>enable</code><code>-zip \</code>
<code>--with-bz2 \</code>
<code>""</code><code>" GNU Readline 指令行快捷鍵綁定 "</code><code>""</code>
<code>--with-readline</code>
3. 編譯安裝
make && make install
如下圖 ,不抱任何錯誤
4.配置服務
配置檔案
cp php.ini-development /usr/local/php-fpm/etc/php.ini
cp /usr/local/php-fpm/etc/php-fpm.conf.default /usr/local/php-fpm/etc/php-fpm.conf
5 .修改配置
vim /usr/local/php-fpm/etc/php-fpm.conf
[global]
pid =/usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
6. 儲存配置檔案後,檢驗配置是否正确的方法如下:
/usr/local/php-fpm/sbin/php-fpm -t
如果顯示 "test is successful",說明配置沒有問題,否則就要根據提示檢查配置檔案.
7.啟動 php-fpm,指令如下:
cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
useradd -s /sbin/nologin php-fpm
service php-fpm start
設定php-fpm開啟啟動指令如下:
chkconfig php-fpm on
檢測php-fpm是否啟動的指令如下:
ps aux |grep php-fpm
執行這條指令,可以看見多個程序
安裝nginx-1.14.2:
先不要急着安裝,先確定它所依賴的庫是否有,怎樣檢視軟體是否安裝(rpm -q xxx),如果沒有安裝依賴則進行安裝(筆者一般安裝依賴庫直接使用yum 預設安裝,這樣在軟體安裝的時候就不需要知道依賴庫的安裝路徑,省去不少麻煩)
需要安裝的依賴包有 gcc expat-devel openssl-devel pcre pcre-devel
在src目錄下 yum install gcc
yum install -y expat-devel
yum install openssl-devel
yum install -y pcre pcre-devel
yum install pcre-devel
1:在/usr/local下建立一個nginx目錄
mkdir nginx
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar zxvf nginx-1.14.2.tar.gz
2.配置編譯選項
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx
3.編譯和安裝
4.編寫nginx啟動腳本,并加入系統服務
vim /etc/init.d/nginx
儲存該腳本後更改權限,指令如下:
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
如果想開啟啟動nginx,請執行指令如下:
chkconfig nginx on
5.更改nginx的配置檔案:
> /usr/local/nginx/conf/nginx.conf
重定向符号>,單獨使用時,可以吧一個文本文檔快速清空
vim /usr/local/nginx/conf/nginx.conf //寫入如下内容:
/usr/local/nginx/sbin/nginx -t
7.啟動nginx,指令如下:
service nginx start
重新開機 service nginx restart
8.測試是否正确解析php
vim /usr/local/nginx/html/index.php
其内容如下
<?php
echo phpinfo();
安裝mysql-5.6.43(與之前一模一樣)
javascript:void(0)
------------------------------------------------------------------------額外補充-----------------------------------------------------------------------------------
nginx.conf