lamp搭建部署詳細分解
1.lamp簡介
所謂lamp,其實就是由Linux+Apache+Mysql/MariaDB+Php/Python的一組動態網站或服務器的開源軟件,除Linux外其他各部件本身都是各自獨立的程序,但是因為經常被放在一起使用,擁有了越來越高的兼容度,共同組成了一個強大的Web應用程序平臺。
LAMP指的是Linux(操作系統)、Apache(HTTP服務器)、MySQL(也指MariaDB,數據庫軟件)和PHP(有時也是指Perl或Python)的第一個字母,一般用來建立web應用平臺。
##2.web服務器工作流程
在說lamp架構平臺的搭建前,我們先來了解下什麽是CGI,什麽是FastCGI,什麽是....
web服務器的資源分為兩種,靜態資源和動態資源
- 靜態資源就是指靜態內容,客戶端從服務器獲得的資源的表現形式與原文件相同。可以簡單的理解為就是直接存儲於文件系統的資源
- 動態資源則通常是程序文件,需要在服務器執行之後,將執行的結果返回給客戶端
那麽web服務器如何執行程序並將結果返回給客戶端呢?下面通過一張圖來說明一下web服務器如何處
如圖所示:
階段1顯示的是httpd服務器(即apache)和php服務器通過FastCGI協議進行通信,且php為獨立的服務進程運行
階段2顯示的是php程序和mysql數據庫間通過mysql協議進行通信,php與mysql本沒有什麽聯系,但是由Php語言寫成的程序可以與mysql進行數據交互。同理perl和Python寫的程序也可以與mysql數據庫進行交互
上圖階段1中提到了FastCGl,下面我們來了解下CGI與FastCGI
CGI(Common Gateway Interface,通用網關接口),CGI是外部應用程序(CGI程序)與WEB服務器之間的接口標準,是在CGI程序與Web服務器之間傳遞信息的過程,CGI規範允許Web服務器執行外部程序,並將它們的輸出發送給Web瀏覽器,CGI將web的一組簡單的靜態超媒體文檔變成一個完整的新的交互式媒體。
FastCGI(Fast Common Gateway Interface)是CGI的改良版,CGI是通過啟用一個解釋器進程來處理每個請求,耗時且耗資源,而FastCGI則是通過master-worker形式來處理每個請求,即啟動一個master主進程,然後根據配置啟動幾個worker進程,當請求進來時,master會從worker進程中選擇一個去處理請求,這樣就避免了重復的生成和殺死進程帶來的頻繁Cpu上下文切換而導致耗時。
2.2 httpd與php結合的方式
httpd與php結合的方式有以下三種:
-
modules :php將以httpd的擴展塊形式存在,需要加載動態資源時,httpd可以直接通過php模塊來加工資源並返回給客戶端
- httpd prefork:libphp5.so(多進程模型的php)
- httpd event or worker :libphp-zts.so(線程模型的php)
- CGI:httpd需要加載動態資源時,通過CGI與php解釋器聯系,獲取php執行的結果,此時httpd負責與php連接的建立和斷開等
-
FastCGI:利用php-fpm機制,啟動為服務進程,php自行運行為一個服務,https通過socket與php通信
#####較於CGI方式,FastCGI更為常用,很少有人使用CGI方式來加載動態資源
###2.3web工作流程
通過上面的圖說明一下web的工作流程: - 客戶端通過http協議請求web服務器資源
-
web服務器收到請求後判斷客戶端請求的資源是靜態資源或動態資源
- 若為靜態資源則直接從本地文件系統取值返回給客戶端。
- 否則若為動態資源則通過FastCGI協議與php服務器聯系,通過CGI程序的master進程調度worker進程來執行程序以獲得客戶端請求的動態資源,並將執行的結果通過FastCGI協議返回給httpd服務器,http服務器收到php的執行結果後將其封裝為http響應報文響應給客戶端。在執行程序獲取動態資源時若需要獲取數據庫中的資源時,由Php服務器通過mysql協議與MYSQL/MariaDB服務器交互,取值而後返回給httpd,httpd將從php服務器收到的執行結果封裝成http響應報文響應給客戶端。
3.lamp平臺構建
環境說明
系統平臺 | IP | 需要安裝的服務 |
---|---|---|
centos7/redhat7 | 192.168.24.168 | http-2.4 mysql-5.7 php php-mysql |
lamp平臺軟件安裝次序
httpd->mysql->php
註意:php要求httpd使用prefork MPM
3.1 安裝httpd
關閉防火墻和SELINUX
[root@linfan ~]# systemctl stop firewalld
[root@linfan ~]# systemctl disable firewalld
[root@linfan ~]# sed -ri ‘s/(SELINUX=).*/\1disabled/g‘ /etc/selinux/config
[root@linfan ~]# setenforce 0
安裝開發工具包
[root@linfan ~]# 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
Marked install: Development Tools
[root@linfan ~]# yum grouplist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
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@linfan ~]# groupadd -r apache
[root@linfan ~]# useradd -r -M -s /sbin/nologin -g apache apache
安裝依賴包
[root@linfan ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
下載和安裝apr以及apr-util
[root@linfan ~]# cd /usr/src/
[root@linfan src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.tar.bz2
[root@linfan src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
[root@linfan src]# ls
apr-1.6.3.tar.bz2 apr-util-1.6.1.tar.bz2 debug kernels
[root@linfan src]# tar xf apr-1.6.3.tar.bz2
[root@linfan src]# tar xf apr-util-1.6.1.tar.bz2
[root@linfan 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
[root@linfan src]# cd apr-1.6.3
[root@linfan apr-1.6.3]# vi configure
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
$RM "$cfgfile" //將此行加上註釋或刪除此行
root@linfan apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@linfan apr-1.6.3]# make -j && make install
[root@linfan apr-util-1.6.1]# cd /usr/src/apr-util-1.6.1
[root@linfan apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@linfan apr-util-1.6.1]# make -j && make install
編譯安裝httpd
[root@linfan ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.34.tar.bz2
[root@linfan ~]# ls
[root@linfan ~]# tar xf httpd-2.4.34.tar.bz2
[root@linfan ~]# cd httpd-2.4.34
[root@linfan httpd-2.4.34]# ./configure --prefix=/usr/local/apache \ //網站發布存放的目錄
> --sysconfdir=/etc/httpd24 \ //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@linfan ~]# make -j && make install
安裝後配置
[root@linfan ~]# echo ‘PATH=/usr/local/apache/bin:$PATH‘ > /etc/profile.d/httpd.sh
[root@linfan ~]# source /etc/profile.d/httpd.sh
[root@linfan ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@linfan ~]# echo ‘MANPATH /usr/local/apache/man‘ >> /etc/man.config
取消 ServerName前面的註釋
[root@linfan ~]# sed -i ‘/#ServerName/s/#//g‘ /etc/httpd24/httpd.conf
啟動apache
[root@linfan ~]# apachectl start
[root@linfan ~]# 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 :::*
3.2 安裝mysql
安裝依賴包
[root@linfan ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
創建用戶和組
[root@linfan ~]# groupadd -r -g 306 mysql
[root@linfan ~]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
下載二進制格式的mysql軟件包
[root@linfan ~]# cd /usr/src/
[root@linfan src]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
解壓軟件至/usr/local/
[root@linfan src]# ls
apr-1.6.3 apr-util-1.6.1 debug mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
apr-1.6.3.tar.bz2 apr-util-1.6.1.tar.bz2 kernels
[root@linfan src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@linfan src]# ls /usr/local/
apache apr-util etc include lib64 mysql-5.7.22-linux-glibc2.12-x86_64 share
apr bin games lib libexec sbin src
[root@linfan src]# cd /usr/local/
[root@linfan local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
‘mysql’ -> ‘mysql-5.7.22-linux-glibc2.12-x86_64/’
[root@linfan local]# ll
total 0
drwxr-xr-x. 13 root root 152 Aug 17 12:46 apache
drwxr-xr-x. 6 root root 58 Aug 17 12:35 apr
drwxr-xr-x. 5 root root 43 Aug 17 12:40 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 17 13:54 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 Aug 17 13:30 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 11 15:44 share
drwxr-xr-x. 2 root root 6 Nov 5 2016 src
修改目錄/usr/locaal/mysql的屬主屬組
[root@linfan ~]# chown -R mysql.mysql /usr/local/mysql
[root@linfan ~]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 Aug 17 13:54 /usr/local/mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
添加環境變量
[root@linfan ~]# ls /usr/local/mysql
bin COPYING docs include lib man README share support-files
[root@linfan ~]# echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
[root@linfan ~]# . /etc/profile.d/mysql.sh
[root@linfan ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
建立數據存放目錄
[root@linfan ~]# cd /usr/local/mysql
[root@linfan mysql]# mkdir /opt/data
[root@linfan mysql]# chown -R mysql.mysql /opt/data/
[root@linfan mysql]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Aug 17 14:05 data
drwxr-xr-x. 8 root root 220 Jul 18 17:09 lin.d
初始化數據庫
[root@linfan mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2018-08-17T06:08:33.347313Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-17T06:08:33.873415Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-17T06:08:33.953310Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-17T06:08:34.016549Z 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: f8e46285-a1e3-11e8-b6bf-000c29c9d4ed.
2018-08-17T06:08:34.019542Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2018-08-17T06:08:34.023380Z 1 [Note] A temporary password is generated for root@localhost: B<HiGFoc.8yZ
//這個命令的最後會生成一個臨時密碼,此處密碼是B<HiGFoc.8yZ
配置mysql
[root@linfan ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[root@linfan ~]# echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf
[root@linfan ~]# ldconfig -v
生成配置文件
[root@linfan ~]# 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@linfan ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@linfan ~]# sed -ri ‘s#^(basedir=).*#\1/usr/local/mysql#g‘ /etc/init.d/mysqld
[root@linfan ~]# sed -ri ‘s#^(datadir=).*#\1/opt/data#g‘ /etc/init.d/mysqld
啟動mysql
[root@linfan ~]# service mysqld start
Starting MySQL.Logging to ‘/opt/data/linfan.err‘.
SUCCESS!
[root@linfan ~]# ps -ef|grep mysql
root 52200 1 0 14:25 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql 52378 52200 4 14:25 pts/1 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=linfan.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root 52408 2998 0 14:25 pts/1 00:00:00 grep --color=auto mysql
[root@linfan ~]# 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@linfan ~]# 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> set password = password(‘linfan123‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
3.3 安裝php
配置yum源
[root@linfan ~]# cd /etc/yum.repos.d/
[root@linfan yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@linfan yum.repos.d]# sed -i ‘s/\$releasever/7/g‘ /etc/yum.repos.d/CentOS7-Base-163.repo
[root@linfan yum.repos.d]# sed -i ‘s/^enabled=.*/enabled=1/g‘ /etc/yum.repos.d/CentOS7-Base-163.repo
[root@linfan yum.repos.d]# yum -y install epel-release
安裝依賴包
[root@linfan ~]# 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@linfan ~]# cd /usr/src/
[root@linfan src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
編譯安裝php
[root@linfan ~]#ls
[root@linfan ~]#tar xf php-7.2.8.tar.xz
[root@linfan ~]#cd php-7.2.8
[root@linfan 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-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
[root@linfan php-7.2.8]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
[root@linfan php-7.2.8]# make install
安裝後配置
[root@linfan ~]# echo ‘export PATH=/usr/local/php7/bin:$PATH‘ > /etc/profile.d/php7.sh
[root@linfan ~]# source /etc/profile.d/php7.sh
[root@linfan ~]# which php
/usr/local/php7/bin/php
[root@linfan ~]# php -v
PHP 7.2.8 (cli) (built: Aug 17 2018 16:27:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
配置php-fpm
[root@linfan php-7.2.8]# cp php.ini-production /etc/php.ini
[root@linfan php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@linfan php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[root@linfan php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@linfan 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的相關選項為你所需要的值:
[root@linfan ~]# vi /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@linfan ~]# 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@linfan ~]# service php-fpm start
Starting php-fpm done
[root@linfan ~]# 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@linfan ~]# ps -ef|grep php
root 91842 1 0 16:41 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody 91843 91842 0 16:41 ? 00:00:00 php-fpm: pool www
nobody 91844 91842 0 16:41 ? 00:00:00 php-fpm: pool www
nobody 91845 91842 0 16:41 ? 00:00:00 php-fpm: pool www
nobody 91846 91842 0 16:41 ? 00:00:00 php-fpm: pool www
nobody 91847 91842 0 16:41 ? 00:00:00 php-fpm: pool www
root 91850 75645 0 16:41 pts/2 00:00:00 grep --color=auto php
3.4配置apache
3.4.1 啟用代理模塊
在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
啟用httpd的相關模塊
[root@linfan ~]# sed -i ‘/proxy_module/s/#//g‘ /etc/httpd24/httpd.conf
[root@linfan ~]# sed -i ‘/proxy_fcgi_module/s/#//g‘ /etc/httpd24/httpd.conf
3.4.2配置虛擬主機
在需要使用fcgi的虛擬主機中添加類似如下兩行
ProxyRequests Off //關閉正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
例如
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/idfsoft.com/
$1
在配置文件的最後加入以下內容
[root@linfan ~]# vim /etc/httpd24/httpd.conf
<VirtualHost 192.168.24.168:80>
ServerName www.doudou.com
DocumentRoot "/usr/local/apache/htdocs/doudou.com"
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdo
cs/doudou.com/$1
<Directory "/usr/local/apache/htdocs/doudou.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
搜索AddType,添加以下內容
[root@linfan ~]# 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@linfan ~]# sed -i ‘/ DirectoryIndex/s/index.html/index.php index.html/g‘ /etc/httpd24/httpd.conf
創建虛擬主機目錄並生成php測試頁面
[root@linfan ~]# mkdir /usr/local/apache/htdocs/doudou.com
[root@linfan ~]# cat > /usr/local/apache/htdocs/wangqing.com/index.php <<EOF
<?php
phpinfo();
?>
EOF
[root@linfan ~]# chown -R apache.apache /usr/local/apache/htdocs/
[root@linfan ~]# ll /usr/local/apache/htdocs/ -d
drwxr-xr-x. 3 apache apache 42 Aug 17 17:35 /usr/local/apache/htdocs/
重啟apache服務
[root@linfan ~]# apachectl stop
[root@linfan ~]# 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@linfan ~]# apachectl start
[root@linfan ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
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 :::*
3.5 驗證
1.修改/etc/hosts文件,添加域名與IP的映射
2.在瀏覽器上使用域名訪問,如圖所示,實驗成功
lamp搭建部署詳細分解