lamp

lamp

lamp:Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一組動態網站或者服務器的開源軟件
'Linux:操作系統
Apache:HTTP服務器
MySQL:也值MariaDB,數據庫軟件
PHP:指Perl或Python。一般用來建立web應用平臺'

web服務器的資源

靜態資源:直接存儲於文件系統中的資源
動態資源:通常是程序文件,需要在服務器執行之後,將執行的結果返回給客戶端

web服務器如何處理客戶端的請求?

'客戶端發送到服務器端的請求(request)信息,根據HTTP協議的規則拼接而成的字符串,
Request請求消息包括三部分(請求行、消息報頭、請求正文),
web服務器收到請求後,查看是否存在該請求目標,不存在則返回錯誤信息給瀏覽器,如存在,web服務器判斷是靜態還是動態,
靜態資源直接返回動態需要先查看是否存在緩存,
httpd服務器(即apache)和php服務器通過FastCGI協議進行通信,
且php作爲獨立的服務進程運行,php會解析響應的請求,
如果有查找文件圖片會請求存儲,如果有數據查詢會請求MYSQL,
在查詢數據之前會先檢查REDIS有沒有緩存,如果有則返回,
沒有則查詢數據庫,php程序和MYSQL數據庫間通過mysql協議進行通信,
php與mysql沒有什麼聯繫,
但是由PHP語言寫成的程序可以與mysql進行數據交互,
同理可證,perl和python寫的程序也可以與mysql數據庫進行交互,
查詢完畢後會緩存一份至Redis中。
最後,MYSQL查詢完畢返回對應數據,php將數據返回給HTTPd服務器,將最終的數據返回給負載均衡,負載均衡返回數據給用戶,斷開連接四次揮手。'

1.0LAMP平臺構建
需要安裝的服務:httpd-2.4 mysql-5.7 php php-mysql
操作前一定要把防火牆和selinux關閉

系統平臺 IP
Centos7/redhat7 192.168.228.21

1.1安裝httpd

'安裝開發工具包'
[root@yaoxiaorong ~]# yum groups mark install "Development Tools"
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Marked install: Development Tools
[root@yaoxiaorong ~]# yum grouplist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Installed Groups:
   Development Tools
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done
'創建apache組和用戶'
[root@yaoxiaorong ~]# groupadd -r apache
[root@yaoxiaorong ~]# useradd -r -M -s /sbin/nologin -g apache apache
[root@yaoxiaorong ~]# id apache
uid=998(apache) gid=996(apache) groups=996(apache)
'安裝依賴包'
[root@yaoxiaorong ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
'下載和安裝apr以及apr-util'
[root@yaoxiaorong src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
[root@yaoxiaorong src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.tar.bz2
'解壓下載的apr和apr-util並進行編譯三部曲'
[root@yaoxiaorong src]# ls
apr-1.6.3.tar.bz2       debug
apr-util-1.6.1.tar.bz2  kernels
[root@yaoxiaorong src]# tar xf apr-1.6.3.tar.bz2 
[root@yaoxiaorong src]# tar xf apr-util-1.6.1.tar.bz2 
[root@yaoxiaorong src]# ls
apr-1.6.3          apr-util-1.6.1          debug
apr-1.6.3.tar.bz2  apr-util-1.6.1.tar.bz2  kernels
[root@yaoxiaorong src]# cd apr-1.6.3/
[root@yaoxiaorong apr-1.6.3]# vim configure
    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    $RM "$cfgfile"  //'將此行刪除或者加上註釋'
[root@yaoxiaorong apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@yaoxiaorong apr-1.6.3]# make -j 2 && make install
[root@yaoxiaorong apr-1.6.3]# cd /usr/src/apr-util-1.6.1/
[root@yaoxiaorong apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@yaoxiaorong apr-util-1.6.1]# make -j 2 && make install
'編譯安裝httpd'
[root@yaoxiaorong ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.34.tar.bz2
--2018-08-20 19:51:43--  http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.34.tar.bz2
Resolving mirror.bit.edu.cn (mirror.bit.edu.cn)... 202.204.80.77, 2001:da8:204:2001:250:56ff:fea1:22
Connecting to mirror.bit.edu.cn (mirror.bit.edu.cn)|202.204.80.77|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://64.123.28.149/files/22030000003D43F8/mirrors.hust.edu.cn/apache//httpd/httpd-2.4.34.tar.bz2 [following]
--2018-08-20 19:51:43--  http://64.123.28.149/files/22030000003D43F8/mirrors.hust.edu.cn/apache//httpd/httpd-2.4.34.tar.bz2
Connecting to 64.123.28.149:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6942969 (6.6M) [application/octet-stream]
Saving to: ‘httpd-2.4.34.tar.bz2’

100%[=========>] 6,942,969   1.06MB/s   in 6.4s   

2018-08-20 19:51:49 (1.03 MB/s) - ‘httpd-2.4.34.tar.bz2’ saved [6942969/6942969]

[root@yaoxiaorong ~]# ls
anaconda-ks.cfg  httpd-2.4.34.tar.bz2
[root@yaoxiaorong ~]# tar xf httpd-2.4.34.tar.bz2 
[root@yaoxiaorong ~]# cd httpd-2.4.34/
[root@yaoxiaorong httpd-2.4.34]# ./configure --prefix=/usr/local/apache \
> --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
[root@yaoxiaorong httpd-2.4.34]# make -j 2 && make install
'安裝後配置'
[root@yaoxiaorong ~]# echo 'PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@yaoxiaorong ~]# source /etc/profile.d/httpd.sh 
[root@yaoxiaorong ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@yaoxiaorong ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
'取消ServerName前面的註釋'
[root@yaoxiaorong ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf 
'啓動apache'
root@yaoxiaorong ~]# apachectl start
[root@yaoxiaorong ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128    :::80                 :::*                  
LISTEN      0      128    :::22                 :::*                  
LISTEN      0      100       ::1:25                 :::*                  

安裝mysql

'安裝依賴包'
[root@yaoxiaorong ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
'創建用戶和組'
[root@yaoxiaorong ~]# groupadd -r -g 306 mysql
[root@yaoxiaorong ~]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
'下載二進制格式的mysql軟件包'
[root@yaoxiaorong ~]# cd /usr/src/
[root@yaoxiaorong src]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
'解壓軟件至/usr/local'
[root@yaoxiaorong src]# ls
apr-1.6.3
apr-1.6.3.tar.bz2
apr-util-1.6.1
apr-util-1.6.1.tar.bz2
debug
kernels
mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@yaoxiaorong src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 
[root@yaoxiaorong src]# mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/
[root@yaoxiaorong src]# cd /usr/local/
[root@yaoxiaorong local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
‘mysql’ -> ‘mysql-5.7.22-linux-glibc2.12-x86_64/’
[root@yaoxiaorong local]# ll
total 0
drwxr-xr-x. 13 root root 152 Aug 20 19:57 apache
drwxr-xr-x.  6 root root  58 Aug 20 19:47 apr
drwxr-xr-x.  5 root root  43 Aug 20 19:50 apr-util
drwxr-xr-x.  2 root root   6 Nov  5  2016 bin
drwxr-xr-x.  2 root root   6 Nov  5  2016 etc
drwxr-xr-x.  2 root root   6 Nov  5  2016 games
drwxr-xr-x.  2 root root   6 Nov  5  2016 include
drwxr-xr-x.  2 root root   6 Nov  5  2016 lib
drwxr-xr-x.  2 root root   6 Nov  5  2016 lib64
drwxr-xr-x.  2 root root   6 Nov  5  2016 libexec
lrwxrwxrwx.  1 root root  36 Aug 20 20:14 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
drwxr-xr-x.  9 root root 129 Aug 20 20:13 mysql-5.7.22-linux-glibc2.12-x86_64
drwxr-xr-x.  2 root root   6 Nov  5  2016 sbin
drwxr-xr-x.  5 root root  49 Jul 12 19:53 share
drwxr-xr-x.  2 root root   6 Nov  5  2016 src
'修改目錄/usr/local/mysql的屬主屬組'
[root@yaoxiaorong local]# chown -R mysql.mysql /usr/local/mysql
[root@yaoxiaorong local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 Aug 20 20:14 /usr/local/mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
'添加環境變量'
in      docs     lib  README  support-files
COPYING  include  man  share
[root@yaoxiaorong local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@yaoxiaorong local]# . /etc/profile.d/mysql.sh 
[root@yaoxiaorong local]# echo $PATH
/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
'建立數據存放目錄'
[root@yaoxiaorong local]# mkdir /opt/data
[root@yaoxiaorong local]# chown -R mysql.mysql /opt/data/
[root@yaoxiaorong local]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Aug 20 20:19 data
'初始化數據庫'
[root@yaoxiaorong local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data
2018-08-20T12:21:33.376646Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-20T12:21:36.188697Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-20T12:21:36.709732Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-20T12:21:36.785505Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 954d22ce-a473-11e8-a8de-000c29a70901.
2018-08-20T12:21:36.787392Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-20T12:21:36.790132Z 1 [Note] A temporary password is generated for root@localhost: +k3otRubTC7y
'配置mysql'
[root@yaoxiaorong ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[root@yaoxiaorong ~]# echo '/usr/local/mysql/lib' >/etc/ld.so.conf.d/mysql.conf
[root@yaoxiaorong ~]# ldconfig -v
'生成配置文件'
[root@yaoxiaorong ~]# cat > /etc/my.cnf <<EOF
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
'配置服務啓動腳本'
[root@yaoxiaorong ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@yaoxiaorong ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@yaoxiaorong ~]# sed -ri 's#^(datadir=).*#\1/o
pt/data#g' /etc/init.d/mysqld 
'啓動mysql'
[root@yaoxiaorong ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/yaoxiaorong.err'.
. SUCCESS! 
[root@yaoxiaorong ~]# ps -ef|grep mysql
root      51910      1  0 20:34 pts/2    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql     52088  51910  3 20:34 pts/2    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=yaoxiaorong.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root      52120  19516  0 20:34 pts/2    00:00:00 grep --color=auto mysql
[root@yaoxiaorong ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128    :::80                 :::*                  
LISTEN      0      128    :::22                 :::*                  
LISTEN      0      100       ::1:25                 :::*                  
LISTEN      0      80     :::3306               :::*                  
'修改密碼
使用臨時密碼登錄'
[root@yaoxiaorong ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
'設置新密碼'
mysql> set password = password('yaoxiaorong!');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit
Bye

安裝php

'配置yum源'
[root@yaoxiaorong ~]# cd /etc/yum.repos.d/
[root@yaoxiaorong yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2018-08-20 20:40:14--  http://mirrors.163.com/.help/CentOS7-Base-163.repo
Resolving mirrors.163.com (mirrors.163.com)... 59.111.0.251
Connecting to mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1572 (1.5K) [application/octet-stream]
Saving to: ‘CentOS7-Base-163.repo’

100%[=========>] 1,572       --.-K/s   in 0s      

2018-08-20 20:40:14 (12.7 MB/s) - ‘CentOS7-Base-163.repo’ saved [1572/1572]
[root@yaoxiaorong yum.repos.d]# ls
CentOS7-Base-163.repo  CentOS-fasttrack.repo
CentOS-Base.repo       CentOS-Media.repo
CentOS-CR.repo         CentOS-Sources.repo
CentOS-Debuginfo.repo  CentOS-Vault.repo
[root@yaoxiaorong yum.repos.d]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo 
[root@yaoxiaorong yum.repos.d]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo 
[root@yaoxiaorong yum.repos.d]# yum -y install epel-release
'安裝依賴包'
[root@yaoxiaorong yum.repos.d]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel
'下載php'
[root@yaoxiaorong src]# cd /usr/src/

[root@yaoxiaorong src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
'編譯安裝php'
[root@yaoxiaorong src]# ls
apr-1.6.3
apr-1.6.3.tar.bz2
apr-util-1.6.1
apr-util-1.6.1.tar.bz2
debug
kernels
mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
php-7.2.8.tar.xz
[root@yaoxiaorong src]# tar xf php-7.2.8.tar.xz
[root@yaoxiaorong php-7.2.8]# cd php-7.2.8/
[root@yaoxiaorong php-7.2.8]# ./configure --prefix=/usr/local/php7 \
> --with-curl \
> --with-freetype-dir \
> --with-gd \
> --with-gettext \
> --with-iconv-dir \
> --with-kerberos \
> --with-libdir=lib64 \
> --with-libxml-dir=/usr \
> --with-mysqli=/usr/local/mysql/bin/mysql_config \> --with-openssl \
> --with-pcre-regex \
> --with-pdo-mysql \
> --with-pdo-sqlite \
> --with-pear \
> --with-jpeg-dir \
> --with-png-dir \
> --with-xmlrpc \
> --with-xsl \
> --with-zlib \
> --with-config-file-path=/etc \
> --with-config-file-scan-dir=/etc/php.d \
> --with-bz2 \
> --enable-fpm \
> --enable-bcmath \
> --enable-libxml \
> --enable-inline-optimization \
> --enable-mbregex \
> --enable-mbstring \
> --enable-opcache \
> --enable-pcntl \
> --enable-shmop \
> --enable-soap \
> --enable-sockets \
> --enable-sysvsem \
> --enable-xml \
> --enable-zip
[root@yaoxiaorong php-7.2.8]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
[root@yaoxiaorong php-7.2.8]# make install
'安裝後配置'

[root@yaoxiaorong ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@yaoxiaorong ~]# source /etc/profile.d/php7.sh
[root@yaoxiaorong ~]# which php
/usr/local/php7/bin/php
[root@yaoxiaorong ~]# php -v
PHP 7.2.8 (cli) (built: Aug 21 2018 12:52:28) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
'配置php-fpm'
[root@yaoxiaorong ~]# cd /usr/src/
[root@yaoxiaorong src]# ls
apr-1.6.3
apr-1.6.3.tar.bz2
apr-util-1.6.1
apr-util-1.6.1.tar.bz2
CentOS7-Base-163.repo
debug
kernels
mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
php-7.2.8
php-7.2.8.tar.xz
[root@yaoxiaorong src]# cd php-7.2.8/
[root@yaoxiaorong php-7.2.8]# cp php.ini-production /etc/php.ini
[root@yaoxiaorong php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@yaoxiaorong php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm 
[root@yaoxiaorong php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@yaoxiaorong php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
'編輯php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf)
配置fpm的相關選項爲你所需要的值:
進入php-fpm的配置文件按G光標跳轉到最後一行添加以下內容'
[root@yaoxiaorong ~]# vim /usr/local/php7/etc/php-fpm.conf
pm.max_children = 50   '最多同時提供50個進程提供50個併發服務'
pm.start_servers = 5   '啓動時啓動5個進程'
pm.min_spare_servers = 2  '最小空閒進程數'
pm.max_spare_servers = 8   '最大空閒進程數'

[root@yaoxiaorong ~]# tail /usr/local/php7/etc/php-fpm.conf
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used. They will be prefixed by:
;  - the global prefix if it's been set (-p argument)
;  - /usr/local/php7 otherwise
include=/usr/local/php7/etc/php-fpm.d/*.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
'啓動php-fpm'
[root@yaoxiaorong ~]# service php-fpm start
Starting php-fpm  done
'默認情況下。fpm監聽在127.0.0.1的9000端口,也可以使用如下命令驗證其是否已經監聽在相應的套接字'
[root@yaoxiaorong ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128    127.0.0.1:9000                *:*                  
LISTEN      0      128    :::80                 :::*                  
LISTEN      0      128    :::22                 :::*                  
LISTEN      0      100       ::1:25                 :::*                  
LISTEN      0      80     :::3306               :::*                  
[root@yaoxiaorong ~]# ps -ef |grep php
root      72054      1  0 13:46 ?        00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody    72055  72054  0 13:46 ?        00:00:00 php-fpm: pool www
nobody    72056  72054  0 13:46 ?        00:00:00 php-fpm: pool www
nobody    72057  72054  0 13:46 ?        00:00:00 php-fpm: pool www
nobody    72058  72054  0 13:46 ?        00:00:00 php-fpm: pool www
nobody    72059  72054  0 13:46 ?        00:00:00 php-fpm: pool www
root      72062   1541  0 13:49 pts/0    00:00:00 grep --color=auto php

配置apache
啓動代理模塊,在apache httpd 2.4以後已經專門有一個模塊針對FastCGI的實現,此模塊mod_proxy_fcgi.so,它其實是作爲mod_proxy.so模塊的擴展,因此這兩個模塊都要編輯httpd.conf文件,取消以下內容的註釋:

'LoadModule proxy_module modules/mod_proxy.so
 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so'
 [root@yaoxiaorong ~]# sed -i '/proxy_module/s/#//g' /etc/httpd24/httpd.conf 
[root@yaoxiaorong ~]# sed -i '/proxy_fcgi_module/s/#//g' /etc/httpd24/httpd.conf 

**配置虛擬主機

'創建虛擬主機目錄並生成ph測試頁面'
[root@yaoxiaorong ~]# mkdir /usr/local/apache/htdocs/yxr.com
[root@yaoxiaorong ~]# cat > /usr/local/apache/htdocs/yxr.com/index.php <<EOF
> <?php
>     phpinfo();
> ?>
> EOF
[root@yaoxiaorong ~]# chown -R apache.apache /usr/l
ocal/apache/htdocs/
[root@yaoxiaorong ~]# ll /usr/local/apache/htdocs/ -d
drwxr-xr-x. 3 apache apache 39 Aug 21 13:59 /usr/local/apache/htdocs/

'在配置文件的最後加入以下內容:'
[root@yaoxiaorong ~]# vim /etc/httpd24/httpd.conf
<VirtualHost *:80>
        DocumentRoot "/usr/local/apache/htdocs/yxr.
com"
        ServerName www.yxr.com
        ProxyRequests Off
        ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.
1:9000/usr/local/apache/htdocs/yxr.com/$1
      <Directory "/usr/local/apache/htdocs/yxr.com">
        Options none
        AllowOverride none
        Require all granted
  </Directory>
</VirtualHost>
'搜索AddType  ,添加以下內容'
[root@yaoxiaorong ~]# vim /etc/httpd24/httpd.conf 

    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php  '添加此行'
    AddType application/x-httpd-php-source .phps  '添加此行'
[root@yaoxiaorong ~]# sed -i '/ DirectoryIndex/s/index.html/index.php index.html/g' /etc/httpd24/httpd.conf
'重啓apache服務'
[root@yaoxiaorong ~]# apachectl stop
[root@yaoxiaorong ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128    127.0.0.1:9000                *:*                  
LISTEN      0      128    :::22                 :::*                  
LISTEN      0      100       ::1:25                 :::*                  
LISTEN      0      80     :::3306               :::*                  
[root@yaoxiaorong ~]# apachectl start
[root@yaoxiaorong ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128    127.0.0.1:9000                *:*                  
LISTEN      0      128    :::80                 :::*                  
LISTEN      0      128    :::22                 :::*                  
LISTEN      0      100       ::1:25                 :::*                  
LISTEN      0      80     :::3306               :::*                  

驗證
'windows系統進入C:\Windows\System32\drivers\etc修改hosts文件,'
lamp
瀏覽器訪問www.yxr.com
lamp

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章