本文介绍
前提条件
背景信息
本文适用于熟悉Linux操作系统,初次使用阿里云进行建站 的个人 用户。在示例步骤中使用了以下版本的软件。操作时,请您以实际软件版本为准。
- Apache:2.4.6
- MySQL:5.7.31
- PHP:7.0.33
- phpMyAdmin:4.0.10.20
本文主要说明手动安装LAMP平台的操作步骤,您也可以在云市场
点我去体验
步骤一:准备工作
- 使用向导创建实例。
- 通过密码或密钥认证登录Linux实例。
- 运行命令cat /etc/redhat-release查看系统版本。
- 关闭防火墙。
- 运行systemctl status firewalld命令查看当前防火墙的状态。
- 如果防火墙的状态参数是inactive,则防火墙为关闭状态。
- 如果防火墙的状态参数是active,则防火墙为开启状态。本示例中防火墙为开启状态,因此需要关闭防火墙。
- 关闭防火墙。如果防火墙为关闭状态,请忽略此步骤。
- 如果您想临时关闭防火墙,运行命令systemctl stop firewalld。说明 这只是暂时关闭防火墙,下次重启Linux后,防火墙还会开启。
- 如果您想永久关闭防火墙,运行命令systemctl disable firewalld。说明 如果您想重新开启防火墙,请参见firewalld官网信息。
- 如果您想临时关闭防火墙,运行命令systemctl stop firewalld。
- 运行systemctl status firewalld命令查看当前防火墙的状态。
- 关闭SELinux。
- 运行getenforce命令查看SELinux的当前状态。
- 如果SELinux状态参数是Disabled, 则SELinux为关闭状态。
- 如果SELinux状态参数是Enforcing,则SELinux为开启状态。本示例中SELinux为开启状态,因此需要关闭SELinux。
- 关闭SELinux。如果SELinux为关闭状态,请忽略此步骤。
- 如果您想临时关闭SELinux,运行命令
setenforce 0
。说明 这只是暂时关闭SELinux,下次重启Linux后,SELinux还会开启。 - 如果您想永久关闭SELinux,运行命令vi /etc/selinux/config编辑SELinux配置文件。回车后,把光标移动到
SELINUX=enforcing
这一行,按i键,将其修改为SELINUX=disabled
, 按Esc键,然后输入:wq并回车以保存并关闭SELinux配置文件。 最后重启系统使设置生效。说明 如果您想重新开启SELinux,请参见SELinux的官方文档。
- 如果您想临时关闭SELinux,运行命令
- 运行getenforce命令查看SELinux的当前状态。
步骤二:安装Apache
- 运行以下命令安装Apache服务及扩展包。
yum -y install httpd httpd-manual mod_ssl mod_perl mod_auth_mysql
- 运行httpd -v命令可查看Apache的版本号。
- 依次运行以下命令启动Apache服务并设置服务开机自启动。
systemctl start httpd
systemctl enable httpd
- 查看安装结果。
- 登录ECS管理控制台。
- 在左侧导航栏,单击实例与镜像 > 实例。
- 在实例列表中找到正在
部署 环境的实例,从该实例的IP地址中复制公网IP。 - 在本地机器的浏览器地址栏中,输入
http://实例公网IP
并按Enter键。若返回页面如下图所示,说明Apache服务启动成功。
步骤三:安装并配置MySQL
- 运行以下命令
更新 YUM源。rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
- 运行以下命令安装MySQL。说明 如果您使用的操作系统内核版本为el8,可能会提示报错信息No match for argument。您需要先运行命令yum module disable mysql禁用默认的MySQL模块,再安装MySQL。
yum -y install mysql-community-server --nogpgcheck
- 运行以下命令查看MySQL版本号。
mysql -V
返回结果如下所示,表示MySQL安装成功。mysql Ver 14.14 Distrib 5.7.31, for Linux (x86_64) using EditLine wrapper
- 运行以下命令启动MySQL。
systemctl start mysqld
- 依次运行以下命令设置开机启动MySQL。
systemctl enable mysqld systemctl daemon-reload
- 运行以下命令查看MySQL的初始密码。
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
- 运行以下命令配置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!
- 重置root账号的密码。
步骤四:安装PHP
- 更新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
- 运行以下命令添加epel源。
- 运行以下命令安装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
- 运行以下命令查看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
- 运行以下命令,在Apache网站根目录创建测试文件。
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
- 运行以下命令重启Apache服务。
systemctl restart httpd
- 在本地机器的浏览器地址栏中,输入
http://实例公网IP/phpinfo.php
并按Enter键。显示如下页面表示安装成功。
步骤五:安装phpMyAdmin
phpMyAdmin是一个MySQL数据库管理工具,通过Web接口管理数据库方便快捷。
- 运行以下命令准备phpMyAdmin数据存放目录。
mkdir -p /var/www/html/phpmyadmin
- 运行以下命令下载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
- 依次运行以下命令,返回系统主目录并下载phpMyAdmin压缩包。
- 运行以下命令复制phpMyAdmin文件到准备好的数据存放目录。
mv phpMyAdmin-4.0.10.20-all-languages/* /var/www/html/phpmyadmin
- 在本地机器浏览器地址栏,输入
http://实例公网 IP/phpmyadmin
并按Enter键,访问phpMyAdmin登录页面。若返回页面如下图所示,说明phpMyAdmin安装成功。 - 输入MySQL的用户名和密码,单击执行。如果出现以下页面,说明MySQL连接成功。
在文档使用中是否遇到以下问题
更多建议