This topic describes how to build a LAMP stack on an Elastic Compute Service (ECS)
instance. LAMP is an acronym of the names of its original four components: the Linux
operating system, Apache HTTP Server, MySQL relational database management system,
and PHP programming language.
Prerequisites
- An ECS instance is created and assigned a public IP address. For more information,
see Creation method overview.
In this topic, an ECS instance that has the following configurations is used. To prevent
command errors caused by operating system version issues, we recommend that you use
the operating system version that is used in this topic.
- Instance type: ecs.c6.large
- Operating system: CentOS 7.8 64-bit public image
- Network type: Virtual Private Cloud (VPC)
- IP address: public IP address
- An inbound rule is added to a security group of the ECS instance to allow traffic
on ports 22 and 80. For more information, see Add a security group rule.
Background information
This topic is intended for individual users who are familiar with Linux operating
systems but new to using Alibaba Cloud ECS to build websites. The following software
versions are used in the examples in this topic. Operations may vary based on software
versions.
- Apache HTTP Server: 2.4.6
- MySQL: 5.7.31
- PHP 7.0.33
- phpMyAdmin 4.0.10.20
This topic describes how to manually build a LAMP stack. You can also purchase a LAMP
image on Alibaba Cloud Marketplace and create an ECS instance from the image to build websites.
Step 1: Make preparations
- Create an ECS instance. For more information, see Create an instance by using the wizard.
- Log on to the instance. For more information, see Connect to a Linux instance by using a password.
- Run the cat /etc/redhat-release command to check the operating system version.
- Disable the firewall.
- Run the systemctl status firewalld command to check the state of the firewall.
- If the firewall is in the inactive state, the firewall is disabled.
- If the firewall is in the active state, the firewall is enabled. In this example, the firewall is in the active state
and must be disabled.
- Disable the firewall. Skip this step if the firewall is already disabled.
- To temporarily disable the firewall, run the systemctl stop firewalld command.
Note After you run the preceding command, the firewall is disabled. The next time you restart
the Linux operating system, the firewall is re-enabled and enters the active state.
- To permanently disable the firewall, run the systemctl disable firewalld command.
- Disable Security-Enhanced Linux (SELinux).
- Run the getenforce command to check the state of SELinux.
- If SELinux is in the Disabled state, SELinux is disabled.
- If SELinux is in the Enforcing state, SELinux is enabled. In this example, SELinux is in the Enforcing state and
must be disabled.
- Disable SELinux. Skip this step if SELinux is already disabled.
- To temporarily disable SELinux, run the
setenforce 0
command.
Note After you run the preceding command, SELinux is disabled. The next time you restart
the Linux operating system, SELinux is re-enabled and enters the Enforcing state.
- To permanently disable SELinux, run the vi /etc/selinux/config command to edit the SELinux configuration file. Press the Enter key. Move the pointer
to the
SELINUX=enforcing
line and press the I key to switch to the Insert mode. Change the line to SELINUX=disabled
and press the Esc key. Enter :wq and press the Enter key to save the changes and close the SELinux configuration file.
Restart the operating system to apply the settings.
Step 2: Install Apache
- Run the following command to install Apache and its extension package:
yum -y install httpd httpd-manual mod_ssl mod_perl
- Run the httpd -v command to check the Apache version.
- Run the following commands in sequence to start Apache and configure Apache to start
on system startup:
systemctl start httpd
systemctl enable httpd
- Check the installation result.
- Log on to the ECS console.
- In the left-side navigation pane, choose .
- On the Instances page, find the instance on which you want to build a LAMP stack and copy its public
IP address from the IP Address column.
- Enter
http://<Public IP address of the ECS instance>
in the address bar of your browser and press the Enter key. A page similar to the following one indicates that Apache is started.

Step 3: Install and configure MySQL
- Run the following command to update the YUM repository:
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
- Run the following command to install MySQL.
Note If you are using an operating system whose kernel version is el8, you may receive
the No match for argument error message. If this occurs, run the yum module disable mysql command to disable the default MySQL module before you install MySQL.
yum -y install mysql-community-server --nogpgcheck
- Run the following command to check the MySQL version:
A command output similar to the following one indicates that MySQL is installed:
mysql Ver 14.14 Distrib 5.7.31, for Linux (x86_64) using EditLine wrapper
- Run the following command to start MySQL:
- Run the following commands in sequence to configure MySQL to start on system startup:
systemctl enable mysqld
systemctl daemon-reload
- Run the following command to check the initial password of the root account used to
log on to MySQL:
grep "password" /var/log/mysqld.log
A command output similar to the following one is returned and displays the initial
password of the root account. In this example, the initial password of the root account
is
+47,uijcojcU
:
2020-08-28T03:01:49.848762Z 1 [Note] A temporary password is generated for root@localhost: +47,uijcojcU
- Run the following command to configure the security settings of MySQL:
mysql_secure_installation
Perform the following operations:
- Reset the password of the root account.
Note You must keep the password of the root account secure.
Enter password for user root: # Enter the initial password of the root account that you obtained in the preceding step.
The existing password for the user account root has expired. Please set a new password.
New password: # Enter a new password. The password must be 8 to 30 characters in length and must contain uppercase letters, lowercase letters, digits, and special characters. Supported special characters include ( ) ` ~ ! @ # $ % ^ & * - + = | { } [ ] : ; ‘ < > , . ? /
Re-enter new password: # Enter the new password again.
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 # Enter Y and enter the new password again.
New password: # Enter the new password.
Re-enter new password: # Enter the new password again.
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 # Enter Y to use the new password.
- Enter Y to delete the anonymous user account.
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 # Enter Y to delete the anonymous user.
Success.
- Enter Y to deny remote access by the root account.
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 # Enter Y to deny remote access by the root account.
Success.
- Enter Y to delete the test database and the access permissions on the database.
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 # Enter Y to delete the test database and the access permissions on the database.
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
- Enter Y to reload privilege tables.
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 # Enter Y to reload privilege tables.
Success.
All done!
Step 4: Install PHP
- Update the YUM repositories.
- Run the following commands to add the EPEL repository:
yum install -y \
https://repo.ius.io/ius-release-el7.rpm \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- Run the following command to add the Webtatic repository:
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
- Run the following command to install 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
If the "Cannot find a valid baseurl for repo: webtatic/x86_64" error message appears,
perform the following operations to re-install PHP:
- Run the following command to open the configuration file:
vi /etc/resolv.conf
- Press the I key to enter the Insert mode. Then, paste
nameserver 8.8.8.8
to the configuration file.
- Press the Ecs key and then enter :wq to exit the Insert mode and save the changes.
- Run the following command to restart the network service:
service network restart
- Run the following command to check the PHP version:
A command output similar to the following one indicates that PHP is installed:
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
- Run the following command to create a test file in the root directory of the Apache
website.
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
- Run the following command to restart Apache:
- Enter
http://<Public IP address of the ECS instance>/phpinfo.php
in the address bar of a browser on your computer and press the Enter key. A page similar to the following one indicates that PHP is installed.

Step 5: Install phpMyAdmin
phpMyAdmin is a MySQL databases management tool that allows you to manage databases
by using web interfaces.
- Run the following command to prepare a directory to store phpMyAdmin data:
mkdir -p /var/www/html/phpmyadmin
- Run the following commands to download and decompress the phpMyAdmin package.
- Run the following commands in sequence to switch to the home directory and download
the phpMyAdmin package:
cd
wget --no-check-certificate https://files.phpmyadmin.net/phpMyAdmin/4.0.10.20/phpMyAdmin-4.0.10.20-all-languages.zip
- Run the following commands in sequence to install the unzip tool and decompress the
phpMyAdmin package:
yum install -y unzip
unzip phpMyAdmin-4.0.10.20-all-languages.zip
- Run the following command to copy the phpMyAdmin files to the prepared directory:
mv phpMyAdmin-4.0.10.20-all-languages/* /var/www/html/phpmyadmin
- Enter
http://<Public IP address of the ECS instance>/phpmyadmin
in the address bar of your browser and press the Enter key to go to the logon page of phpMyAdmin. A page similar to the following one indicates that phpMyAdmin is installed.

- Enter the username and password of your MySQL account and click Go.