LAMP
[toc]
lamp是什么
LAMP是指一组通常一起使用来运行动态网站或者服务器的*软件名称首字母缩写:
1、Linux;操作系统;
2、Apache;网页服务器;
3、MariaDB或MySQL,数据库管理系统(或者数据库服务器);
4、PHP、Perl或Python,脚本语言;
静态网页和动态网页区别
- 静态网页是相对于动态网页而言,是指没有后台数据库、不含程序和不可交互的网页。
- 编的是什么它显示的就是什么、不会有任何改变。
- 静态网页相对更新起来比较麻烦,适用于一般更新较少的展示型网站。
- 另外,如果扩展名为.asp但却没有连数据库,完全是静态的页面,那也是静态网站.只是.asp扩展名。
- 动态网页和静态网页是有区别的,网站采用动态网页还是静态网页主要取决于网站的功能需求和网站内容的多少,如果网站功能比较简单,内容更新量不是很大,采用纯静态网页的方式会更简单,反之一般要采用动态网页技术来实现。不过现在一般的都是采用的动态网站,有内容更新的话就可以随时在后台来更新。
fastcgi跟cgi的区别
在web服务器方面 | 在对数据进行处理的进程方面 | |
---|---|---|
cgi | fork一个新的进程进行处理 | 读取参数,处理数据,然后就结束生命期 |
fastcgi | 用tcp方式跟远程机子上的进程或本地进程建立连接 | 要开启tcp端口,进入循环,等待数据的到来,处理数据 |
单主机:
apache
安装epel-release vim
[root@localhost ~]# dnf -y install epel-release vim
安装开发工具包
[root@localhost ~]# dnf -y groups mark install "Development Tools"
给apache创建用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
安装依赖包
[root@localhost ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
安装bzip2并解压
[root@localhost ~]# dnf -y install bzip2
[root@localhost ~]# tar xf apr-1.6.3.tar.bz2
[root@localhost ~]# tar xf apr-util-1.6.1.tar.bz2
[root@localhost ~]# tar xf httpd-2.4.43.tar.bz2
[root@localhost ~]# ls
anaconda-ks.cfg apr-util-1.6.1.tar.bz2
apr-1.6.3 httpd-2.4.43
apr-1.6.3.tar.bz2 httpd-2.4.43.tar.bz2
apr-util-1.6.1
修改configure
[root@localhost apr-1.6.3]# vim configure
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
安装apr
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.3]# make
[root@localhost apr-1.6.3]# make install
安装apr-utl
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make
[root@localhost apr-util-1.6.1]# make install
安装httpd
[root@localhost httpd-2.4.43]# ./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@localhost httpd-2.4.43]# make
[root@localhost httpd-2.4.43]# make install
配置httpd
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
配置帮助文档
[root@localhost ~]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/apache/man
开启并关闭防火墙
[root@localhost ~]# 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 ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
mysql
安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
创建mysql用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
解压并放到指定位置
[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# mv mysql-5.7.33-linux-glibc2.12-x86_64 /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache etc lib64 share
apr games libexec src
apr-util include mysql-5.7.33-linux-glibc2.12-x86_64
bin lib sbin
[root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
apache apr-util etc include lib64 mysql share
apr bin games lib libexec sbin src
修改权限
[root@localhost local]# chown -R mysql.mysql mysql/
[root@localhost local]# ll
total 0
drwxr-xr-x. 13 root root 152 May 12 21:50 apache
drwxr-xr-x. 6 root root 58 May 12 21:44 apr
drwxr-xr-x. 5 root root 43 May 12 21:45 apr-util
drwxr-xr-x. 2 root root 6 May 19 2020 bin
drwxr-xr-x. 2 root root 6 May 19 2020 etc
drwxr-xr-x. 2 root root 6 May 19 2020 games
drwxr-xr-x. 2 root root 6 May 19 2020 include
drwxr-xr-x. 2 root root 6 May 19 2020 lib
drwxr-xr-x. 3 root root 17 Mar 24 09:08 lib64
drwxr-xr-x. 2 root root 6 May 19 2020 libexec
drwxr-xr-x. 9 mysql mysql 129 May 12 22:08 mysql
drwxr-xr-x. 2 root root 6 May 19 2020 sbin
drwxr-xr-x. 5 root root 49 Mar 24 09:08 share
drwxr-xr-x. 2 root root 6 May 19 2020 src
添加环境变量并读取
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh
做软连接
[root@localhost local]# ln -s /usr/local/mysql/include/ /usr/include/mysql/
lib
[root@localhost local]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost local]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost local]# ldconfig
添加帮助文档
[root@localhost local]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/apache/man
MANDATORY_MANPATH /usr/local/mysql/man
创建数据库存放目录并授权
[root@localhost local]# mkdir /opt/data
[root@localhost local]# chown -R mysql.mysql /opt/data/
初始化数据库
[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
qaSU!&qXe9p3
FiE15gq,6XoE
生成配置文件
[root@localhost local]# 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@localhost local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost local]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/opt/data
登录mysql并修改密码
[root@localhost local]# 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.33
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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('hzy123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
开机启动
[root@localhost local]# chkconfig --add mysqld
[root@localhost local]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost local]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
PHP
安装依赖包
[root@localhost local]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel
安装php
[root@localhost local]# dnf -y install php*
启动php
[root@localhost local]# systemctl start php-fpm
设置开机启动
[root@localhost local]# systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
修改并重启php-fpm
[root@localhost php-fpm]# vim /etc/php-fpm.d/www.conf
;listen = /run/php-fpm/www.sock
listen = 0.0.0.0:9000
[root@localhost php-fpm]# systemctl restart php-fpm
[root@localhost php-fpm]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
修改httpd.conf
[root@localhost ~]# vim /etc/httpd24/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
创建htdocs目录
root@localhost ~]# mkdir /usr/local/apache/htdocs/hzy.com
[root@localhost ~]# cd /usr/local/apache/htdocs/hzy.com
[root@localhost hzy.com]# cd ..
[root@localhost htdocs]# ls
hzy.com index.html
创建php页面
[root@localhost htdocs]# vim index.php
[root@localhost htdocs]# cat index.php
<?php
phpinfo();
?>
[root@localhost htdocs]# mv index.php hzy.com/
[root@localhost htdocs]# ls
hzy.com index.html
[root@localhost htdocs]# cd hzy.com/
[root@localhost hzy.com]# ls
index.php
修改权限
[root@localhost htdocs]# chown -R apache.apache /usr/local/apache/htdocs/
配置虚拟主机设置
[root@localhost httpd24]# vim httpd.conf
Include /etc/httpd24/extra/vhosts.conf
[root@localhost extra]# vim vhosts.conf
[root@localhost extra]# cat vhosts.conf
lHost *:80>
DocumentRoot "/usr/local/apache/htdocs/hzy.com"
ServerName www.hzy.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://0.0.0.0:9000/usr/local/apache/htdocs/hzy.com/$1
<Directory "/usr/local/apache/htdocs/hzy.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
[root@localhost httpd24]# vim httpd.conf
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
用源码安装的apache启动
[root@localhost httpd24]# apachectl stop
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 httpd24]# /usr/local/apache/bin/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 httpd24]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
三主机
apache
安装epel-release vim
[root@localhost ~]# dnf -y install gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel make expat-devel libtool
[root@localhost ~]# dnf -y install epel-release vim
安装开发工具包
[root@localhost ~]# dnf -y groups mark install "Development Tools"
给apache创建用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
[root@localhost httpd-2.4.43]# chown -R apache.apache /usr/local/apache/
安装依赖包
[root@localhost ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
安装bzip2并解压
[root@localhost ~]# dnf -y install bzip2
[root@localhost ~]# tar xf apr-1.6.3.tar.bz2
[root@localhost ~]# tar xf apr-util-1.6.1.tar.bz2
[root@localhost ~]# tar xf httpd-2.4.43.tar.bz2
[root@localhost ~]# ls
anaconda-ks.cfg apr-util-1.6.1.tar.bz2
apr-1.6.3 httpd-2.4.43
apr-1.6.3.tar.bz2 httpd-2.4.43.tar.bz2
apr-util-1.6.1
修改configure
[root@localhost apr-1.6.3]# vim configure
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
安装apr
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.3]# make
[root@localhost apr-1.6.3]# make install
安装apr-utl
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make
[root@localhost apr-util-1.6.1]# make install
安装httpd
[root@localhost httpd-2.4.43]# ./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@localhost httpd-2.4.43]# make
[root@localhost httpd-2.4.43]# make install
配置httpd
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
配置帮助文档
[root@localhost ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
取消ServerName的注释
[root@localhost ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
写apache的service文件
[root@localhost extra]# cat /etc/systemd/system/httpd.service
Description=Start httpd
[Service]
Type=simple
EnvironmentFile=/etc/httpd24/httpd.conf
ExecStart=/usr/local/apache/bin/httpd -k start -DFOREGROUND
ExecReload=/usr/local/apache/bin/httpd -k graceful
ExecStop=/bin/kill -WINCH
[Install]
WantedBy=multi-user.target
开启并关闭防火墙
[root@localhost ~]# 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 ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
mysql
安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
创建mysql用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
解压并放到指定位置
[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# mv mysql-5.7.33-linux-glibc2.12-x86_64 /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache etc lib64 share
apr games libexec src
apr-util include mysql-5.7.33-linux-glibc2.12-x86_64
bin lib sbin
[root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
apache apr-util etc include lib64 mysql share
apr bin games lib libexec sbin src
修改权限
[root@localhost local]# chown -R mysql.mysql mysql/
[root@localhost local]# ll
total 0
drwxr-xr-x. 13 root root 152 May 12 21:50 apache
drwxr-xr-x. 6 root root 58 May 12 21:44 apr
drwxr-xr-x. 5 root root 43 May 12 21:45 apr-util
drwxr-xr-x. 2 root root 6 May 19 2020 bin
drwxr-xr-x. 2 root root 6 May 19 2020 etc
drwxr-xr-x. 2 root root 6 May 19 2020 games
drwxr-xr-x. 2 root root 6 May 19 2020 include
drwxr-xr-x. 2 root root 6 May 19 2020 lib
drwxr-xr-x. 3 root root 17 Mar 24 09:08 lib64
drwxr-xr-x. 2 root root 6 May 19 2020 libexec
drwxr-xr-x. 9 mysql mysql 129 May 12 22:08 mysql
drwxr-xr-x. 2 root root 6 May 19 2020 sbin
drwxr-xr-x. 5 root root 49 Mar 24 09:08 share
drwxr-xr-x. 2 root root 6 May 19 2020 src
添加环境变量并读取
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh
做软连接
[root@localhost local]# ln -s /usr/local/mysql/include/ /usr/include/mysql/
lib
[root@localhost local]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost local]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost local]# ldconfig
添加帮助文档
[root@localhost local]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/apache/man
MANDATORY_MANPATH /usr/local/mysql/man
创建数据库存放目录并授权
[root@localhost local]# mkdir /opt/data
[root@localhost local]# chown -R mysql.mysql /opt/data/
初始化数据库
[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
qaSU!&qXe9p3
FiE15gq,6XoE
生成配置文件
[root@localhost local]# 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@localhost local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost local]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/opt/data
登录mysql并修改密码
[root@localhost local]# 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.33
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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('hzy123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
开机启动
[root@localhost local]# chkconfig --add mysqld
[root@localhost local]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost local]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
PHP
安装依赖包
[root@localhost local]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel
安装php
[root@localhost local]# dnf -y install php*
启动php
[root@localhost local]# systemctl start php-fpm
设置开机启动
[root@localhost local]# systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
修改并重启php-fpm
[root@localhost php-fpm]# vim /etc/php-fpm.d/www.conf
;listen = /run/php-fpm/www.sock
listen = 0.0.0.0:9000
[root@localhost php-fpm]# systemctl restart php-fpm
[root@localhost php-fpm]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
修改httpd.conf
[root@localhost ~]# vim /etc/httpd24/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
创建htdocs目录
root@localhost ~]# mkdir /usr/local/apache/htdocs/hzy.com
[root@localhost ~]# cd /usr/local/apache/htdocs/hzy.com
[root@localhost hzy.com]# cd ..
[root@localhost htdocs]# ls
hzy.com index.html
创建php页面
[root@localhost htdocs]# vim index.php
[root@localhost htdocs]# cat index.php
<?php
phpinfo();
?>
[root@localhost htdocs]# mv index.php hzy.com/
[root@localhost htdocs]# ls
hzy.com index.html
[root@localhost htdocs]# cd hzy.com/
[root@localhost hzy.com]# ls
index.php
修改权限
[root@localhost htdocs]# chown -R apache.apache /usr/local/apache/htdocs/
配置虚拟主机设置
[root@localhost httpd24]# vim httpd.conf
Include /etc/httpd24/extra/vhosts.conf
[root@localhost extra]# vim vhosts.conf
[root@localhost extra]# cat vhosts.conf
lHost *:80>
DocumentRoot "/usr/local/apache/htdocs/hzy.com"
ServerName www.hzy.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://0.0.0.0:9000/usr/local/apache/htdocs/hzy.com/$1
<Directory "/usr/local/apache/htdocs/hzy.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
[root@localhost httpd24]# vim httpd.conf
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
用源码安装的apache启动
[root@localhost httpd24]# apachectl stop
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 httpd24]# /usr/local/apache/bin/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 httpd24]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*