×
Community Blog How to Install LAMP Stack

How to Install LAMP Stack

LAMP stands for Linux, Apache, MySQL, and PHP. This tutorial provides steps on how you can install LAMP on Alibaba Cloud.

LAMP Stack is a combination of the open-source software, Linux, Apache, MySQL, and PHP, which allows dynamic websites and web servers to function.

In this tutorial, we will install a LAMP stack on a virtual private server on Alibaba Cloud. LAMP includes Linux, but we won't be learning how to install Linux because a version of it, specifically Ubuntu, is preinstalled on our server on Alibaba Cloud. So, in this tutorial, we will be focusing on how to install the rest of the LAMP stack in a few easy steps.

Prerequisites

The only prerequisite is that you should have, or apply for, an Alibaba Cloud account.

Installing LAMP Stack

Step 1: Launch an Alibaba Cloud ECS Server

Alibaba Cloud Elastic Compute Service (ECS) is a virtual cloud server product that offers excellent elasticity and computer performance. You can easily launch an Alibaba Cloud ECS instance installed with Linux, or in our case, Ubuntu. Follow the steps below to execute this application:

1.  Login to the Alibaba Cloud ECS Management Console where you will be redirected to the main dashboard.

1

2.  Click Elastic Compute Service under the Products & Services section. This will take you to the ECS overview dashboard. Upon reaching that page, click Instances on the sidebar to navigate to the Instances menu.

2

3.  Create an instance. Thereafter, you can select a preferred payment mode that suits your requirements. You can choose from two packages: Quick launch or Custom Launch. Make the appropriate selection for your data center region and Availability Zone to launch your ECS instance. If you are unsure of your Availability Zone, but you specify your data center region, then the instance will be placed in the default zone.

3

4.  You will now have to select Generation under the Choose Instance Type section. Every generation type offers unique configuration and computing power. Select a Network Type from the options of Classic Network or VPC based on your requirements. Then, select a Network Billing type.

4

5.  This will take you to the next page where you will have to opt for Ubuntu or another Linux server by clicking one of the server thumbnails provided. Also, under the thumbnail, select a version for the server from the drop-down menu and pick the desired storage type from the various options.

5

6.  You will next come to an option to set up your server's security by setting a password. However, you can choose to complete this task later on your console if you don't want to complete it now.

6

7.  Review the details of your purchase configuration, and make changes if needed. Click Activate to confirm and launch your server.

7

8.  You will see your instances in the Instances section. Click Manage to manage your ECS instance.

8

9.  Navigate to Security Groups from the left panel and select Configure Rules.

9

10.  Check whether the instance is already set to allow inbound traffic from Port 80. If not, select Add Security Group Rules to create a new rule.

10

11.  Enter the details as shown in the image below. Click OK to continue.

11

Step 2: Install Apache Server

The Apache web server helps in accepting HTTP requests that come from browsers and allow them to serve them HTTP responses.

1.  To install Apache, open a terminal window and enter the following commands:

apt-get update
apt-get install apache2

2.  To verify that the installation was successful, open your browser and enter the server IP address as follows:

http://ip_of_server 

3.  The Apache server default page should appear upon installation.

Step 3: Install MySQL

MySQL is the open-source database management system used to store and manage the structured data. It can store videos, pictures, along with several other data types. Follow the steps below to install MySQL.

1.  To install MySQL, open a terminal window and enter the following command:

sudo apt-get install mysql-server 

Note: During installation, you will be asked to set the root user password. You can just set a password of your choice.

2.  Now that you have MySQL installed. You can either use the open-source MySQL database management system or the Alibaba database management service called ApsaraDB for RDS to serve as the database system to work with MySQL. Check out the tutorial on How to Launch Apsara DB for RDS instance to learn more.

Step 4: Install PHP

PHP is an acronym that stands for Hypertext Preprocessor. It is an open source scripting language that aids web development and can be used with HTML.

1.  To install PHP, open a terminal window and enter the following command:

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt libapache2-mod-auth-mysql php5-mysql

Here's a quick guide to the parameters used in the above code:

  • libapache2-mod-php5 provides a PHP5 module for the Apache 2 and is compatible only with Apache's prefork MPM.
  • php5-mcrypt enables the data encryption for added security reasons.
  • libapache2-mod-auth-mysql, an Apache 2 module that enables extra HTTP authentication for data stored in MySQL.
  • php5-mysql includes the generic "MySQL" module which can be used to connect to all versions of MySQL.

2.  Answer yes to the prompts that follow, after which PHP will get installed. If you wish to serve the PHP pages with the Apache server, add PHP to the directory index. Then, open the file /etc/apache2/mods-enabled/dir.conf to facilitate this.

vim  /etc/apache2/mods-enabled/dir.conf

3.  Add index.php at the beginning of index files, which looks like the following:

 <IfModule mod_dir.c >   DirectoryIndex index.php index.html index.cgi index.pl index.php index.xhtml  index.htm    </IfModule > 

Step 5: Confirm Installation

To verify a successful installation, deploy a sample PHP page with these configurations:

1.  Create a new file. Name it: info.php in the /var/www/html directory.

vim /var/www/html/info.php

2.  Enter the following content in the file:

 <?php phpinfo(); ?>

3.  Save the file and exit.

4.  Restart the Apache server to see the changes applied.

 sudo service apache2 restart

5.  Now, enter the server IP address in a web browser window:

 http://IPAddress/info.php

Your LAMP Stack installation is now complete. LAMP stack is aptly touted as a very dynamic platform by developers across the globe. Also, it has been proven as a secure, robust, and solid base to deploy high-performing web applications.

Some products you may want to consider from Alibaba Cloud to further enhance the capabilities and security of your Alibaba Cloud ECS server are Alibaba Cloud Web Application Firewall (WAF) and CloudMonitor, which are two top-of-the-line security and monitoring products. These products can increase the reliability and security of our website in the production environment. You can also make continual backups by taking snapshots of your running database to eliminate database failure, which is a feature of ECS.

Below is a detailed introduction:

Alibaba Cloud Web Application Firewall (WAF) can be used to provide protection against web-based attacks, including SQL injections, Cross-site scripting (XSS), Malicious BOT, command execution vulnerabilities, and other common web attacks. WAF filters out a large number of malicious access attempts and alleviates the performance impact of Hypertext Transfer Protocol (HTTP)/HTTP Secure (HTTPS) flood attacks on servers.

Alibaba CloudMonitor can be used to provide in-depth insights into your cloud deployments. CloudMonitor provides advanced analytics on critical metrics like Central Processing Unit (CPU) utilization, latency and also lets you customize parameters specific to business requirements.

0 0 0
Share on

Alibaba Clouder

2,599 posts | 764 followers

You may also like

Comments