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. LAMP stacks are commonly used to build websites. This topic describes how to deploy a LAMP stack on an Elastic Compute Service (ECS) instance that runs Alibaba Cloud Linux 3.
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: Alibaba Cloud Linux 3.2104 LTS 64-bit
- Network type: Virtual Private Cloud (VPC)
- IP address: a public IP address
- Inbound rules are 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. Note For security purposes, this topic describes only the inbound rules that allow traffic on the ports required to deploy and test an LAMP stack. You can configure security group rules to allow traffic on more ports based on your requirements. For example, if you want to connect to a MySQL database that is deployed on an ECS instance, you must add an inbound rule to a security group of the instance to allow traffic on port 3306, which is the default port used for MySQL.
Background information
- Apache: 2.4.37
- MySQL: 5.7.40
- PHP: 7.4.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
- Connect to the ECS instance on which you want to build a LAMP stack. For more information, see Connection methodsGuidelines on instance connection.
- Run the following command to check the operating system version:
A command output similar to the following one indicates that the operating system is Alibaba Cloud Linux 3:cat /etc/redhat-release
[root@iZbp14h7n3cwipjln62**** ~]# cat /etc/redhat-release Alibaba Cloud Linux release 3 (Soaring Falcon)
- Disable the firewall.
- Disable Security-Enhanced Linux (SELinux).
Step 2: Install Apache
Apache is the number one web server software on the Internet. Apache can run on almost any operating systems and is well accepted as a secure, cross-platform web server.
- Run the following commands to install Apache and its extension package:
yum -y install httpd httpd-manual mod_ssl mod_perl yum -y install httpd httpd-devel
- Run the following command to check the version of Apache:
A command output similar to the following one indicates that the Apache version is 2.4.6:httpd -v
[root@iZbp14h7n3cwipjln62**** ~]# httpd -v Server version: Apache/2.4.37 (Alibaba Cloud Linux) Server built: Jul 21 2022 15:33:44
- Run the following commands in sequence to start Apache and configure Apache to auto-start on system startup:
systemctl start httpd systemctl enable httpd
- Check whether Apache is installed and started.
Step 3: Install and configure MySQL
- Run the following command to install MySQL:
wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm && yum -y install mysql57-community-release-el7-10.noarch.rpm && yum -y install mysql-community-server --nogpgcheck
- Run the following command to check the version of MySQL:
mysql -V
A command output similar to the following one indicates that MySQL is installed:[root@iZbp14h7n3cwipjln62**** ~]# mysql -V mysql Ver 14.14 Distrib 5.7.40, for Linux (x86_64) using EditLine wrapper
- Run the following command to start MySQL:
systemctl start mysqld
- Run the following commands in sequence to configure MySQL to auto-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. In this example, the initial password isdyrksweb****
.[root@iZbp14h7n3cwipjln62kxvZ ~]# grep "password" /var/log/mysqld.log 2022-10-26T09:29:00.515789Z 1 [Note] A temporary password is generated for root@localhost: dyrksweb****
- Run the following command to configure the security settings of MySQL:
mysql_secure_installation
Perform one of the following operations based on the command output:
Step 4: Install PHP
- Run the following command to add and update the Extra Packages for Enterprise Linux (EPEL) repository:
rpm -ivh --nodeps https://rpms.remirepo.net/enterprise/remi-release-8.rpm
- Run the following commands to install PHP:
dnf update -y dnf libdnf sed -i 's/PLATFORM_ID="platform:al8"/PLATFORM_ID="platform:el8"/g' /etc/os-release yum -y module install php:remi-7.4 sed -i 's/PLATFORM_ID="platform:el8"/PLATFORM_ID="platform:al8"/g' /etc/os-release
- Run the following command to check the version of PHP:
php -v
A command output similar to the following one indicates that PHP is installed:[root@iZbp14h7n3cwipjln62**** ~]# php -v PHP 7.4.33 (cli) (built: Dec 19 2022 13:23:13) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.33, Copyright (c), 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:
systemctl restart httpd
- 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. - After the LAMP stack is built, we recommend that you delete the phpinfo.php test file to prevent data leaks.
In this example, /var/www/html is used as the website root directory. Run the following command to delete the test file:rm -rf <Website root directory> /phpinfo.php
rm -rf /var/www/html/phpinfo.php
Step 5: (Optional) Install phpMyAdmin
phpMyAdmin is a MySQL databases management tool that allows you to manage databases by using web interfaces.
- Run the following command to create a directory to store phpMyAdmin data:
mkdir -p /var/www/html/phpmyadmin
- 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 command to install the unzip tool and decompress the phpMyAdmin package:
unzip phpMyAdmin-4.0.10.20-all-languages.zip
- Run the following commands in sequence to switch to the home directory and download the phpMyAdmin package:
- Run the following command to copy the phpMyAdmin files to the created 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 a browser on your computer 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. The default username for MySQL is root. The password is the one that you reset in the following step: If a command output similar to the following one is returned, reset the password of the root account as prompted.