1. 安装httpd服务器
1.1 下载源码包
$ rpm -qa | grep httpd
$ yum install gcc gcc-c++ gcc-gfortran make pcre-devel apr-util-devel pkgconfig -y
$ wget -c https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.46.tar.bz2
$ sha256sum httpd-2.4.46.tar.bz2
740eddf6e1c641992b22359cabc66e6325868c3c5e2e3f98faf349b61ecf41ea httpd-2.4.46.tar.bz2
1.2 编译安装
$ yum install bzip2 -y
$ tar jxvf httpd-2.4.46.tar.bz2 -C /usr/src/
$ cd /usr/src/httpd-2.4.46/
$ ./configure --prefix= /usr/local/httpd --enable-so --enable-cgi --enable-rewrite --enable-mpms-shared= all --enable-charset-lite
$ make
$ make install
$ ls -l /usr/local/httpd/
total 36
drwxr-xr-x 2 root root 262 Mar 5 05:37 bin
drwxr-xr-x 2 root root 167 Mar 5 05:37 build
drwxr-xr-x 2 root root 78 Mar 5 05:37 cgi-bin
drwxr-xr-x 4 root root 84 Mar 5 05:37 conf
drwxr-xr-x 3 root root 4096 Mar 5 05:37 error
drwxr-xr-x 2 root root 24 Mar 5 05:37 htdocs
drwxr-xr-x 3 root root 8192 Mar 5 05:37 icons
drwxr-xr-x 2 root root 4096 Mar 5 05:37 include
drwxr-xr-x 2 root root 6 Mar 5 05:37 logs
drwxr-xr-x 4 root root 30 Mar 5 05:37 man
drwxr-xr-x 14 root root 8192 Mar 5 05:37 manual
drwxr-xr-x 2 root root 4096 Mar 5 05:37 modules
1.3 优化执行路径
$ ln -s /usr/local/httpd/bin/* /usr/local/bin/
$ ls -l /usr/local/bin/httpd /usr/local/bin/apachectl
lrwxrwxrwx 1 root root 30 Mar 5 05:39 /usr/local/bin/apachectl -> /usr/local/httpd/bin/apachectl
lrwxrwxrwx 1 root root 26 Mar 5 05:39 /usr/local/bin/httpd -> /usr/local/httpd/bin/httpd
$ httpd -v
Server version: Apache/2.4.46 ( Unix)
Server built: Mar 5 2021 05:34:19
1.4 配置启动脚本
$ vim /usr/lib/systemd/system/httpd.service
[ Unit]
Description= The Apache HTTP Server
After= network.target
[ Service]
Type= forking
PIDFile= /usr/local/httpd/logs/httpd.pid
ExecStart= /usr/local/bin/apachectl start
ExecReload= /bin/kill -HUP $MAINPID
[ Install]
WantedBy= multi-user.target
$ systemctl daemon-reload
$ systemctl enable httpd
$ systemctl start httpd
$ netstat -atnp | grep 80
tcp 0 0 192.168.101.230:41384 221.194.161.238:80 TIME_WAIT -
tcp6 0 0 :::80 :::* LISTEN 19404/httpd
1.5 测试
$ systemctl stop firewalld
$ systemctl disable firewalld
$ curl 192.168.101.101
< html> < body> < h1> It works! < /h1> < /body> < /html>
2. 基于域名的虚拟主机
2.1 修改hosts文件
$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.101.101 www.cisco.com
192.168.101.101 www.huawei.com
2.2 创建虚拟主机网页文档
$ cd /usr/local/httpd/htdocs/
$ mkdir cisco
$ mkdir huawei
$ vi cisco/index.html
< html>
< head>
< title> cisco< /title>
< /head>
< body>
< h1> www.cisco.com< /h1>
< /body>
< /html>
$ vim huawei/index.html
< html>
< head>
< title> huawei< /title>
< /head>
< body>
< p> www.huawei.com< /p>
< /body>
< /html>
2.3 添加虚拟主机配置
$ vim /usr/local/httpd/conf/httpd.conf
Include conf/extra/httpd-vhosts.conf
$ vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
< VirtualHost *:80>
DocumentRoot "/usr/local/httpd/htdocs/cisco"
ServerName www.cisco.com
ErrorLog "logs/www.cisco.com-error_log"
CustomLog "logs/www.cisco.com-access_log" common
< Directory '/usr/local/httpd/htdocs/cisco' >
Require all granted
< /Directory>
< /VirtualHost>
< VirtualHost *:80>
DocumentRoot "/usr/local/httpd/htdocs/huawei"
ServerName www.huawei.com
ErrorLog "logs/www.huawei.com-error_log"
CustomLog "logs/www.huawei.com-access_log" common
< Directory '/usr/local/httpd/htdocs/huawei' >
Require all granted
< /Directory>
< /VirtualHost>
$ apachectl -t
Syntax OK
$ systemctl restart httpd.service
2.4 测试
$ curl www.cisco.com
< html>
< head>
< title> cisco< /title>
< /head>
< body>
< h1> www.cisco.com< /h1>
< /body>
< /html>
$ curl http://www.huawei.com/
< html>
< head>
< title> huawei< /title>
< /head>
< body>
< p> www.huawei.com< /p>
< /body>
< /html>
3. 安装MySQL
$ yum install -y lrzsz
$ mkdir mysql
$ cd mysql/
$ ll
total 859720
-rw-r--r--. 1 root root 880353280 Jan 13 05:42 mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar
$ rpm -qa | grep mysql
$ rpm -qa | grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
$ rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
$ rpm -qa | grep mariadb
$ tar xvf mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar
$ ls
mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar mysql-community-devel-8.0.22-1.el7.x86_64.rpm mysql-community-server-8.0.22-1.el7.x86_64.rpm
mysql-community-client-8.0.22-1.el7.x86_64.rpm mysql-community-embedded-compat-8.0.22-1.el7.x86_64.rpm mysql-community-test-8.0.22-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm mysql-community-libs-8.0.22-1.el7.x86_64.rpm
mysql-community-common-8.0.22-1.el7.x86_64.rpm mysql-community-libs-compat-8.0.22-1.el7.x86_64.rpm
$ rpm -ivh mysql-community-common-8.0.22-1.el7.x86_64.rpm
$ rpm -ivh mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm
$ rpm -ivh mysql-community-libs-8.0.22-1.el7.x86_64.rpm
$ rpm -ivh mysql-community-client-8.0.22-1.el7.x86_64.rpm
$ rpm -ivh mysql-community-server-8.0.22-1.el7.x86_64.rpm --force --nodeps
$ systemctl restart mysqld
$ systemctl enable mysqld
$ grep 'password' /var/log/mysqld.log
2021-02-01T03:48:01.176651Z 6 [ Note] [ MY-010454] [ Server] A temporary password is generated for root@localhost: QzgXw7QW36*O
[ root@slave01 mysql]
> alter user 'root' @'localhost' identified by 'Ytl@2032734117' ;
Query OK, 0 rows affected ( 0.00 sec)
$ mysql -uroot -pYtl@2032734117
Server version: 8.0.22 MySQL Community Server - GPL
> create user 'root' @'%' identified with mysql_native_password by 'Ytl@2032734117' ;
Query OK, 0 rows affected ( 0.04 sec)
> grant all on *.* to 'root' @'%' ;
Query OK, 0 rows affected ( 0.01 sec)
4. PHP安装
4.1 安装php7YUM源
$ rpm -ivh mysql-community-libs-compat-8.0.22-1.el7.x86_64.rpm
warning: mysql-community-libs-compat-8.0.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing.. .
Updating / installing.. .
1:mysql-community-libs-compat-8.0.2
$ yum install epel-release -y
$ rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
4.2 安装PHP7.2
$ yum install php72w php72w-cli php72w-common php72w-gd php72w-ldap php72w-mbstring php72w-mysql php72w-mcrypt php72w-pdo php72w-opcache
4.3 复制php模块
$ find / -name '*php*.so'
/usr/lib64/httpd/modules/libphp7-zts.so
/usr/lib64/httpd/modules/libphp7.so
$ cp /usr/lib64/httpd/modules/libphp7-zts.so /usr/local/httpd/modules/
$ cp /usr/lib64/httpd/modules/libphp7.so /usr/local/httpd/modules/
$ ll /usr/local/httpd/modules/ | grep php7
-rwxr-xr-x 1 root root 5132912 Mar 5 06:50 libphp7.so
-rwxr-xr-x 1 root root 5338848 Mar 5 06:50 libphp7-zts.so
4.4 修改Apache配置主配置文件
$ vim /usr/local/httpd/conf/httpd.conf
LoadModule php7_module modules/libphp7.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
LoadModule authn_file_module modules/mod_authn_file.so
Include conf/extra/httpd-mpm.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
< IfModule dir_module>
DirectoryIndex index.html index.php
< /IfModule>
$ systemctl restart httpd
4.5 创建测试文件
$ vim /usr/local/httpd/htdocs/cisco/test.php
< ?php
phpinfo( ) ;
$ curl www.cisco.com/test.php
4.6 创建管理员账号
$ create user 'dbadmin' @'%' identified with mysql_native_password by '123456Abc!' ;
Query OK, 0 rows affected ( 0.04 sec)
mysql> grant all on *.* to 'dbadmin' @'%' ;
Query OK, 0 rows affected ( 0.01 sec)
4.7 修改PHP的配置文件
$ vim /etc/php.ini
mysqli.default_socket = /var/lib/mysql/mysql.sock
4.8 创建测试文件
$ vim /usr/local/httpd/htdocs/cisco/mysqltest.php
< ?PHP
$conn = mysqli_connect( "localhost" ,"dbadmin" ,"123456Abc!" ) ;
if( $conn ) {
echo "ok" ;
} else{
echo "error" ;
}
?>
$ systemctl restart httpd
$ curl www.cisco.com/mysqltest.php
ok
5. 安装phpMyAdmin
$ wget https://files.phpmyadmin.net/phpMyAdmin/5.1.0/phpMyAdmin-5.1.0-all-languages.zip
$ unzip phpMyAdmin-5.1.0-all-languages.zip
$ mv phpMyAdmin-5.1.0-all-languages /usr/local/httpd/htdocs/
$ cd /usr/local/httpd/htdocs/
$ mv phpMyAdmin-5.1.0-all-languages phpmyadmin
$ cp config.sample.inc.php config.inc.php
$ vim config.inc.php
cfg[ 'blowfish_secret' ] = 'ytl' ; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */