一,LNMP概述
LNMP代表的就是:Linux系統下Nginx+MySQL+PHP這種網站服務器架構。
Linux是一類Unix計算機操作系統的統稱,是目前最流行的免費操作系統。代表版本有:debian、centos、ubuntu、fedora、gentoo等。
Nginx是一個高性能的HTTP和反向代理服務器,也是一個IMAP/POP3/SMTP代理服務器。
Mysql是一個小型關係型數據庫管理系統。
PHP是一種在服務器端執行的嵌入HTML文檔的腳本語言。
這四種軟件均爲免費開源軟件,組合到一起,成爲一個免費、高效、擴展性強的網站服務系統。
編輯本段特點 Nginx是一個小巧而高效的Linux下的Web服務器軟件,是由 Igor Sysoev 爲俄羅斯訪問量第二的 Rambler 站點開發的,已經在一些俄羅斯的大型網站上運行多年,相當的穩定。
Nginx性能穩定、功能豐富、運維簡單、處理靜態文件速度快且消耗系統資源極少。
編輯本段
優點 作爲 Web 服務器:相比 Apache,Nginx 使用更少的資源,支持更多的併發連接,體現更高的效率。
作爲負載均衡服務器:Nginx 既可以在內部直接支持 Rails 和 PHP,也可以支持作爲 HTTP代理服務器對外進行服務。Nginx 用C編寫,不論是系統資源開銷還是CPU使用效率都比Perlbal要好的多。
作爲郵件代理服務器:Nginx同時也是一個非常優秀的郵件代理服務器(最早開發這個產品的目的之一也是作爲郵件代理服務器),Last/fm 描述了成功並且美妙的使用經驗。
Nginx 安裝非常的簡單,配置文件非常簡潔(還能夠支持perl語法)。Nginx支持平滑加載新的配置,還能夠在不間斷服務的情況下進行軟件版本的升級。
二,LNMP環境的搭建
php,mysql環境的搭建詳見本人博客其他內容
nginx環境的建立
[root@station2 ~]# mkdir /mnt/cdrom
[root@station2 ~]# mount /dev/cdrom /mnt/cdrom/建立光盤掛載點
[root@station2 ~]# yum install pcre-devel.i386
安裝成功
庫文件提高網站性能
[root@station2 ~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src/
[root@station2 ~]# cd /usr/local/
[root@station2 local]# vim /etc/ld.so.conf.d/libevent.conf
[root@station2 local]# cd /usr/local/src/
[root@station2 src]# cd libevent-2.0.16-stable/
[root@station2 libevent-2.0.16-stable]# ./configure
[root@station2 libevent-2.0.16-stable]# make
[root@station2 libevent-2.0.16-stable]# make install
手動加載
[root@station2 libevent-2.0.16-stable]# ldconfig -v
[root@station2 libevent-2.0.16-stable]# ldconfig -pv |grep libevent
圖
解壓liginx
[root@station2 ~]# tar -zxvf nginx-1.0.11.tar.gz -C /usr/local/src/
[root@station2 ~]# cd /usr/local/src/
[root@station2 src]# cd nginx-1.0.11/
[root@station2 nginx-1.0.11]# cd ..
[root@station2 src]# cd libevent-2.0.16-stable/
[root@station2 libevent-2.0.16-stable]# groupadd -r nginx
[root@station2 libevent-2.0.16-stable]# useradd -r -g nginx -s /bin/false -M nginx
[root@station2 ~]# cd /usr/local/src/
[root@station2 src]# cd nginx-1.0.11/
[root@station2 nginx-1.0.11]# ./configure \
> --prefix=/usr \
> --sbin-path=/usr/sbin/nginx \
> --conf-path=/etc/nginx/nginx.conf \
> --error-log-path=/var/log/nginx/error.log \
> --http-log-path=/var/log/nginx/access.log \
> --pid-path=/var/run/nginx/nginx.pid \
> --lock-path=/var/lock/nginx.lock \
> --user=nginx \
> --group=nginx \
> --with-http_ssl_module \
> --with-http_flv_module \
> --with-http_stub_status_module \
> --with-http_gzip_static_module \
> --http-client-body-temp-path=/var/tmp/nginx/client/ \
> --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
> --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
> --with-pcre
[root@station2 nginx-1.0.11]# make
[root@station2 nginx-1.0.11]# make install
[root@station2 ~]# mkdir -pv /var/tmp/nginx
[root@station2 ~]# nginx
使Nginx和Php、Mysql進行關聯
[root@station2 ~]# vim /etc/nginx/nginx.conf
[root@station2 ~]#vim /usr/local/src/nginx/fastcgi_params
此處紅線蓋着下劃線
[root@station2 ~]# pkill -1 nginx
[root@station2 ~]# cd /usr/local/src/nginx-1.0.11/html
[root@station2 html]#mv index.html index.php
[root@station2 html]#vim index.php
[root@lyt php-5.3.7]# cp php.ini-production /usr/local/php/etc/php.ini 爲php-fpm提供配置文件 [root@localhost php-5.3.7]# cp /usr/local/php/etc/php-fpm.conf.default [root@localhost php-5.3.7]# cd /usr/local/php/etc/ [root@localhost etc]# vim php-fpm.conf // 編輯該文件去掉分號 error_log= pm.max_children = pm.start_servers = pm.min_spare_servers = pm.max_spare_servers = pm.max_requests = [root@localhost etc]# /usr/local/php/sbin/php-fpm & //啓動fastcgi
/usr/local/php/etc/php-fpm.conf
測試
[root@station2 html]#vim index.php