Implement a LAMP structure

Josie Tseng
eCloudture
Published in
5 min readJan 3, 2022

With the constant advancements in technology choosing the right option for building powerful and dynamic web applications is surely a tedious task. LAMP is known for its free and open-source approach to back-end development. It contains Linux OS, Apache web server, MySQL database, and PHP. Besides PHP, developers can also use Python and Perl as an alternative. Developers choose the LAMP stack because of the ease of deployment and customization. It is the most popular architecture on the web. LAMP architecture is behind widely-known Content Management Systems (CMS) like WordPress, Joomla, and Drupal. Therefore, if you’re working with one of these popular CMS, you’re using the LAMP stack on your Virtual Private Server(VPS) or dedicated server. So, how to deploy the LAMP architecture in the Azure cloud?

Azure offers a choice of fully managed relational, NoSQL, and in-memory databases, spanning proprietary and open-source engines, to fit the needs of modern app developers. Azure Database for MySQL database solution provides you with database engines. Azure Virtual Machines provides scalable computing capacity in the cloud. Using Azure Virtual Machines eliminates your need to invest in hardware upfront, so you can develop and deploy applications faster.

So We will deploy LAMP architecture using Azure Database for MySQL and Azure Virtual Machines.

By the end of this lab, you will be able to:

  • Deploy an Azure Database for MySQL database and web server
  • Connect your web server to your database

Scenario

We will launch a virtual machine with the Ubuntu OS. And will install the Apache and run the PHP script to connect to the MySQL database in this virtual machine. For the MySQL of the LAMP, we use the Azure Database for MySQL to build the MySQL database.

Task 1: Create web server with Virtual Machine

  • Search Virtual Machine in the search bar
  • Click Create -> Virtual machine in the main panel
  • For Virtual machines name, type the name you prefer
  • For Region, choose East US 2
  • For Image, choose Ubuntu Server 18.04 LTS
  • For Size, choose Standard_DS1_V2
  • For Authentication type, choose password
  • For Username & Password, type the name you prefer
  • For Select inbound ports, choose HTTP (80), HTTPS (443), SSH (22)
  • Click Disks tab
  • For OS disk type, choose Standard SSD
  • Click Advanced tab
  • Click Enable user data
  • For user data, type the following code
#!/bin/bash
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
sudo apt-get install php7.3 php7.3-dev php7.3-xml -y — allow-unauthenticated
sudo apt-get update
source ~/.bashrc
sudo apt-get install libapache2-mod-php7.3 apache2
sudo ACCEPT_EULA=Y apt-get install php php-mysql php-curl php-gd php-json php-zip -y
sudo apt-get install php7.3-mysql
sudo phpenmod pdo_mysql
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
sudo a2enmod php7.3
sudo service apache2 restart
cd /var/www/html
sudo rm index.html
sudo wget
https://josie.blob.core.windows.net/lamp-materials/index.php
sudo wget
https://josie.blob.core.windows.net/lamp-materials/login.php
sudo wget
https://josie.blob.core.windows.net/lamp-materials/style.css
  • Click Review + create & Create
  • Click Go to Resource
  • Copy Virtual machine Public IP address to browser and check the website

Task 2: Create Azure Databases for MySQL servers

  • Type MYSQL at the search bar, and choose Azure Databases for MySQL servers
  • Click Create in the main panel
  • On the deployment options page, select Single server and click Create
  • Server detail settings

For Server name, type a unique name

For Location, choose (US) East US 2

For Compute + storage ,choose Basic, 1 vCores, 5 GB storage

  • Administrator account settings
  • For Admin username, type “adminlampdb”
  • For Password and Confirm password, type “Lamp4@pass”
  • Click Review + create & Create
  • Click Create
  • After creating, please click Go to Resource

Task 3: Configure MySQL server settings

  • Configure a server-level firewall rule
  • Go to Connection security from the left pane
  • Allow access to Azure Services and click Yes
  • Click Add 0.0.0.0 -255.255.255.255 ( Only used for testing )
  • DISABLED Enforce SSL connection ( Only used for testing )
  • Click Save
  • Configure Server parameters
  • Click Server parameters
  • The below sets the character_set_server to the value UTF8
  • Save changes

Task 4 : Connect to SQL database

  • Back to the VM’s website
  • Use the following information to connect to the SQL
  • Server Name: “your server name”
  • Server admin login name: “ your admin login name ”
  • Password: Lamp4@pass
  • If you see the data, it mean complete the lab

Conclusion

We now have learned how to:

  • Build a web server on Azure Virtual Machine
  • Deploy an Azure database for MySQL
  • Build the connection between web server and MySQL Database

--

--