lnmp源碼安裝前準備:
1.配置yum
2.查看組軟件包安裝狀況
yum grouplist | less //查看確保五組包要被安裝上
Development Libraries
Development Tools
X Software Development
Legacy Software Development
Java Development
3.注意php軟件包最後安裝
一.安裝niginx
實驗準備源碼安裝包:
libevent-2.0.16-stable.tar.gz //事件觸發庫(新版本)安裝後網站性能有大幅度提高
nginx-1.0.11.tar.gz
//niginx安裝包
實驗步驟:
1. [root@localhost ~]# yum list |grep pcre
[root@localhost ~]# yum install pcre-devel //提升網站性能,可以現頭部地址重寫
2. [root@localhost ~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src
[root@localhost libevent-2.0.16-stable]#./configure --help |less 查看默認安裝路徑
Installation directories:
--prefix=PREFIX
install architecture-independent files in PREFIX
[/usr/local]
[root@localhost libevent-2.0.16-stable]#./configure
[root@localhost libevent-2.0.16-stable]#make
[root@localhost libevent-2.0.16-stable]#make install
說明: /usr/local // 默認安裝位置,造成庫文件在/usr/local/lib
系統調用庫在默認路徑(/lib ;/usr/lib)
爲了使系統找到非標準路徑的庫:
vim /etc/ld.so.conf.d/libevent.conf
文件內容:/usr/local/lib
[root@localhost libevent-2.0.16-stable]#ldconfig -v 手工調用庫文件
[root@localhost libevent-2.0.16-stable]# ldconfig -pv |grep libevent
libevent_pthreads-2.0.so.5 (libc6) => /usr/local/lib/libevent_pthreads-2.0.so.5
libevent_openssl-2.0.so.5 (libc6) => /usr/local/lib/libevent_openssl-2.0.so.5
libevent_extra-2.0.so.5 (libc6) => /usr/local/lib/libevent_extra-2.0.so.5
libevent_core-2.0.so.5 (libc6) => /usr/local/lib/libevent_core-2.0.so.5
libevent-2.0.so.5 (libc6) => /usr/local/lib/libevent-2.0.so.5
libevent-1.1a.so.1 (libc6) => /usr/lib/libevent-1.1a.so.1
3. [root@localhost ~]# tar -zxvf nginx-1.0.11.tar.gz -C /usr/local/src
[root@localhost nginx-1.0.11]# groupadd -r nginx
[root@localhost nginx-1.0.11]# useradd -r -g nginx -s /bin/false -M nginx(賬號名)
-r 建立系統賬號
-g 加入組
-s shell
-M 不建立家目錄 由於是系統賬號
[root@localhost 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 \
存放父進程id
--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/ \ php臨時緩存
--with-pcre
地址重寫
[root@localhost nginx-1.0.11]#make
[root@localhost nginx-1.0.11]#make install
4. [root@localhost ~]# mkdir -pv /var/tmp/nginx //建立目錄
[root@localhost ~]# nginx
//啓動服務
[root@localhost ~]# netstat -tupln |less //查看80端口
Web訪問nginx
5.物理目錄站點
[root@localhost ~]#cd /usr/html
[root@localhost html]# mkdir abc
[root@localhost html]# cd abc
[root@localhost abc]# echo "abc" >index.html
Web訪問
6.虛擬目錄站點
[root@localhost ~]# mkdir /qq
[root@localhost ~]# cd /qq
[root@localhost qq]# echo "tec" >index.html
[root@localhost qq]# vim /etc/nginx/nginx.conf
文件內容:43-46 複製
43
location / {
44
root html;
45
index index.html index.htm;
46
}
47
48
location /tec { //訪問的域名
49
alias /qq; //訪問的目錄
50
index index.html index.htm;
51
}
重啓服務(沒有腳本,不能用service啓動,可是能夠不用中斷用戶請求使配置從新生效)
[root@localhost ~]#pkill -1 nginx
Web訪問
7.基於ip地址虛擬主機
[root@localhost ~]# ifconfig eth0:0 192.168.2.101
[root@localhost ~]#mkdir /mkt
[root@localhost ~]#cd /mkt
[root@localhost mkt]#echo 「mkt」 >index.html
[root@localhost ~]# vim /etc/nginx/nginx.conf
文件內容:42-76複製
server {
listen 192.168.2.100:80;
server_name tec.abc.com;
access_log /var/log/tec.access.log;
error_log /var/log/tec.error.log;
root /qq ;
index index.html index.htm;
server {
listen 192.168.2.101:80;
server_name mkt.abc.com;
access_log /var/log/mkt.access.log;
error_log /var/log/mkt.error.log;
root /mkt;
index index.html index.htm;
客戶端修改hosts文件:
192.168.2.100
tec.abc.com
192.168.2.101
mkt.abc.com
客戶端Web訪問
8.基於主機頭虛擬主機
[root@localhost ~]# ifconfig eth0:0 down
[root@localhost ~]# vim /etc/nginx/nginx.conf
文件內容:
server {
listen 192.168.2.100:80;
server_name tec.abc.com;
access_log /var/log/tec.access.log;
error_log /var/log/tec.error.log;
root /qq ;
index index.html index.htm;
server {
listen 192.168.2.100:80;
server_name mkt.abc.com;
access_log /var/log/mkt.access.log;
error_log /var/log/mkt.error.log;
root /mkt;
index index.html index.htm;
客戶端修改hosts文件:
192.168.2.100
tec.abc.com
192.168.2.100
mkt.abc.com
客戶端Web訪問
二.安裝mysql
實驗準備軟件包:
mysql-5.5.15-linux2.6-i686.tar.gz
實驗步驟:
1.[root@localhost ~]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz - C /usr/local/
[root@localhost ~]# cd /usr/local/mysql-5.5.15-linux2.6-i686
[root@localhost mysql-5.5.15-linux2.6-i686]# less INSTALL-BINARY
文件內容:
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
2.按照INSTALL-BINARY文件內容順序安裝
[root@localhost local]# ln -s mysql-5.5.15-linux2.6-i686/ mysql
[root@localhost local]# cd mysql
[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -r -g mysql mysql
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# scripts/mysql_install_db --user=mysql //以mysql身份運行初始化腳本
[root@localhost mysql]# chown -R root .
//全部者改回來
[root@localhost mysql]# chown -R mysql data
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf
[root@localhost mysql]# bin/mysqld_safe --user=mysql & //啓動服務
[root@localhost mysql]# netstat -tupln |grep mysql
tcp
0 0 :::3306 :::* LI STEN 4549/mysqld
換成經常使用方式啓動服務:
[root@localhost mysql]cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# service mysqld stop
Shutting down MySQL.
[肯定]
[root@localhost mysql]# netstat -tupln |grep mysql
[root@localhost mysql]# service mysqld start
Starting MySQL..
[肯定]
[root@localhost mysql]# netstat -tupln |grep mysql
tcp
0 0 :::3306 :::* LISTEN 5544/mysqld
3.庫文件說明:系統調用庫通常是從 /lib 、 /usr/lib ; 可是此次安裝的庫是在/usr/local/mysql/lib ,爲非標準類型的庫,因此須要連接到系統上去
方法:
[root@localhost mysql]# cd /etc/ld.so.conf.d
vim mysql.conf
文件內容加上:
/usr/local/mysql/lib
[root@localhost ld.so.conf.d]# ldconfig -v |grep mysql //查看系統是否連接上庫
/usr/local/mysql/lib:
libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0
//說明庫能夠被調用了
4.頭文件說明:mysql的頭文件include也不在常見目錄:/usr/include /; 由於不是標準路徑,須向系統指明路徑
方法:
[root@localhost ld.so.conf.d]# cd /usr/include/
[root@localhost include]# ln -s /usr/local/mysql/include/ mysql
二.安裝php
1.解壓並編譯安裝
[root@localhost ~]#tar -jxvf php-5.3.7.tar.bz2 -C /usr/local/src/
[root@localhost php-5.3.7]#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --with-libevent-dir=/usr/local --enable-mbstring --with-zlib
--with-mysqli=/usr/local/mysql/bin/mysql_config --with-freetype-dir --with-jpeg-dir --with-png-dir --with-libxml-dir=/usr --enable-xml --with-iconv-dir=/usr/local
[root@localhost php-5.3.7]#make
[root@localhost php-5.3.7]#make insall
2.整合nginx和php
[root@localhost php-5.3.7]# cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-5.3.7]#cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-5.3.7]#cd /usr/local/php/etc/
vim php-fpm.conf
文件內容修改:去掉前面的「;」
30 error_log = log/php-fpm.log
166 pm.start_servers = 20
171 pm.min_spare_servers = 5
176 pm.max_spare_servers = 35
182 pm.max_requests = 500
3.啓動fastcgi服務
[root@localhost etc]# /usr/local/php/sbin/php-fpm &
4.vim /etc/nginx/fastcgi.conf
文件內容修改:
fastcgi_param SERVER_SOFTWARE
nginx; //修改成nginx;
vim /etc/nginx/fastcgi_params
文件內容修改:
fastcgi_param SERVER_SOFTWARE
nginx; //修改成nginx;
vim /etc/nginx/nginx.conf
文件內容修改:
43
location / {
44
root /usr/html; //修改文件目錄爲/usr/html
45
index index.php index.html index.htm; //加入index.php網頁類型
46
}
65
location ~ \.php$ {
66
root /usr/html; //修改文件目錄爲/usr/html
67
fastcgi_pass 127.0.0.1:9000;
68
fastcgi_index index.php;
69
fastcgi_param SCRIPT_FILENAME /usr/html$fastcgi_script_name; //修改文件目錄爲/usr/html
70
include fastcgi_params;
71
}
四.測試
1.經過nginx調用php
vim /usr/html/index.html
文件內容增長:
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>
<?php
phpinfo();
?>
[root@localhost ~]# cd /usr/html
[root@localhost html]# mv index.html index.php
Web訪問:
3.經過php調動mysql
vim /usr/html/index.php
文件內容修改:
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>
<?php
$link=mysql_connect('127.0.0.1','root','');
if ($link)
echo "connect";
else echo "fail"
?>
Web訪問: