环境:操作系统:CentOS 7.6 64位
一、准备工作
1、查看系统版本
cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
2、查看防火墙状态
systemctl status firewalld
[root@iZbp1c1dto65uh7clwak1qZ ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
如果防火墙的状态参数是inactive,则防火墙为关闭状态。
如果防火墙的状态参数是active,则防火墙为开启状态。本示例中防火墙为开启状态,因此需要关闭防火墙。
3、关闭防火墙
● 如果您想临时关闭防火墙,运行命令systemctl stop firewalld
。
说明: 这只是暂时关闭防火墙,下次重启Linux后,防火墙还会开启。
● 如果您想永久关闭防火墙,运行命令systemctl disable firewall
4、查看SELinux状态
运行getenforce
命令查看SELinux的当前状态
[root@iZbp1c1dto65uh7clwak1qZ ~]# getenforce
Disabled
● 如果SELinux状态参数是Disabled, 则SELinux为关闭状态。
● 如果SELinux状态参数是Enforcing,则SELinux为开启状态。本示例中SELinux为开启状态,因此需要关闭SELinux。
5、关闭SELinux
如果SELinux为关闭状态,请忽略此步骤。
● 如果您想临时关闭SELinux,运行命令setenforce 0
。
说明: 这只是暂时关闭SELinux,下次重启Linux后,SELinux还会开启。
● 如果您想永久关闭SELinux,运行命令vi /etc/selinux/config
编辑SELinux配置文件。回车后,把光标移动到SELINUX=enforcing
这一行,按i键,将其修改为SELINUX=disabled
, 按Esc键,然后输入:wq
并回车以保存并关闭SELinux配置文件。 最后重启系统使设置生效。
6、更新系统
$ yum -y update:升级所有bai包同时也升级软件和系统内核;
$ yum -y upgrade:只升级所有包,不升级软件和系统内核。
二、安装Apache
1、安装apache
yum -y install httpd httpd-manual mod_ssl mod_perl mod_auth_mysql
.
.
.
perl-BSD-Resource.x86_64 0:1.29.07-1.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-ExtUtils-Install.noarch 0:1.58-299.el7_9
perl-ExtUtils-MakeMaker.noarch 0:6.68-3.el7 perl-ExtUtils-Manifest.noarch 0:1.61-244.el7 perl-ExtUtils-ParseXS.noarch 1:3.18-3.el7
perl-Linux-Pid.x86_64 0:0.04-18.el7 perl-Test-Harness.noarch 0:3.28-3.el7 perl-devel.x86_64 4:5.16.3-299.el7_9
pyparsing.noarch 0:1.5.6-9.el7 systemtap-sdt-devel.x86_64 0:4.0-13.el7
Complete!
运行httpd -v
命令可查看Apache的版本号。
2、启动apache服务
systemctl start httpd
3、设置httpd服务开机启动
systemctl enable httpd
[root@iZbp1c1dto65uh7clwak1qZ ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
4、查看服务状态
systemctl status httpd
[root@iZbp1c1dto65uh7clwak1qZ ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2021-02-07 16:38:44 CST; 30s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 31987 (/usr/sbin/httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─31987 /usr/sbin/httpd -DFOREGROUND
├─31988 /usr/sbin/httpd -DFOREGROUND
├─31989 /usr/sbin/httpd -DFOREGROUND
├─31990 /usr/sbin/httpd -DFOREGROUND
├─31991 /usr/sbin/httpd -DFOREGROUND
└─31992 /usr/sbin/httpd -DFOREGROUND
Feb 07 16:38:44 iZbp1c1dto65uh7clwak1qZ systemd[1]: Starting The Apache HTTP Server...
Feb 07 16:38:44 iZbp1c1dto65uh7clwak1qZ httpd[31987]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name...message
Feb 07 16:38:44 iZbp1c1dto65uh7clwak1qZ systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
5、防火墙设置开启80端口
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
6、确认80端口监听中
netstat -tulp
[root@iZbp1c1dto65uh7clwak1qZ ~]# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:http 0.0.0.0:* LISTEN 31987/httpd
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN 21510/sshd
tcp 0 0 0.0.0.0:https 0.0.0.0:* LISTEN 31987/httpd
udp 0 0 0.0.0.0:bootpc 0.0.0.0:* 751/dhclient
udp 0 0 localhost:323 0.0.0.0:* 21730/chronyd
udp6 0 0 localhost:323 [::]:* 21730/chronyd
7、浏览器访问查看
在本地机器的浏览器地址栏中,输入http://实例公网IP
并按Enter键
出现Test123ing
等Apache信息即表示成功安装Apache
三、安装并配置MySQL
1、运行以下命令更新YUM源
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
[root@iZbp1c1dto65uh7clwak1qZ ~]# rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
Retrieving http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
warning: /var/tmp/rpm-tmp.lXOikI: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-9 ################################# [100%]
说明 如果您使用的操作系统内核版本为el8,可能会提示报错信息No match for argument。您需要先运行命令yum module disable mysql禁用默认的mysql模块,再安装MySQL。
2、运行以下命令安装MySQL
yum -y install mysql-community-server
.
.
.
Verifying : libaio-0.3.109-13.el7.x86_64 6/7
Verifying : 1:mariadb-libs-5.5.68-1.el7.x86_64 7/7
Installed:
mysql-community-libs.x86_64 0:5.7.33-1.el7 mysql-community-libs-compat.x86_64 0:5.7.33-1.el7 mysql-community-server.x86_64 0:5.7.33-1.el7
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7 mysql-community-client.x86_64 0:5.7.33-1.el7 mysql-community-common.x86_64 0:5.7.33-1.el7
Replaced:
mariadb-libs.x86_64 1:5.5.68-1.el7
Complete!
3、运行以下命令查看 MySQL 版本号
mysql -V
返回版本号信息,表示MySQL安装成功
4、运行以下命令启动MySQL
systemctl start mysqld
5、运行以下命令设置开机启动 MySQL
systemctl enable mysqld
systemctl daemon-reload
6、运行以下命令查看 MySQL 的初始密码
grep "password" /var/log/mysqld.log
返回结果末尾冒号后面位初始密码
7、运行以下命令配置 MySQL 的安全性
mysql_secure_installation
7.1 重置root账号的密码
Enter password for user root: #输入上一步获取的root用户初始密码
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? (Press y|Y for Yes, any other key for No) : Y #是否更改root用户密码,输入Y
New password: #输入新密码,长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/
Re-enter new password: #再次输入新密码
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
连续输入4个Y
.
.
.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!
四、安装 PHP
1、更新 YUM 源
运行以下命令添加 epel 源
yum install -y \
https://repo.ius.io/ius-release-el7.rpm \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
运行以下命令添加 Webtatic 源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2、运行以下命令安装 PHP
yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-pdo.x86_64 php70w-mysqlnd php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongodb
3、运行以下命令查看 PHP 版本
php -v
4、运行以下命令,在 Apache 网站根目录创建测试文件
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
5、运行以下命令重启Apache服务
systemctl restart httpd
6、本地浏览器确认
在本地机器的浏览器地址栏中,输入http://实例公网IP/phpinfo.php
并按Enter键。
显示PHP信息表示安装成功.
— End —