lamp + mssql环境部署之一:安装Apache、Mysql、PHP

步骤一:准备工作

1.运行命令cat /etc/redhat-release查看系统版本。

2.关闭防火墙。

2.1. 运行systemctl status firewalld命令查看当前防火墙的状态。

* 如果防火墙的状态参数是inactive,则防火墙为关闭状态。
* 如果防火墙的状态参数是active,则防火墙为开启状态。本示例中防火墙为开启状态,因此需要关闭防火墙。

2.2. 关闭防火墙。如果防火墙为关闭状态,请忽略此步骤。

* 如果您想临时关闭防火墙,运行命令systemctl stop firewalld。
  > 说明 这只是暂时关闭防火墙,下次重启Linux后,防火墙还会开启。

* 如果您想永久关闭防火墙,运行命令systemctl disable firewalld。
  > 说明 如果您想重新开启防火墙,请参见firewalld官网信息。
  1. 关闭SELinux。

3.1 运行getenforce命令查看SELinux的当前状态。

* 如果SELinux状态参数是Disabled, 则SELinux为关闭状态。
* 如果SELinux状态参数是Enforcing,则SELinux为开启状态。本示例中SELinux为开启状态,因此需要关闭SELinux。

3.2 关闭SELinux。如果SELinux为关闭状态,请忽略此步骤。
* 如果您想临时关闭SELinux,运行命令setenforce 0。
>说明 这只是暂时关闭SELinux,下次重启Linux后,SELinux还会开启。

* 如果您想永久关闭SELinux,运行命令vi /etc/selinux/config编辑SELinux配置文      件。回车后,把光标移动到SELINUX=enforcing这一行,按i键,将其修改为SELINUX=disabled, 按Esc键,然后输入:wq并回车以保存并关闭SELinux配置文件。 最后重启系统使设置生效。
  > 说明 如果您想重新开启SELinux,请参见SELinux的官方文档。

步骤二:安装Apache

  1. 运行以下命令安装Apache服务及扩展包。
yum -y install httpd httpd-manual mod_ssl mod_perl mod_auth_mysql
  1. 运行httpd -v命令可查看Apache的版本号。
httpd -v
``
![](https://img2022.cnblogs.com/blog/2519465/202207/2519465-20220727161304334-125995948.png)

3. 依次运行以下命令启动Apache服务并设置服务开机自启动。
```shell
systemctl start httpd
systemctl enable httpd
  1. 查看安装结果。
  • 登录ECS管理控制台。
  • 在左侧导航栏,单击实例与镜像 > 实例。
  • 在实例列表中找到正在部署环境的实例,从该实例的IP地址中复制公网IP。
  • 在本地机器的浏览器地址栏中,输入http://实例公网IP并按Enter键。
  • 若返回页面如下图所示,说明Apache服务启动成功。httpd

步骤三:安装并配置MySQL

  1. 运行以下命令更新YUM源。
rpm -Uvh  http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
  1. 运行以下命令安装MySQL。

说明 如果您使用的操作系统内核版本为el8,可能会提示报错信息No match for argument。您需要先运行命令yum module disable mysql禁用默认的MySQL模块,再安装MySQL。

yum -y install mysql-community-server --nogpgcheck
  1. 运行以下命令查看MySQL版本号。
mysql -V

返回结果如下所示,表示MySQL安装成功。

  1. 运行以下命令启动MySQL。
systemctl start mysqld
  1. 依次运行以下命令设置开机启动MySQL。
systemctl enable mysqld
systemctl daemon-reload
  1. 运行以下命令查看MySQL的初始密码。
grep "password" /var/log/mysqld.log

返回结果示例如下,本示例中初始密码为7inAqKeKgS-i。

  1. 运行以下命令配置MySQL的安全性。
mysql_secure_installation

安全性的配置包含以下五个方面:

  • 重置root账号的密码。

说明 请您安全保管root账号的密码信息。

Enter password for user root: #输入上一步获取的root用户初始密码。

The existing password for the user account root has expired. Please set a new password.

New password: #输入新密码,长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/

Re-enter new password: #重复输入新密码。
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 #按Y,并再次输入上步已设置的密码。

New password: #再次输入新密码。

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 #按Y使用新密码。

  • 输入Y删除匿名用户账号。
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y  #是否删除匿名用户,输入Y
Success.
  • 输入Y禁止root账号远程登录。
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #禁止root远程登录,输入Y
Success.

  • 输入Y删除test库以及对test库的访问权限。
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #是否删除test库和对它的访问权限,输入Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.
  • 输入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 #是否重新加载授权表,输入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
  1. 运行以下命令安装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
  1. 运行以下命令查看PHP版本。
    php -v

返回结果如下所示,表示安装成功。

  1. 运行以下命令,在Apache网站根目录创建测试文件。
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
  1. 运行以下命令重启Apache服务。
systemctl restart httpd
  1. 在本地机器的浏览器地址栏中,输入http://实例公网IP/phpinfo.php并按Enter键。
    显示如下页面表示安装成功。PHP

步骤五:安装phpMyAdmin

phpMyAdmin是一个MySQL数据库管理工具,通过Web接口管理数据库方便快捷。

1.运行以下命令准备phpMyAdmin数据存放目录。

mkdir -p /var/www/html/phpmyadmin
  1. 运行以下命令下载phpMyAdmin压缩包并解压。
  • 依次运行以下命令,返回系统主目录并下载phpMyAdmin压缩包。
cd
wget --no-check-certificate https://files.phpmyadmin.net/phpMyAdmin/4.0.10.20/phpMyAdmin-4.0.10.20-all-languages.zip
  • 依次运行以下命令,安装unzip工具并解压phpMyAdmin压缩包。
yum install -y unzip
unzip phpMyAdmin-4.0.10.20-all-languages.zip
  1. 运行以下命令复制phpMyAdmin文件到准备好的数据存放目录。
mv phpMyAdmin-4.0.10.20-all-languages/*  /var/www/html/phpmyadmin
  1. 在本地机器浏览器地址栏,输入http://实例公网 IP/phpmyadmin并按Enter键,访问phpMyAdmin登录页面。
    若返回页面如下图所示,说明phpMyAdmin安装成功。phpMyAdmin安装成功

  2. 输入MySQL的用户名和密码,单击执行。

如果出现以下页面,说明MySQL连接成功。MySQL连接成功

posted @ 2022-07-27 20:47  panbin_2006  阅读(68)  评论(0编辑  收藏  举报