N21天天第十二周課程練習

1、請描述一次完整的http請求處理過程;

1、建立TCP連接
2、Web瀏覽器向Web服務器發送請求
3、Web瀏覽器發送請求頭信息
  建立連接后,客戶機發送一個請求給服務器,請求方式的格式為:統一資源標識符(URL)、協議版本號,后邊是MIME
  信息包括請求修飾符、客戶機信息和可能的內容
4、Web服務器應答
  服務器接到請求后,給予相應的響應信息,其格式為一個狀態行,包括信息的協議版本號、一個成功或錯誤的代碼,后邊
  是MIME信息包括服務器信息、實體信息和可能的內容。
5、Web服務器發送應答頭信息
6、Web服務器向瀏覽器發送數據
7、Web服務器關閉TCP連接

2、httpd所支持的處理模型有哪些,他們的分別使用于哪些環境。

httpd所支持的事務處理模型主要有:
prefork
worker
event
他們分別使用于以下場景:
prefork:多進程模型,每個進程負責響應一個請求。prefork模型在工作時,由一個主進程負責生成n個子進程,即工
  作進程。每個工作進程響應一個用戶請求,即使當前沒有用戶請求,它亦會預先生成多個空閑進程,隨時等待請求連接,
  這樣的好處是,服務器不用等到請求到達時,才去臨時建立進程,縮短了進程創建的時間。提高連接效率。但受限于
  linux的特性,工作進程數上限為1024個,如果超出該數量,服務器性能會急劇降低。因而,prefork模型的最大并發連
  接數量為1024.由于每個工作進程相對獨立,就算崩潰了,也不會對其它進程有明顯影響。所以,該模型的特點是穩定可
  靠,適合于并發量適中而又追求穩定的用戶使用。
worker:多線程模型,每個線程響應一個請求。worker模型在工作時,主進程負責生成多個子進程, 同時每個子進程負
  責生成多個線程,每個線程響應一個用戶請求。同時,worker模型也會預先創建一些空閑線程來等待用戶連接。并發
  連接數,如果生成進程數為m,線程數為n,則并發數可達到m*n個。但由于在linux中,原生不支持線程,且進程本身
  就足夠輕量化,與線程的區別不是很大,因而,worker模型在linux環境中的實際性能表現與prefork相差無幾。
event:事件驅動模型,每個線程響應n個用戶請求。event模型工作時,由主進程生成m個子進程,每 個單獨的子進程可
  響應n個用戶請求。因而,event的并發數量可達到m*n個,同時,因為event的子進程為一對多,節省大量CPU進程切換
  上下文的時間,也沒有了linux系統的1024個進程限制,所以,event模型是三種模型中效率最高的一種   ??梢酝黄?
  10K的限制(即并發數1W),對海量的系統特別適用。

3、源碼編譯安裝LAMP環境(基于wordpress程序),并寫出詳細的安裝、配置、測試過程。

以CentOS7.2,http2.4.16,mysql-5.6.26.tar.gz,mysql-5.6.26.tar.gz為例,源碼編譯安裝LAMP,詳細步驟如下:

安裝開發環境
[root@localhost ~]# yum groupinstall "Development Tools" "Server Platform Development" -y
1、編譯安裝Apache
解決依賴關系
(1)編譯安裝apr
[root@localhost ~]# tar xf apr-1.5.2.tar.gz 
[root@localhost ~]# cd apr-1.5.2/
[root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr
root@localhost ~]# make && make install && cd
(2)編譯安裝apr-util
[root@localhost ~]# tar xf apr-util-1.5.4.tar.bz2 
[root@localhost ~]# cd apr-util-1.5.4/
[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util 
  --with-apr=/usr/local/apr 
[root@localhost apr-util-1.5.4]# make && make install && cd
(3)httpd-2.4.16依賴于pcre-devel軟件包
[root@localhost ~]# yum -y install pcre-devel  openssl-devel
編譯安裝httpd-2.4.16
[root@localhost ~]# tar xf httpd-2.4.16.tar.bz2 
[root@localhost ~]# cd httpd-2.4.16/
[root@localhost httpd-2.4.16]# ./configure --prefix=/usr/local/apache 
  --sysconfdir=/etc/httpd --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
[root@localhost ~]# make -j 4 && make install &&cd
[root@localhost ~]# vim /etc/profile.d/httpd.sh
添加
export PATH=/usr/local/apache/bin:$PATH
[root@localhost ~]# . /etc/profile.d/httpd.sh 
#編輯apache服務腳本
[root@localhost ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
[root@localhost ~]# vim /etc/init.d/httpd
添加
# chkconfig: 2345 85 15
# description: httpd startup for the Apache Http Server
[root@localhost ~]# service httpd start
[root@localhost ~]# chkconfig --add httpd
[root@localhost ~]# chkconfig httpd on
[root@localhost ~]# ss -tnl | grep :80
LISTEN     0      128         :::80                      :::* 
2、編譯安裝MySQL
#添加mysql用戶
[root@localhost ~]# groupadd -g 316 mysql
[root@localhost ~]# useradd -g mysql -u 316 -r -s /sbin/nologin mysql 
#安裝mysql依賴的軟件包
[root@localhost ~]# yum -y install cmake ncurses-devel
#編譯安裝mysql 
[root@localhost ~]# tar xf mysql-5.6.26.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/mysql-5.6.26/
[root@localhost mysql-5.6.26]# cmake  --DCMAKE_INSTALL_PREFIX=/usr/local/mysql  
  --DMYSQL_UNIX_ADDR=/tmp/mysql.sock   --DDEFAULT_CHARSET=utf8  
  --DDEFAULT_COLLATION=utf8_general_ci  --DWITH_EXTRA_CHARSETS=all  
  --DWITH_MYISAM_STORAGE_ENGINE=1 --DWITH_INNOBASE_STORAGE_ENGINE=1  
  --DWITH_MEMORY_STORAGE_ENGINE=1  --DWITH_READLINE=1  --DENABLED_LOCAL_INFILE=1  
  --DMYSQL_DATADIR=/usr/local/mysql/data  --DMYSQL-USER=mysql
[root@localhost mysql-5.6.26]# make -j 4 && make install
[root@localhost mysql-5.6.26]# cd && chown -R mysql:mysql /usr/local/mysql/
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# sed  -i 's#^basedir=#basedir=/usr/local/mysql#' /etc/init.d/mysqld
[root@localhost ~]# sed  -i 's#^datadir=#datadir=/usr/local/mysql/data#' /etc/init.d/mysqld
[root@localhost ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
[root@localhost ~]# sed -i '/^\[mysqld\]/adatadir = /usr/local/mysql/data' /etc/my.cnf
[root@localhost ~]# sed -i '/^\[mysqld\]/abasedir = /usr/local/mysql' /etc/my.cnf
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf
  --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
[root@localhost ~]# ln -s /usr/local/mysql/bin/* /bin/
[root@localhost ~]# service mysqld start
3、安裝PHP
#安裝PHP依賴的軟件包
[root@localhost ~]# yum -y install libxml2-devel
#編譯安裝PHP
[root@localhost ~]# tar xf php-5.6.13.tar.bz2 
[root@localhost ~]# cd php-5.6.13/
[root@localhost php-5.6.13]# ./configure --prefix=/usr/local/php 
  --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache/bin/apxs 
  --with-config-file-path=/usr/local/php
[root@localhost php-5.6.13]# make ; make install 
[root@localhost php-5.6.13]# cp php.ini-production /usr/local/php/php.ini;cd
[root@localhost ~]# sed -i 's/index.html/index.html index.php/' /etc/httpd/httpd.conf
[root@localhost ~]#  sed -i '377a    AddType application/x-httpd-php .php' 
  /etc/httpd/httpd.conf 
[root@localhost ~]# sed -i '378a    AddType application/x-httpd-php-source .phps' 
  /etc/httpd/httpd.conf 
[root@localhost ~]# service httpd  restart
[root@localhost ~]# echo '<?php phpinfo();  ?>' >/usr/local/apache/htdocs/index.php
4、wordpress程序的安裝
#下載wordpress程序
[root@localhost ~]# wget https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz
#解壓wordpress到/usr/local/apache/htdocs/
[root@localhost ~]# tar xf wordpress-4.5.3-zh_CN.tar.gz -C /usr/local/apache/htdocs/
[root@localhost ~]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# chown root:root wordpress/ -R
[root@localhost htdocs]# cd wordpress/
[root@localhost wordpress]# cp wp-config-sample.php wp-config.php
(1)修改數據庫名
修改 
define('DB_NAME', 'database_name_here');
為
define('DB_NAME', 'wordpress');
(2) 修改MySQL數據庫登錄用戶名
修改 
define('DB_USER', 'username_here');
為
define('DB_USER', 'root');
(3)修改MySQL數據庫登錄密碼
修改
define('DB_PASSWORD', 'password_here');
為
define('DB_PASSWORD', 'magedu');
#登錄mysql創建wordpress數據庫,并設置root用戶登錄密碼
[root@localhost ~]# mysql
mysql> create database wordpress;
mysql> use mysql;
mysql> update user set password=PASSWORD('magedu') where user='root';
mysql> flush privileges;
mysql> \q
在瀏覽器中輸入
http://192.168.1.72/wordpress/
設置注冊用戶的用戶名和密碼,完成安裝wordPress

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);

安裝開發環境
[root@localhost ~]# yum groupinstall "Development Tools" "Server Platform Development" -y
1、編譯安裝Apache
解決依賴關系
(1)編譯安裝apr
[root@localhost ~]# tar xf apr-1.5.2.tar.gz 
[root@localhost ~]# cd apr-1.5.2/
[root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr
root@localhost ~]# make && make install && cd
(2)編譯安裝apr-util
[root@localhost ~]# tar xf apr-util-1.5.4.tar.bz2 
[root@localhost ~]# cd apr-util-1.5.4/
[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util 
  --with-apr=/usr/local/apr 
[root@localhost apr-util-1.5.4]# make && make install && cd
(3)httpd-2.4.16依賴于pcre-devel軟件包
[root@localhost ~]# yum -y install pcre-devel  openssl-devel
編譯安裝httpd-2.4.16
[root@localhost ~]# tar xf httpd-2.4.16.tar.bz2 
[root@localhost ~]# cd httpd-2.4.16/
[root@localhost httpd-2.4.16]# ./configure --prefix=/usr/local/apache 
  --sysconfdir=/etc/httpd --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
[root@localhost ~]# make -j 4 && make install &&cd
[root@localhost ~]# vim /etc/profile.d/httpd.sh
添加
export PATH=/usr/local/apache/bin:$PATH
[root@localhost ~]# . /etc/profile.d/httpd.sh 
#編輯apache服務腳本
[root@localhost ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
[root@localhost ~]# vim /etc/init.d/httpd
添加
# chkconfig: 2345 85 15
# description: httpd startup for the Apache Http Server
[root@localhost ~]# service httpd start
[root@localhost ~]# chkconfig --add httpd
[root@localhost ~]# chkconfig httpd on
[root@localhost ~]# ss -tnl | grep :80
LISTEN     0      128         :::80                      :::* 
2、編輯apache配置文件
[root@localhost ~]# cd /etc/httpd/
[root@localhost httpd]# cp httpd.conf{,.bak}
[root@localhost httpd]# vim httpd.conf
(1)啟用虛擬主機
修改
#Include /etc/httpd/extra/httpd-vhosts.conf
為
Include /etc/httpd/extra/httpd-vhosts.conf
(2)添加兩個虛擬主機目錄的訪問權限
在末尾添加以下內容:
<Directory "/web/vhosts/www1">
options none
allowoverride none
Require all granted
</Directory>
<Directory "/web/vhosts/www2">
options none
allowoverride none
Require all granted
</Directory>
(3)創建虛擬主機目錄
[root@localhost ~]# mkdir -p /web/vhosts/www{1,2}
[root@localhost ~]# mkdir /var/log/httpd
[root@localhost ~]# touch /var/log/httpd/www{1,2}.{err,access}
(4)編輯虛擬主機文件
[root@localhost ~]# vim /etc/httpd/extra/httpd-vhosts.conf
在末尾添加以下內容
<VirtualHost *:80>
    DocumentRoot "/web/vhosts/www1"
    ServerName www1.stuX.com
    ErrorLog "/var/log/httpd/www1.err"
    CustomLog "/var/log/httpd/www1.access" common
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "/web/vhosts/www2"
    ServerName www2.stuX.com
    ErrorLog "/var/log/httpd/www2.err"
    CustomLog "/var/log/httpd/www2.access" common
</VirtualHost>
[root@localhost ~]# service httpd restart
(5)創建虛擬主機主頁文件
[root@localhost ~]# echo "<h1>www1.stuX.com</h1>" > /web/vhosts/www1/index.html
[root@localhost ~]# echo "<h1>www2.stuX.com</h1>" > /web/vhosts/www2/index.html 
(6)客戶端測試,需要在DNS服務器或hosts中配置好虛擬主機
[root@localhost ~]# curl www1.stuX.com
<h1>www1.stuX.com</h1>
[root@localhost ~]# curl www2.stuX.com 
<h1>www2.stuX.com</h1>
3、構建Server-Status設置
在www1.stuX.com里,增加server-status的設置
[root@www1 httpd]# vim /etc/httpd/extra/httpd-vhosts.conf 
修改www1.stuX.com主機的配置文件為
<VirtualHost *:80>
DocumentRoot "/web/vhosts/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/extra/.htpasswd"
Require valid-user
</location>
</VirtualHost>
#生成密碼文件
[root@localhost ~]# htpasswd -cm /etc/httpd/extra/.htpasswd status#密碼也設為status
[root@www1 httpd]# service httpd restart

5、為第4題中的第2個虛擬主機提供https服務,使得用戶可以通過https安全的訪問此web站點;

   (1)要求使用證書認證,證書中要求使用的國家(CN)、州(HA)、城市(ZZ)和組織(MageEdu);

   (2)設置部門為Ops,主機名為www2.stuX.com,郵件為admin@stuX.com;

#CA與Web在同一主機上

1、創建私有CA
(1)創建所需要的文件
[root@www1 ~]# cd /etc/pki/CA
[root@www1 CA]# touch index.txt
[root@www1 CA]# echo 01 > serial
(2)CA自簽證書
[root@www1 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)
[root@www1 CA]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 7300 
  -out /etc/pki/CA/cacert.pem
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) []:ca.stuX.com
Email Address []:ca@stuX.com
(3)發證
[root@www1 CA]# cd /etc/httpd/
[root@www1 httpd]# mkdir ssl
[root@www1 httpd]# (umask 077;openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)
Generating RSA private key, 2048 bit long modulus
.......................................+++
..................................................................................
..................................................................................
.........+++
e is 65537 (0x10001)
[root@www1 httpd]# openssl req -new -key /etc/httpd/ssl/httpd.key -days 365 -out 
 /etc/httpd/ssl/httpd.csrYou 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 []:admin@stuX.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
 
  [root@www1 httpd]# openssl ca -in /etc/httpd/ssl/httpd.csr -out 
  /etc/pki/CA/certs/httpd.crt -days 365
Using 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: Oct 19 09:09:37 2016 GMT
            Not After : Oct 19 09:09:37 2017 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = HA
            organizationName          = MageEdu
            organizationalUnitName    = Ops
            commonName                = www2.stuX.com
            emailAddress              = admin@stuX.com
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                CE:2A:51:9E:2C:5E:05:B4:79:AB:14:C8:32:E7:68:42:2B:E8:CD:4E
            X509v3 Authority Key Identifier: 
                keyid:88:96:ED:8A:43:0F:8B:2A:DD:D4:E5:B1:02:7A:6C:9F:11:45:FF:E9
Certificate is to be certified until Oct 19 09:09:37 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
[root@www1 httpd]# cp /etc/pki/CA/certs/httpd.crt /etc/httpd/ssl/
[root@www1 httpd]# ls /etc/httpd/ssl/
httpd.crt  httpd.csr  httpd.key
[root@www1 ~]# yum -y install mod_ssl
[root@www1 ~]# vim /etc/httpd/conf.d/ssl.conf
在末尾添加以下內容
<VirtualHost 192.168.1.73:443>
DocumentRoot /web/vhosts/www2/
ServerName  www2.stuX.com:443
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/httpd.crt
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key
</VirtualHost>

6、在LAMP架構中,請分別以php編譯成httpd模塊形式和php以fpm工作為獨立守護進程的方式來支持httpd,列出詳細的過程。

安裝開發環境

[root@localhost ~]# yum groupinstall "Development Tools" "Server Platform Development" -y
1、編譯安裝Apache
解決依賴關系
(1)編譯安裝apr、apr-util
[root@localhost ~]# tar xf apr-1.5.2.tar.gz 
[root@localhost ~]# cd apr-1.5.2/
[root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr
root@localhost ~]# make && make install && cd
[root@localhost ~]# tar xf apr-util-1.5.4.tar.bz2 
[root@localhost ~]# cd apr-util-1.5.4/
[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util 
  --with-apr=/usr/local/apr 
[root@localhost apr-util-1.5.4]# make && make install && cd
(2)httpd-2.4.16依賴于pcre-devel軟件包
[root@localhost ~]# yum -y install pcre-devel  openssl-devel
編譯安裝httpd-2.4.16
[root@localhost ~]# tar xf httpd-2.4.16.tar.bz2 
[root@localhost ~]# cd httpd-2.4.16/
[root@localhost httpd-2.4.16]# ./configure --prefix=/usr/local/apache 
  --sysconfdir=/etc/httpd --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
[root@localhost ~]# make -j 4 && make install && cd
[root@localhost ~]# vim /etc/profile.d/httpd.sh
添加
export PATH=/usr/local/apache/bin:$PATH
[root@localhost ~]# . /etc/profile.d/httpd.sh 
#編輯apache服務腳本
[root@localhost ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
[root@localhost ~]# vim /etc/init.d/httpd
添加
# chkconfig: 2345 85 15
# description: httpd startup for the Apache Http Server
[root@localhost ~]# service httpd start
[root@localhost ~]# chkconfig --add httpd
[root@localhost ~]# chkconfig httpd on
[root@localhost ~]# ss -tnl | grep :80
LISTEN     0      128         :::80                      :::* 
2、編譯安裝MySQL
#添加mysql用戶
[root@localhost ~]# groupadd -g 316 mysql
[root@localhost ~]# useradd -g mysql -u 316 -r -s /sbin/nologin mysql 
#安裝mysql依賴的軟件包
[root@localhost ~]# yum -y install cmake ncurses-devel
#編譯安裝mysql 
[root@localhost ~]# tar xf mysql-5.6.26.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/mysql-5.6.26/
[root@localhost mysql-5.6.26]# cmake  --DCMAKE_INSTALL_PREFIX=/usr/local/mysql  
  --DMYSQL_UNIX_ADDR=/tmp/mysql.sock   --DDEFAULT_CHARSET=utf8  
  --DDEFAULT_COLLATION=utf8_general_ci  --DWITH_EXTRA_CHARSETS=all  
  --DWITH_MYISAM_STORAGE_ENGINE=1 --DWITH_INNOBASE_STORAGE_ENGINE=1  
  --DWITH_MEMORY_STORAGE_ENGINE=1  --DWITH_READLINE=1  --DENABLED_LOCAL_INFILE=1  
  --DMYSQL_DATADIR=/usr/local/mysql/data  --DMYSQL-USER=mysql
[root@localhost mysql-5.6.26]# make -j 4 && make install
[root@localhost mysql-5.6.26]# cd && chown -R mysql:mysql /usr/local/mysql/
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# sed  -i 's#^basedir=#basedir=/usr/local/mysql#' /etc/init.d/mysqld
[root@localhost ~]# sed  -i 's#^datadir=#datadir=/usr/local/mysql/data#' 
  /etc/init.d/mysqld
[root@localhost ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
[root@localhost ~]# sed -i '/^\[mysqld\]/adatadir = /usr/local/mysql/data' /etc/my.cnf
[root@localhost ~]# sed -i '/^\[mysqld\]/abasedir = /usr/local/mysql' /etc/my.cnf
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf
  --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
[root@localhost ~]# ln -s /usr/local/mysql/bin/* /bin/
[root@localhost ~]# service mysqld start
3、安裝PHP
安裝php依賴的軟件
[root@localhost ~]# yum -y install libxml2-devel bzip2-devel libcurl-devel libjpeg-devel
   libpng-devel freetype freetype-devel
[root@localhost ~]# tar xf libmcrypt-2.5.8.tar.bz2 
[root@localhost ~]# cd libmcrypt-2.5.8/
[root@localhost libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt
[root@localhost libmcrypt-2.5.8]# make && make install
[root@localhost libmcrypt-2.5.8]# cd
(一)httpd模塊形式編譯安裝PHP
[root@localhost ~]# tar xf php-5.6.13.tar.bz2 
[root@localhost ~]# cd php-5.6.13/
#以httpd模塊方式運行,所以需要在編譯時指定apache的apxs2的目錄路徑 
  --with-apxs2=/usr/local/apache/bin/apxs 
[root@localhost php-5.6.13]# ./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/apache/bin/apxs 
  --with-mcrypt=/usr/local/libcrympt  --with-config-file-path=/etc 
  --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts
[root@localhost php-5.6.13]# make -j 4 && make install
[root@localhost php-5.6.13]# cp php.ini-production /etc/php.ini && cd
#編輯apache配置文件
[root@localhost ~]#sed -i 's/index.html/index.html index.php/' /etc/httpd/httpd.conf
[root@localhost ~]#sed -i '377a    AddType application/x-httpd-php .php' 
  /etc/httpd/httpd.conf
[root@localhost ~]#sed -i '378a    AddType application/x-httpd-php-source .phps' 
  /etc/httpd/httpd.conf
[root@localhost ~]#service httpd  restart
[root@localhost ~]#echo '<?php phpinfo();  ?>' >/usr/local/apache/htdocs/index.php
訪問http://192.168.1.72/index.php進行測試
(二)以fpm模式運行
[root@localhost ~]# sed -i '1a/usr/local/libmcrypt/lib' /etc/ld.so.conf
[root@localhost ~]# sed -i '2a/usr/local/mysql/lib' /etc/ld.so.conf
[root@localhost ~]# yum install php-pear -y
[root@localhost ~]# ldconfig
[root@localhost ~]# echo 'ldconfig' >> /etc/rc.local
[root@localhost ~]# tar xf php-5.6.13.tar.bz2 
[root@localhost ~]# cd php-5.6.13/
#以fpm模式運行,使能fpm選項,--enable-fpm, --with-apxs2一項就不需要啟用了
[root@localhost php-5.6.13]# ./configure --prefix=/usr/local/php 
  --with-config-file-path=/usr/local/php --with-mysql=/usr/local/mysql 
  --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir 
  --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml 
  --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem 
  --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm 
  --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash 
  --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap 
  --with-mcrypt=/usr/local/libmcrypt
[root@localhost php-5.6.13]# make -j 4 && make install
[[root@localhost php-5.6.13]# cp php.ini-production /usr/local/php/php.ini && cd
[root@localhost php-5.6.13]# cp /usr/local/php/etc/php-fpm.conf.default 
  /usr/local/php/etc/php-fpm.conf
[root@localhost php-5.6.13]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.6.13]#  chmod +x /etc/init.d/php-fpm
[root@localhost php-5.6.13]# chkconfig php-fpm on
[root@localhost php-5.6.13]# /etc/init.d/php-fpm start
Starting php-fpm  done
[root@localhost php-5.6.13]# netstat -antup | grep php-fpm
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      
  9769/php-fpm: maste 
#編輯apache配置文件
[root@localhost ~]# sed -i 's/^#LoadModule proxy_fcgi/LoadModule proxy_fcgi/' 
  /etc/httpd/httpd.conf
[root@localhost ~]# sed -i 's/^#LoadModule proxy_module/LoadModule proxy_module/' 
  /etc/httpd/httpd.conf
[root@localhost ~]#sed -i 's/index.html/index.html index.php/' /etc/httpd/httpd.conf
[root@localhost ~]#sed -i '377a    AddType application/x-httpd-php .php' 
  /etc/httpd/httpd.conf
[root@localhost ~]#sed -i '378a    AddType application/x-httpd-php-source .phps' 
  /etc/httpd/httpd.conf
[root@localhost ~]#service httpd  restart
[root@localhost ~]#echo '<?php phpinfo();  ?>' >/usr/local/apache/htdocs/index.php
訪問http://192.168.1.72/index.php進行測試

原創文章,作者:N21-天天,如若轉載,請注明出處:http://www.www58058.com/55105

(0)
N21-天天N21-天天
上一篇 2016-10-31
下一篇 2016-10-31

相關推薦

  • Mariadb數據庫復制系列(五):基于SSL的復制

       實驗五:基于SSL的主從復制功能的實現 在mysql服務器之間復制數據,默認情況下都是基于明文的,在有些場景中,明文傳輸會造成嚴重的數據安全隱患,因此,需要對mysql服務器之間的復制時的傳輸進行加密,傳輸加密方式可以基于SSL的會話進行 1、實驗環境 2、私有CA的搭建 3、在主節點node72上生成證書簽署請求、發送到私有CA服務器 4、在從節點n…

    Linux干貨 2016-11-24
  • man手冊的使用

    在Linux中man的使用頻率應該是很高的,靈活運用它可以讓自己快速的掌握一個不熟悉命令的使用方法。下面來介紹下man 環境CentOS6.8 man – format and display the on-line manual pages 在線使用手冊格式及展示通俗點來說它就是命令的使用手冊。它共分九個章節 1、用戶命令2、系統調用3、C庫調…

    Linux干貨 2016-10-19
  • 磁盤管理

    磁盤,分區,文件系統

    Linux干貨 2017-12-02
  • shell進階之循環

    循環執行,將某代碼段重復運行多次

    重復運行多少次:

    循環次數事先已知

    循環次數事先未知

    有進入條件和退出條件

    for, while, until

    Linux干貨 2017-12-24
  • iptables的DNAT、SNAT配置

    DNAT:目的地址轉換。當外網主機訪問內網的某臺服務器的時候,如果直接暴露服務器的IP于公網,可能會遭受各種各樣的攻擊,而DNAT的主要作用就是在服務器前面添加一臺防火墻。將防火墻的地址公布出去,讓外網客戶端通過訪問防火墻的地址就可以訪問到本地服務器。這樣就起到了保護服務器的目的; SNAT:源地址轉換。內網主機在訪問互聯網的時候所有源地址都轉換為防火墻的外…

    2017-06-12
  • 分布式文件系統之fastDFS部署

    fastDFS下載地址:https://github.com/happyfish100/fastdfs部署參考文檔:http://joelhy.github.io/2015/01/27/FastDFS-v5-06-deploy/ 我們接下來來部署fastDFS 部署結構: 192.168.42.150 node1 [Tracker]192.168.42.15…

    Linux干貨 2017-06-16

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-11-02 14:22

    博客寫得非常的好,32個贊,給出了詳細操作步驟,加油!

欧美性久久久久