1.LNMP 是一個縮寫,它指一組通常一起使用來運行動態網站或者服務器的自由軟件:
Linux+Nginx+MySQL+php( php-fpm),由於 Nginx 有大併發的優勢,現在越來越多的企
業 LAMP 平臺都在向 LNMP 遷移。
接着我們開始進入 LNMP 搭建。現實生產環境下, 不同的業務需求都不相同,因此更多的
企業會考慮使用源碼搭建 LNMP 環境,這樣可以更加靈活使用各個功能參數將性能調製到
最佳狀態。當然如果貴公司的環境比較簡單, 可以考慮 rpm 包安裝。
注意:本實驗環境基本上都是從各大官網下載的最新安裝包。
安裝 LNMP 環境所需要的最基本包
[root@rhel6u3-7 ~]#yum -y install libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel openssl-devel libtool-ltdl-devel gcc *c++*
ncurses-devel // libjpeg-devel , libpng-devel , libtiff-devel , fontconfig-devel ,
freetypedevel,
libXpm-devel 這些都是圖片與字體相關的開發包,爲了使 php 可以對其做更好的支持。
gettext 是語言相關的一個函數庫。 openssl-devel 是一套工具,用於生成 X.509 協議中所
使用的密鑰,公鑰等文件。 libtool 是一個通用庫支持腳本,在 php 編譯過程中會需要使用
到。
2.安裝 nginx 軟件包
[root@rhel6u3-7 yuanma]# tar -xzf nginx-1.2.7.tar.gz
[root@rhel6u3-7 nginx-1.2.7]# useradd nginx
[root@rhel6u3-7 nginx-1.2.7]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module --withsha1=/usr/lib //-with-sha1 指定希哈函數庫位置, 其他參數參看以上共享文檔
[root@rhel6u3-7 nginx-1.2.7]#make && make install
[root@rhel6u3-7 pcre-8.32]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
//啓動 nginx
[root@rhel6u3-7 pcre-8.32]# links 192.168.17.128 //出現 welcome to nginx! 說明nginx 安裝成功
3、安裝mysql
# tar xf mysql-5.1.54.tar.gz
# cd mysql-5.1.54
# ./configure --prefix=/opt/mysql && make && make install
# useradd -s /sbin/nologin mysql -M
# cd /opt/mysql
# chown mysql.mysql . -R
# ./bin/mysql_install_db --user=mysql
# chown root . -R
# chown mysql var -R
# cp share/mysql/mysql.server /etc/init.d/mysql
# service mysql start
# chkconfig --add mysql
# chkconfig mysql on
# netstat -tnlp |grep :3306 --驗證是否已經起來
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 16232/mysqld
4. 安裝PHP(fpm-->start-->php-->process)
#yum -y install libxml2-devel mysql-devel (mysql-php)
# tar -xf php-5.5.3.tar.bz2
# ./configure --prefix=/opt/php5 --with-config-file-path=/opt/php5 --enable-fpm --enable-fastcgi --with-mysql=/opt/mysql
--prefix=/opt/php5 --指定php的安裝路徑
--with-config-file-path=/opt/php5 --指定php的配置文件存儲目錄
--enable-fpm --enable-fastcgi --支持以CGI的方式啓動php
--with-mysql=/opt/mysql --讓php支持mysql數據庫
# make && make install
cp php.ini-production /opt/php5/php.ini
4、通過php-fpm以進程的方式啓動php
# cd /opt/php5/etc/
# cp php-fpm.conf.default php-fpm.conf
# /opt/php5/sbin/php-fpm --以進程的方式啓動PHP
# netstat -tnlp | grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 26789/php-fpm
# vim php-fpm.conf
159 listen = 127.0.0.1:9000
225 pm.max_children = 32
230 pm.start_servers = 10
235 pm.min_spare_servers = 10
240 pm.max_spare_servers = 12
# ps aux | grep fpm
root 26917 0.1 0.3 137704 3312 ? Ss 12:01 0:00 php-fpm: master process (/opt/php5/etc/php-fpm.conf)
nobody 26918 0.0 0.2 137704 2852 ? S 12:01 0:00 php-fpm: pool www
nobody 26919 0.0 0.2 137704 2852 ? S 12:01 0:00 php-fpm: pool www
nobody 26920 0.0 0.2 137704 2852 ? S 12:01 0:00 php-fpm: pool www
nobody 26921 0.0 0.2 137704 2852 ? S 12:01 0:00 php-fpm: pool www
nobody 26922 0.0 0.2 137704 2856 ? S 12:01 0:00 php-fpm: pool www
nobody 26923 0.0 0.2 137704 2856 ? S 12:01 0:00 php-fpm: pool www
nobody 26924 0.0 0.2 137704 2856 ? S 12:01 0:00 php-fpm: pool www
nobody 26925 0.0 0.2 137704 2856 ? S 12:01 0:00 php-fpm: pool www
nobody 26926 0.0 0.2 137704 2856 ? S 12:01 0:00 php-fpm: pool www
nobody 26927 0.0 0.2 137704 2856 ? S 12:01 0:00 php-fpm: pool www
邏輯
nginx<--tcp/socket-->php<--/usr/lib64/mysql/libmysqlclient.so-->mysqld
5.測試是否解析php文件
創建測試文件:
vim /usr/local/nginx/html/test.php
內容如下:
<?php echo phpinfo();?>
測試:
[root@localhost nginx]# curl localhost/test.php
或者使用瀏覽器打開http://YourServerIPAddress/test.php
重要:如果解析不了,檢查日誌發現連接不到php,我的php版本爲5.5.23,比較新的版本,需要在php/etc/php-fpm.conf文件中添加
listen.owner = nobody
listen.group = nobody
這兩行,再重啓一下服務就能使用php了
原因是/tmp/php-fcgi.sock這個文件沒有讀權限
至此,最新版的LNMP環境源碼編譯安裝完成了.
6、整合nginx/php/mysql
[root@website conf]# cat nginx.conf
user nginx nginx;
worker_processes 2;
error_log /usr/local/nginx/logs/error.log notice;
pid logs/nginx.pid;
worker_rlimit_nofile 5120;
events {
use epoll;
worker_connections 5120;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
#limit_zone one $binary_remote_addr 32k;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
log_format wwwlogs '$remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for';
server {
listen 80;
server_name www.bbs.com;
location / {
root /data/webroot/html/discuz;
index index.php;
}
location ~ \.php$ {
root /data/webroot/html/discuz;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/webroot/html/discuz$fastcgi_script_name;
include fastcgi_params;
}
}
}
7檢測nginx語法正確性
# /usr/local/nginx/sbin/nginx -t
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
重啓nginx服務
service nginx restart
8.安裝discuz論壇
下載相關軟件包:http://download.comsenz.com/DiscuzX/
#mkdir /data/webroot/html
# unzip Discuz_X3.2_SC_UTF8.zip
# mv upload /data/webroot/html/discuz
# chown -R nginx.nginx /data/webroot/html/discuz
在本地Hosts文件中添加如下記錄:
C:\Windows\System32\Drivers\etc\hosts #打開此文件添加如下內容
192.168.17.128 www.bbs.com
9。瀏覽器打開 192.168.17.128/install 開始安裝!!!
LNMP下搭建discuz論壇---實戰講解
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.