Manually Deploying LAMP (CentOS 7.8 PHP 7.0)
Overview
LAMP is a web application platform consisting of Linux, Apache, MySQL, and PHP.
The best practices for Huawei Cloud ECS guide you through the deployment of LAMP on a Linux ECS. The CentOS 7.8 64bit OS is used as an example in this section.
Prerequisites
- The ECS has an EIP bound.
- The rule listed in the following table has been added to the security group which the target ECS belongs to. For details, see Adding a Security Group Rule.
Table 1 Security group rule Direction
Priority
Action
Type
Protocol & Port
Source Address
Inbound
1
Allow
IPv4
TCP: 80
0.0.0.0/0
Resource Planning
Table 2 lists the resource configuration and software versions used in this practice. The commands and parameters may vary according to the hardware specifications or software versions you would use.
Resource |
Description |
Cost |
---|---|---|
ECS |
|
The following resources generate costs:
For billing details, see Billing Modes. |
Apache |
An open-source web server |
Free |
MySQL |
An open-source relational database software Download URL: http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm |
Free |
PHP |
An open-source software used for web development Download URL: |
Free |
Procedure
- Install Apache.
- Log in to the ECS.
- Run the following commands as user root to update the software package and install Apache:
yum -y update
yum -y install httpd
- Run the following command to check the version of the installed Apache:
Information similar to the following is displayed:
Server version: Apache/2.4.6 (CentOS) Server built: May 30 2023 14:01:11
- Run the following commands in sequence to start Apache and enable it to start automatically upon ECS startup:
systemctl enable httpd
- Enter http://Server IP address in the address bar of the browser to access Apache. If the following page is displayed, Apache has been installed.
- Install MySQL.
- Run the following commands in sequence to install MySQL:
wget -i -c 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 the installed MySQL:
Information similar to the following is displayed:
mysql Ver 14.14 Distrib 5.7.44, for Linux (x86_64) using EditLine wrapper
- Run the following commands in sequence to start MySQL and enable it to start automatically upon ECS startup:
systemctl enable mysqld
- Run the following command to check the MySQL status:
systemctl status mysqld.service
[root@ecs-adc3 ~]# systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2023-10-31 19:33:40 CST; 36s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 7916 (mysqld) CGroup: /system.slice/mysqld.service └─7916 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid Aug 16 19:33:35 ecs-adc3 systemd[1]: Starting MySQL Server... Aug 16 19:33:40 ecs-adc3 systemd[1]: Started MySQL Server.
- Run the following commands to obtain the root user's password that is automatically set during MySQL installation:
grep 'temporary password' /var/log/mysqld.log
Information similar to the following is displayed:2023-10-31T11:53:08.691748Z 1 [Note] A temporary password is generated for root@localhost: 2YY?3uHUA?Ys
- Run the following command and follow the prompts to harden MySQL:
Securing the MySQL server deployment. Enter password for user root: #Enter the obtained password of user root. The existing password for the user account root has expired. Please set a new password. New password: #Enter a new password of user root. 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) : N #Press N. ... skipping. 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 #Press Y to remove anonymous users. Success. 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 #Press Y to disallow remote logins of user root. Success. 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 #Press Y to delete the test database and remove access to it. - Dropping test database... Success. - Removing privileges on test database... Success. 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 #Press Y to reload privilege tables. Success. All done!
- Run the following commands in sequence to install MySQL:
- Install PHP.
- Run the following commands to install PHP 7 and required PHP extensions:
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
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
- Run the following command to check the version of the installed PHP:
Information similar to the following is displayed:
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
- Run the following commands to start PHP and enable it to start automatically upon ECS startup:
systemctl enable php-fpm
- Run the following commands to install PHP 7 and required PHP extensions:
- Test the LAMP deployment.
- Create the info.php test file in /var/www/html/.
- Run the following command to create and open the info.php test file:
vim /var/www/html/info.php
- Press i to enter insert mode.
- Modify the info.php file and add the following to the file:
<?php phpinfo(); ?>
- Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
- Run the following command to create and open the info.php test file:
- Run the following command to restart Apache:
- Enter http://Server IP address/info.php in the address bar. If the following page is displayed, the LAMP environment has been set up.
- Create the info.php test file in /var/www/html/.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.