Manually Deploying LAMP (Ubuntu)
Scenarios
LAMP is an acronym for Linux, Apache, MySQL, and PHP. It is often used to build websites and web applications. LAMP is maintained by a community of global experts and provides abundant resources. This helps you create, deploy, and maintain applications efficiently.
This section describes how to deploy LAMP on an ECS running Ubuntu.
Advantages
- You can unleash ECS features like elastic scaling, strong security, high availability, and easy management.
- The LAMP architecture provides extensive web resources for lightweight and fast development, and delivers high performance at a low cost.
Resource Planning
Table 1 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 software |
Free |
MySQL |
An open-source relational database software |
Free |
PHP |
An open-source software used for web development |
Free |
Procedure
To deploy an LAMP environment on an ECS running Ubuntu, do as follows:
Procedure
Preparations
- An EIP has been bound to the ECS. For details, see Binding an EIP.
- The rules listed in Table 2 have been added to the security group that the target ECS belongs to. For details, see Adding a Security Group Rule.
Procedure
- Log in to the ECS.
- Install Apache.
- Run the following command to update the software packages in Ubuntu:
sudo apt update
- Run the following command to install Apache:
sudo apt-get -y install apache2
- Run the following command to check the Apache version:
apache2 -v
Information similar to the following is displayed.
- Run the following commands in sequence to start Apache and enable it to start automatically upon ECS startup:
sudo systemctl start apache2 sudo systemctl enable apache2
- Run the following command to check whether the Apache service is started:
sudo systemctl status apache2
If the active state is displayed, as shown in the following figure, the Apache service has been started.
- Run the following command to update the software packages in Ubuntu:
- Install and configure MySQL.
- Run the following command to install MySQL:
sudo apt -y install mysql-server
- Run the following command to check the MySQL version:
mysql -V
Information similar to the following is displayed.
- Run the following commands to start MySQL:
sudo systemctl enable mysql sudo systemctl daemon-reload
- Configure MySQL.
- Run the following command to access MySQL:
sudo mysql
- Set the password of user root.
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'newpassword';
- Exit the MySQL database.
exit;
- Run the following commands to perform security configuration for MySQL:
sudo mysql_secure_installation
Securing the MySQL server deployment. Enter password for user root: #Enter the password of user root you have set. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 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 to keep the password unchanged. ... 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 command to access MySQL:
- Run the following command to install MySQL:
- Install PHP.
- Run the following command to install the software-properties-common software package:
sudo apt-get install -y software-properties-common
- Run the following command to install the third-party software package Ondrej PPA of PHP:
sudo add-apt-repository ppa:ondrej/php
If the following information is displayed, press Enter.
- Run the following command to install PHP:
sudo apt-get install -y php8.3 php8.3-fpm libapache2-mod-php8.3
- Run the following command to check the PHP version:
php -v
If information similar to the following is displayed, PHP has been installed.
- Run the following command to install the software-properties-common software package:
- Test the deployment.
- Run the following command to go to the Apache configuration file directory, copy the apache2.conf file to the apache2.conf.bak file, and retain the original example configuration file as a backup:
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak
- Perform the following operations to modify the Apache configuration file to support PHP:
- Run the following command to open the Apache configuration file:
sudo vim /etc/apache2/apache2.conf
- Press i to enter insert mode.
- Modify the apache2.conf file and add the following to the file:
DirectoryIndex index.html index.php <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>
- Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
- Run the following command to open the Apache configuration file:
- Create a test web page in the Apache website root directory.
- Run the following command to obtain the path of the Apache website root directory:
sudo cat /etc/apache2/sites-available/000-default.conf
- Run the following command to create a test web page in the website root directory and add the phpinfo() function to the web page content: The phpinfo() function displays all PHP configuration information.
sudo sh -c 'echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php'
- Run the following command to obtain the path of the Apache website root directory:
- Run the following command to restart Apache:
sudo systemctl restart apache2
- Enter http://<server-IP-address>/phpinfo.php in the address bar. If the following page is displayed, the environment has been deployed.
- After the LAMP environment is set up, run the following command to delete the phpinfo.php test file to prevent potential data breaches:
sudo rm -rf <website-root-directory>/phpinfo.php
In this example, the root directory of the website is /var/www/html. Run the following command to delete the test file:
sudo rm -rf /var/www/html/phpinfo.php
- Run the following command to go to the Apache configuration file directory, copy the apache2.conf file to the apache2.conf.bak file, and retain the original example configuration file as a backup:
Follow-up Operations
After the LAMP environment is deployed, refer to the following to set up a website or application:
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot