1、請描述一次完整的http請求處理過程;
一次完整的http請求處理過程:
(1) 建立或處理連接:接收請求或拒絕請求;
(2) 接收請求:接收來自于網絡上的主機請求報文中對某特定資源的一次請求的過程;
(3) 處理請求:對請求報文進行解析,獲取客戶端請求的資源及請求方法等相關信息;
(4) 訪問資源:獲取請求報文中請求的資源;
(5) 構建響應報文:
(6) 發送響應報文:
(7) 記錄日志:
2、httpd所支持的處理模型有哪些,他們的分別使用于哪些環境。
MPM:Multipath processing Modules (多路處理模塊)
prefork:多進程模型,每個進程響應一個請求;
一個主進程:負責生成子進程及回收子進程;負責創建套接字;負責接收請求,并將其派發給某子進程進行處理;
n個子進程:每個子進程處理一個請求;
工作模型:會預先生成幾個空閑進程,隨時等待用于響應用戶請求;最大空閑和最小空閑;
worker:多進程多線程模型,每線程處理一個用戶請求;
一個主進程:負責生成子進程;負責創建套接字;負責接收請求,并將其派發給某子進程進行處理;
多個子進程:每個子進程負責生成多個線程;
并發響應數量:m*n每個線程:負責響應用戶請求;
m:子進程數量
n:每個子進程所能創建的最大線程數量;
event:事件驅動模型,多進程模型,每個進程響應多個請求;
一個主進程 :負責生成子進程;負責創建套接字;負責接收請求,并將其派發給某子進程進行處理;
子進程:基于事件驅動機制直接響應多個請求;
httpd-2.2: 仍為測試使用模型;
httpd-2.4:event可生產環境中使用;
3、源碼編譯安裝LAMP環境(基于wordpress程序),并寫出詳細的安裝、配置、測試過程。
OS版本:2.6.32-431.el6.x86_64
httpd版本:2.4.9
mariadb版本:mariadb-10.0.13
php版本:php-5.4.26
1、安裝編譯安裝所需系統環境
~]# yum groupinstall "Development Tools" "Server Platform Development" -y
2、編譯安裝http-2.4.9需要較新版本的apr和apr-util,對這兩個包進行解壓后編譯安裝
(1)編譯安裝apr
~]#tar -xf apr-1.5.0.tar.bz2
cd apr-1.5.0
./configure –prefix=/usr/local/apr
make && make install
(2)編譯安裝apr-util
~]# tar xf apr-util-1.5.3.tar.bz2
~]# cd apr-util-1.5.3
apr-util-1.5.3]# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
apr-util-1.5.3]# make && make install
3、編譯安裝httpd
~]# tar -xf httpd-2.4.9.tar.bz2
~]# cd httpd-2.4.9
httpd-2.4.9]# yum install -y openssl openssl-devel pcre pcre-devel 安裝幾個必備軟件
httpd-2.4.9]#./configure –prefix=/usr/local/apache24 –sysconfdir=/etc/httpd24 –enable-so –enable-ssl –enable-cgi –enable-rewrite –with-zlib –with-pcre –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util –enable-modules=most –enable-mpms-shared=all –with-mpm=prefork 我選擇了profork模型
httpd-2.4.9]# make && make install
將apache24的bin加入path變量中
~]# vim /etc/profile.d/httpd.sh
export PATH=/usr/local/apache24/bin:$PATH
~]#source /etc/profile.d/httpd.sh
輸出頭文件至系統文件路徑usr/include
~]# ln -sv /usr/local/apache24/include/ /usr/include/apache24
"/usr/include/apache24" -> "/usr/local/apache24/include/"
啟動httpd并測試是否正常
~]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.
localdomain. Set the 'ServerName' directive globally to suppress this message
~]# ss -tnl | grep 80
LISTEN 0 128 :::80 :::*
~]# curl http://192.168.150.136
<html><body><h1>It works!</h1></body></html>
4、編譯安裝mariadb
首先安裝mariadb編譯安裝所需的cmake、ncurses-devel
~]# yum -y install cmake ncurses-devel
(1)創建數據存放目錄
~]# mkdir -pv /data/mydata
mkdir: 已創建目錄 "/data"
mkdir: 已創建目錄 "/data/mydata"
(2)創建mysql用戶,并授予數據文件mysql賬戶權限
~]# groupadd mysql
~]# useradd -s /sbin/nologin -g mysql -M mysql
~]# id mysql
uid=500(mysql) gid=500(mysql) 組=500(mysql)
~]# chown -R mysql.mysql /data/mydata
(3)安裝mariadb
解壓mariadb
~]# tar -xf mariadb-10.0.13.tar.gz
編譯安裝mariadb
mariadb-10.0.13]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mydata -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
mariadb-10.0.13]# make && make install
(4)配置mariadb
初始化數據庫
~]# cd /usr/local/mysql/
mysql]# scripts/mysql_install_db –user=mysql –datadir=/data/mydata
mysql]# ls /data/mydata/
aria_log.00000001 ibdata1 ib_logfile1 performance_schema
aria_log_control ib_logfile0 mysql test
設置配置文件,修改datadir指定目錄項和socket所指定文件
[mysqld]
datadir=/data/mydata
socket=/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
設置啟動腳本
mysql]# cp support-files/mysql.server /etc/init.d/mysqld
mysql]# chkconfig –add mysqld
mysql]# chkconfig –list mysqld
啟動并查看服務
mysql]# service mysqld start
Starting MySQL. SUCCESS!
~]# ss -tnlp | grep 3306
LISTEN 0 128 :::3306 :::* users:(("mysqld",65174,
16))
設置環境變量
~]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
~]# source /etc/profile.d/mysql.sh
導出頭文件
~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
導出庫文件
mysql]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
mysql]# ldconfig -v
mysql]# ldconfig -p |grep mysql
libmysqlclient_r.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient_r.so.16
libmysqlclient.so.18 (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so.18
libmysqlclient.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so.16
libmysqlclient.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so
使用mysql_secure_installation腳本來進行安全配置
[root@localhost mysql]# mysql_secure_installation
/usr/local/mysql/bin/mysql_secure_installation: line 379: find_mysql_client: command not fou
nd
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, 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 MariaDB
root user without the proper authorisation.
Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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]
… 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] n
… skipping.
By default, MariaDB 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] n
… skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]
… Success!
Cleaning up…
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
5、編譯安裝php
編譯安裝前安裝所需要包
~]# yum -y install libxml2-devel
解壓并進行編譯安裝,注意編譯安裝的參數要和前面安裝的參數一致,比如說Mysql的apache24
php-5.4.26]# ./configure –prefix=/usr/local/php –with-mysql=/usr/local/mysql –with-o
penssl –with-mysqli=/usr/local/mysql/bin/mysql_config –enable-mbstring –with-png-dir –with-jpeg-dir –with-freetype-dir –with-zlib –with-libxml-dir=/usr –enable-xml –enable-sockets –with-apxs2=/usr/local/apache24/bin/apxs –with-mcrypt –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-bz2
編譯時報錯
configure: error: Please reinstall the BZip2 distribution
安裝bzip2-devel
php-5.4.26]# yum -y install bzip2-devel
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
~]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
~]# tar -xf libmcrypt-2.5.7.tar.gz
~]# cd libmcrypt-2.5.7
libmcrypt-2.5.7]# ./configure
libmcrypt-2.5.7]# make && make install
再次編譯沒有問題,進行安裝
php-5.4.26]# make -j 4 && make install
6、修改httpd的配置文件,支持php
~]# vim /etc/httpd24/httpd.conf
末行添加
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
定位至DirectoryIndex index.html
修改為:
DirectoryIndex index.php index.html
重啟httpd服務,并編輯測試頁進行php和mysql的連接測試
~]# apachectl restart
~]# cd /usr/local/apache24/htdocs
htdocs]# ls
index.html
htdocs]# vim index.php
測試php
<h1>phptestpage</h1>
<?php
phpinfo();
?>
測試mysql
htdocs]# cat index.php
<h1>test page</h1>
<?php
$conn = mysql_connect('127.0.0.1','root','oracleadmin');
if ($conn)
echo "OK";
else
echo "Failure";
?>
7、部署wordpress
~]# unzip wordpress-3.2.1-zh_CN.zip
[root@localhost ~]# cp -rf wordpress /usr/local/apache24/htdocs/
[root@localhost ~]# cd /usr/local/apache24/htdocs/wordpress/
[root@localhost wordpress]# cp wp-config-sample.php wp-config.php
[root@localhost wordpress]# vim wp-config.php
/** WordPress 數據庫的名稱 */
define('DB_NAME', 'wpdb');
/** MySQL 數據庫用戶名 */
define('DB_USER', 'wpuser');
/** MySQL 數據庫密碼 */
define('DB_PASSWORD', 'wppasswd');
數據庫創建
~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.0.13-MariaDB Source distribution
Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> GRANT ALL ON wpdb.* TO 'wpuser'@'localhost' IDENTIFIED BY 'wppasswd';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> CREATE DATABASE wpdb;
Query OK, 1 row affected (0.06 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.04 sec)
MariaDB [(none)]> exit
Bye
~]# mysql -uwpuser -pwppasswd
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.0.13-MariaDB Source distribution
Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> SHOW DATABASES;
+——————–+
| Database |
+——————–+
| information_schema |
| test |
| wpdb |
+——————–+
3 rows in set (0.05 sec)
4、建立httpd服務器(基于編譯的方式進行),要求:
提供兩個基于名稱的虛擬主機:
(a)www1.stuX.com,頁面文件目錄為/web/vhosts/www1;錯誤日志為/var/log/httpd/www1.err,訪問日志為/var/log/httpd/www1.access;
(b)www2.stuX.com,頁面文件目錄為/web/vhosts/www2;錯誤日志為/var/log/httpd/www2.err,訪問日志為/var/log/httpd/www2.access;
(c)為兩個虛擬主機建立各自的主頁文件index.html,內容分別為其對應的主機名;
(d)通過www1.stuX.com/server-status輸出httpd工作狀態相關信息,且只允許提供帳號密碼才能訪問(status:status);
1、httpd的編譯安裝參考上題
2、編輯配置文件
~]# vim /etc/httpd24/httpd.conf
主配置文件注釋
#DocumentRoot "/usr/local/apache24/htdocs"
virtual hosts選項打開
Include /etc/httpd24/extra/httpd-vhosts.conf
3、建立虛擬主機配置文件
~]# vim /etc/httpd24/extra/httpd-vhosts.conf
<VirtualHost 192.168.150.136 *:80>
ServerAdmin webmaster@example.com
DocumentRoot "/web/vhost/www1/"
ServerName www1.stuX.com
ServerAlias www.example.com
ErrorLog "/var/log/httpd/www1.err"
CustomLog "/var/log/httpd/www1.access" common
<Directory "/web/vhost/www1">
AllowOverride None
Options None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.150.136 *:80>
ServerAdmin webmaster@example.com
DocumentRoot "/web/vhost/www2"
ServerName www2.stuX.com
ErrorLog "/var/log/httpd/www2.err"
CustomLog "/var/log/httpd/www2.access" common
<Directory "/web/vhost/www2">
AllowOverride None
Options None
Require all granted
</Directory>
</VirtualHost>
4、創建目錄及文件
mkdir -pv /web/vhost/{www1,www2}
mkdir: 已創建目錄 "/web"
mkdir: 已創建目錄 "/web/vhost"
mkdir: 已創建目錄 "/web/vhost/www1"
mkdir: 已創建目錄 "/web/vhost/www2
]# mkdir -p /var/log/httpd
~]# for i in {1..2};do echo "www$i.site" > /web/vhost/www$i/index.html;done
語法檢查
]# httpd -t
Syntax OK
5、重啟httpd服務并進行訪問測試
~]# apachectl restart
~]# vim /etc/hosts
~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.150.136 www1.stuX.com
192.168.150.136 www2.stuX.com
~]# curl http://www2.stuX.com
www2.site
~]# curl http://www1.stuX.com
www1.site
6、構建Server-Status設置
在www1.stuX.com里,增加server-status的設置,具體內容如下:
<VirtualHost 192.168.150.136 *:80>
DocumentRoot "/web/vhost/www1"
ServerName www1.stuX.com
ErrorLog "/var/log/httpd/www1.err"
CustomLog "/var/log/httpd/www1.access" common
<Location /server-status>
SetHandler server-status
AuthType Basic
AuthName "Server-Status"
AuthUserFile "/etc/httpd/.htpasswd"
Require valid-user
</Location>
</VirtualHost>
生成.htpasswd密碼驗證文件
httpd24]# htpasswd -c -m .htpasswd status
New password:
Re-type new password:
Adding password for user status
重啟服務后驗證
httpd24]# apachectl restart
5、為第4題中的第2個虛擬主機提供https服務,使得用戶可以通過https安全的訪問此web站點;
(1)要求使用證書認證,證書中要求使用的國家(CN)、州(HA)、城市(ZZ)和組織(MageEdu);
(2)設置部門為Ops,主機名為www2.stuX.com,郵件為admin@stuX.com;
1、創建私有CA并頒發證書
~]# cd /etc/pki/CA/
CA]# touch index.txt
CA]# echo 01 > serial
CA]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
………………………..+++
………………………………..+++
e is 65537 (0x10001)
CA]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 365 -out /etc/pki/
CA/cacert.pemYou are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
—–
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HA
Locality Name (eg, city) [Default City]:ZZ
Organization Name (eg, company) [Default Company Ltd]:MageEdu
Organizational Unit Name (eg, section) []:Ops
Common Name (eg, your name or your server's hostname) []:stuX.com
Email Address []:admin@stuX.com
CA]# cd /etc/httpd24/
httpd24]# mkdir ssl
httpd24]# cd ssl
ssl]# (umask 077;openssl genrsa -out httpd.key 1024)
Generating RSA private key, 1024 bit long modulus
…………..++++++
………++++++
e is 65537 (0x10001)
ssl]# ls
httpd.key
ssl]# openssl req -new -key httpd.key -out httpd.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
—–
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HA
Locality Name (eg, city) [Default City]:ZZ
Organization Name (eg, company) [Default Company Ltd]:MageEdu
Organizational Unit Name (eg, section) []:Ops
Common Name (eg, your name or your server's hostname) []:www2.stuX.com
Email Address []:amin@stuX.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
ssl]# openssl ca -in /etc/httpd24/ssl/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days
365Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Nov 7 04:14:36 2016 GMT
Not After : Nov 7 04:14:36 2017 GMT
Subject:
countryName = CN
stateOrProvinceName = HA
organizationName = MageEdu
organizationalUnitName = Ops
commonName = www2.stuX.com
emailAddress = amin@stuX.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
87:65:5E:DA:71:EF:1A:E3:A1:2E:48:A4:0F:D2:43:68:11:1E:01:39
X509v3 Authority Key Identifier:
keyid:AE:2C:20:53:29:AE:2B:63:6A:34:35:BC:B3:EA:CB:79:3C:C9:B7:C5
Certificate is to be certified until Nov 7 04:14:36 2017 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
ssl]# ls /etc/pki/CA/certs/httpd.crt
/etc/pki/CA/certs/httpd.crt
ssl]# cp /etc/pki/CA/certs/httpd.crt /etc/httpd24/ssl/
ssl]# ls
httpd.crt httpd.csr httpd.key
2、修改配置文件提供ssl服務
開啟主配置文件的ssl調用,刪除www2在httpd-vhosts中的定義
Include /etc/httpd24/extra/httpd-ssl.conf
~]# vim /etc/httpd24/extra/httpd-ssl.conf
[root@localhost httpd24]# cat extra/httpd-ssl.conf | grep -v "^#"
Listen 443
SSLPassPhraseDialog builtin
<VirtualHost 192.168.150.136:443>
DocumentRoot "/web/vhost/www2"
ServerName www2.stuX.com:443
ServerAdmin you@example.com
ErrorLog "/var/log/httpd/www2.err"
TransferLog "/usr/local/apache24/logs/access_log"
SSLEngine on
SSLCertificateFile "/etc/httpd24/ssl/httpd.crt"
SSLCertificateKeyFile "/etc/httpd24/ssl/httpd.key"
<Directory "/web/vhost/www2">
AllowOverride None
Options None
Require all granted
</Directory>
</VirtualHost>
主配置文件中啟用ssl模塊
~]# vim /etc/httpd24/httpd.conf
LoadModule ssl_module modules/mod_ssl.so
重啟httpd服務后測試
httpd24]# ss -tnl | grep 443
LISTEN 0 128 :::443 :::*
6、在LAMP架構中,請分別以php編譯成httpd模塊形式和php以fpm工作為獨立守護進程的方式來支持httpd,列出詳細的過程。
CentOS 6:
PHP-5.3.2-:默認不支持fpm機制;需要自行打補丁并編譯安裝;
httpd-2.2:默認不支持fcgi協議,需要自行編譯此模塊;
解決方案:編譯安裝httpd-2.4, php-5.3.3+;
此次試驗httpd版本2.4.9 httpd的編譯安裝同上,省略
php版本5.4.26
編譯安裝前安裝所需要包
~]# yum -y install libxml2-devel
安裝bzip2-devel
php-5.4.26]# yum -y install bzip2-devel
~]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
~]# tar -xf libmcrypt-2.5.7.tar.gz
~]# cd libmcrypt-2.5.7
libmcrypt-2.5.7]# ./configure
libmcrypt-2.5.7]# make && make install
1、php編譯成http模塊形式
./configure –prefix=/usr/local/php –with-mysql=mysqlnd –with-openssl –with-mysqli=mysqlnd –enable-mbstring –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr/lib64 –enable-xml –enable-sockets –with-apxs2=/usr/local/apache24/bin/apxs –with-mcrypt=/usr/local/libmcrypt –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-bz2 –enable-maintainer-zts
其中–with-apxs2=/usr/local/apache24/bin/apxs選擇即指定在編譯時將php定義為http的模塊形式
make && make install
拷貝配置文件至/etc目錄
php-5.4.26]# cp php.ini-production /etc/php.ini
在httpd的主配置文件中添加php類型
php-5.4.26]# vim /etc/httpd24/httpd.conf
添加選項
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
定位DirectoryIndex修改為DirectoryIndex index.php index.html
編輯php測試頁并開啟httpd服務進行測試
php-5.4.26]# cd /usr/local/apache24/htdocs/
htdocs]# vim index.php
<h1>phptest</h1>
<?php
phpinfo();
?>
[root@localhost htdocs]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.
localdomain. Set the 'ServerName' directive globally to suppress this message[root@localhost htdocs]# ss -tnl 進程中只有Httpd
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 ::1:6010 :::*
2、php編譯成fpm模式
./configure –prefix=/usr/local/php5 –with-mysql=mysqlnd –with-openssl –with-mysqli=mysqlnd –enable-mbstring –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –enable-sockets –enable-fpm –with-mcrypt –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-bz2
添加了–enable-fpm選項
make && make install
拷貝配置文件至/etc目錄
php-5.4.26]# cp php.ini-production /etc/php.ini
拷貝php-fpm配置文件,并同時取消pid選項的注釋
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
php-5.4.26]# vim /usr/local/php5/etc/php-fpm.conf
pid = /usr/local/php5/var/run/php-fpm.pid
添加服務腳本
fpm]# pwd
/root/php-5.4.26/sapi/fpm
fpm]# cp init.d.php-fpm /etc/rc.d/init.d/php-fp
~]# chmod +x /etc/rc.d/init.d/php-fpm
~]# chkconfig –add php-fpm
啟動php-fpm
~]# service php-fpm start
~]# ps aux | grep fpm
root 14881 0.0 0.3 68920 3928 ? Ss 09:51 0:00 php-fpm: master process (/usr/local/p
hp5/etc/php-fpm.conf) nobody 14882 0.0 0.3 68920 3460 ? S 09:51 0:00 php-fpm: pool www
nobody 14883 0.0 0.3 68920 3460 ? S 09:51 0:00 php-fpm: pool www
root 14885 0.0 0.0 103260 872 pts/1 S+ 09:51 0:00 grep fpm
配置httpd
~]# vim /etc/httpd24/httpd.conf
啟用這兩個模塊
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
添加文件類型
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
添加php文件的訪問通過fpm
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache24/htdocs/$1
找到 DirectoryIndex index.html
改為
DirectoryIndex index.php index.html
編輯php測試頁并開啟httpd進行測試
php-5.4.26]# cd /usr/local/apache24/htdocs/
htdocs]# vim index.php
<h1>phpfpmtest</h1>
<?php
phpinfo();
?>
[root@localhost htdocs]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.
localdomain. Set the 'ServerName' directive globally to suppress this
[root@localhost htdocs]# ss -tnl httpd 80 php-fpm 9000
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 128 127.0.0.1:6011 *:*
LISTEN 0 128 ::1:6011 :::*
LISTEN 0 128 127.0.0.1:9000 *:*
此時的Server API為FPM/FastCGI
原創文章,作者:N23-蘇州-void,如若轉載,請注明出處:http://www.www58058.com/63734
贊,LAMP總結的很完整,這將成為你日后工作中寶貴的筆記~可以加個擴展,比如你的架構師怎樣的,集群的架構是怎么樣的~~繼續加油~