- L - Linux
- A - Apache
- M - MySQL
- P - PHP
We will be using Ubuntu Virtual Machine through AZURE.
After creating the VM, Login and we will be using the following commands to update the VM
sudo apt update
sudo apt upgradeApache is a simple web server that is very popular. It is often used to serve PHP applications, but it can also serve static HTML content.
Then we will be installing the following packages
sudo apt install apache2- The apache2 package installs Apache 2.4 and the default configuration is to run Apache as a daemon. Once the apache2 package finishes installing, you can go to your server’s IP address in your browser and see the default Apache landing page.
Then check the status of the apache2 service
sudo systemctl status apache2This will show you the status of the apache2 service. If it is not running, you can start it with this command:
sudo systemctl start apache2You could also use curl to check if the apache2 service is running
curl http://localhost:80This display the apache2 default page in the terminal as text.
To install MySQL, run the following command:
sudo apt install mysql-server -yThen login to MySQL with the following command:
sudo mysqlCreate a new user and grant privileges to the user
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;Check if the user is created
SELECT user FROM mysql.user;Then exit MySQL with the following command:
exitTo start the MySQL interactive shell with the following command:
sudo mysql -u admin -pEnter the password you created for the admin user. You should now be in the MySQL shell.
To exit the MySQL shell, run the following command:
exitPhp is a server-side scripting language designed for web development but also used as a general-purpose programming language.
To install PHP, run the following command:
sudo apt install php libapache2-mod-php php-mysql -yThese packages tell Ubuntu that you want to install PHP, the Apache PHP module, and MySQL support for PHP. Also, the -y flag is used to skip the confirmation prompt.
NB: To stop using sudo, you can add your user to the www-data group. This will allow you to run commands as the www-data user without using sudo.
Check if the php is installed
php -vIf you got here with no errors, you have successfully installed
- Apache,
- MySQL, and
- PHP on your Ubuntu server.
Now we will be creating a simple PHP file to test if the PHP is working.
Create a new directory in the /var/www directory
sudo mkdir /var/www/projectlampThen assign ownership of the directory with current system user. This is to avoid permission issues.
sudo chown -R $USER:$USER /var/www/projectlampThis makes the current user the owner of the directory and the group owner as well.
Then create and open a new configuration file in the /etc/apache2/sites-available directory
sudo nano /etc/apache2/sites-available/projectlamp.confThen add the following lines to the file:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName projectlamp
ServerAlias www.projectlamp
DocumentRoot /var/www/projectlamp
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>This configuration file tells Apache to serve the /var/www/projectlamp directory when someone visits projectlamp in their browser.
You can use any name you want for the ServerName and ServerAlias directives. The ServerAlias directive is optional, but it is useful if you want to use a domain name instead of an IP address to access your site.
- Verify available sites
000-default.conf default-ssl.conf projectlamp.confThen enable the new configuration file with the following command:
sudo a2ensite projectlamp.confThen disable the default configuration file with the following command to avoid conflict:
sudo a2dissite 000-default.confThen reload Apache with the following command:
sudo systemctl reload apache2Then create a new index.php file in the /var/www/projectlamp directory
sudo nano /var/www/projectlamp/index.phpThen add the following lines to the file:
<?php
phpinfo();
?>This file will display information about your PHP installation when you visit projectlamp in your browser through public dns or ip address.
The default configuration for Apache does not allow PHP files to be executed. To enable PHP, you need to edit the /etc/apache2/mods-enabled/dir.conf file.
sudo nano /etc/apache2/mods-enabled/dir.confThen change the following line:
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>TO
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>Then reload Apache with the following command:
sudo systemctl reload apache2Then open your browser and visit projectlamp through public dns or ip address. You should see the PHP information page.
Congratulations! You have successfully installed Apache, MySQL, and PHP on your Ubuntu server.
It is best to remove the php file as it may contain sensitive information.
sudo rm /var/www/projectlamp/index.phpTo destroy the VM, go to the Azure portal and delete the resource group.
Explore from here !!!







