阿里云部署LAMP环境1

1.准备工作

实例已分配公网IP地址或绑定弹性公网IP(EIP)。
操作系统必须为CentOS 7.x。
实例安全组的入方向规则已放行22、80、443端口。


2.环境说明

Apache版本:Apache 2.4.6
MySQL版本:MySQL 5.7.31
PHP版本:PHP 7.0.33


3.搭建环境

步骤1:关闭防火墙和SELinux

# 1.查看当前防火墙的状态
# 如果防火墙的状态参数是inactive,则防火墙为关闭状态
# 如果防火墙的状态参数是active,则防火墙为开启状态
systemctl status firewalld

# 2.临时关闭防火墙
sudo systemctl stop firewalld
systemctl status firewalld

# 3.查看SELinux的当前状态
# 如果SELinux状态参数是Disabled,则SELinux为关闭状态
# 如果SELinux状态参数是Enforcing,则SELinux为开启状态
getenforce # 4.关闭SELinux并查看SELinux状态

setenforce 0
getenforce


步骤2:安装Apache

# 1.安装Apache服务及扩展包

yum -y install httpd httpd-manual mod_ssl mod_perl


# 2.查看Apache版本

httpd -v


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

Server version: Apache/2.4.6 (CentOS)
Server built: May 30 2023 14:01:11


# 3.启动Apache服务并设置服务开机自启动

systemctl start httpd
systemctl enable httpd


# 4.查看安装结果:浏览器访问【http://ip地址】,返回结果类似如下所示,表示Apache安装成功。

Testing 123..
This page is used to test the proper operation of the Apache HTTP server after it has been installed. If you can read this page it means that this site is working properly. This server is powered by CentOS.


步骤3:安装并配置MySQL

(1) 安装MySQL

# 1.更新YUM源

rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm


# 2.安装MySQL

yum -y install mysql-community-server --nogpgcheck


# 3.查看MySQL版本号
mysql -V

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

mysql Ver 14.14 Distrib 5.7.31, for Linux (x86_64) using EditLine wrapper


# 4.启动MySQL

systemctl start mysqld


# 5.设置开机启动MySQL

systemctl enable mysqld
systemctl daemon-reload


(2) 配置MySQL

# 1.获取并记录root用户的初始密码

grep "password" /var/log/mysqld.log


返回结果示例如下,本示例中初始密码为+47,uijcojcU

2020-08-28T03:01:49.848762Z 1 [Note] A temporary password is generated for root@localhost: +47,uijcojcU


# 2.配置MySQL的安全性

mysql_secure_installation


# 3.重置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使用新密码。


# 4.输入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.


# 5.输入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.


# 6.输入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.


# 7.输入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!


步骤4:安装PHP

# 1.添加epel源

yum install -y \
https://repo.ius.io/ius-release-el7.rpm \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm


# 2.添加Webtatic源

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm


# 3.安装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


# 4.查看PHP版本
php -v

返回结果如下所示,表示安装成功。
PHP 7.0.33 (cli) (built: Dec 6 2018 22:30:44) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.33, Copyright (c) 1999-2017, by Zend Technologies


步骤5:测试环境

(1) 创建测试文件:

# 1.在Apache网站根目录创建测试文件

echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

# 2.重启Apache服务

systemctl restart httpd


(2) 访问测试文件:在浏览器的地址栏输入http://<ECS实例公网IP地址>/phpinfo.php进行访问,操作结果如下:



相关推荐

  • 获取指定目录下的所有图片信息

    1 获取指定目录下的所有图片信息// 获取指定目录下的所有图片信息 public function getImagesInfo($directory) { $images = []; // 创建递归目录迭代器 $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY ); // 遍历目录中的每个文件 foreach (

  • Thinkphp各版本的PHP要求

    ThinkPHP 8.0:运行环境要求PHP8.0+,兼容PHP8.3ThinkPHP 6.1:运行环境要求PHP7.2+,兼容PHP8.1ThinkPHP 6.0:运行环境要求PHP7.2+,兼容PHP8.1ThinkPHP 5.1:运行环境要求PHP5.6+,兼容PHP8.0ThinkPHP 5.0:运行环境要求PHP5.4+,兼容PHP7.3

  • Thinkphp5.1路径常量

    1 配置文件位置根目录/config/template.php2 配置文件内容&lt;?php// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reser

  • Thinkphp5.0路径常量

    1 配置文件位置根目录/application/模块名/config.php2 配置文件内容&lt;?php//配置文件return [ // 后台视图输出字符串内容替换 'view_replace_str' =&gt; [ '__PUBLIC__' =&gt; '/', '__STATIC__' =&gt; '/static', '__CONSOLE__' =&gt; '/static/console', '__CONSOLE_CSS__' =&gt; '/static/console/css', '__CONSOLE_IMAGES__' =&gt; '/static/console/ima

  • wp站点防止别人进行DDOS攻击

    1 简介wp站点防止别人进行DDOS攻击。2 配置位置位置:根目录/wp-config.php3 配置内容在【根目录/wp-config.php】文件的开头添加如下代码:if(strpos($_SERVER['REQUEST_URI'], 'xmlrpc.php') !== false){ $protocol = $_SERVER['SERVER_PROTOCOL'] ?? ''; if(!in_array($protocol, ['HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3'], true)){ $protocol = 'HTTP/1.0'; } hea

  • 只读属性

    1 只读属性简介只读属性的声明方式类似于普通属性,但需要使用 readonly 关键字。2 只读属性例子class Point { public readonly float $x; public readonly float $y; public function __construct(float $x, float $y) { $this-&gt;x = $x; $this-&gt;y = $y; }}$point = new Point(3.5, 2.8);echo $point-&gt;x; // 输出: 3.5echo $point-&gt;y; // 输出: 2.8// 下面的尝