The LAMP stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps, Apache, MySQL and PHP (LAMP) software stack.
- Linux: The operating system (OS) makes up our first layer.
- Apache: The second layer consists of web server software.
- MySQL: Third layer is server hhere databases stored.
- PHP: The scripting layer consists of PHP and other similar web programming languages. Websites and Web Applications run within php.
In order to complete this tutorial, you will need :
- you will need to have an Ubuntu 18.04 server.
- Update your system:
sudo apt update && sudo apt upgrade
Install Apache using Ubuntu’s package manager,
sudo apt update sudo apt install apache2
to verify that everything went as planned by visiting your server’s public IP address in your web browser http://your_server_ip
And you can use
curl utility to verify that apache is up:
sudo apt install curl curl http://your_server_ip
3. Installing MySQL
Now that you have your web server up and running, use
apt to acquire and install this software:
sudo apt install mysql-server
When the installation is complete, run a simple security script that comes pre-installed with MySQL which will remove some dangerous defaults and lock down access to your database system:
4. Installing PHP
PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free
to install php run the following command :
sudo apt install php libapache2-mod-php php-mysql
This should install PHP without any problems. We’ll test this in a moment.
In most cases, you will want to modify the way that Apache serves
files when a directory is requested. Currently, if a user requests a
directory from the server, Apache will first look for a file called
index.html. We want to tell the web server to prefer PHP files over others, so make Apache look for an
index.php file first.
To do this, type this command to open the
dir.conf file in a text editor with root privileges:
sudo nano /etc/apache2/mods-enabled/dir.conf
It will look like this: /etc/apache2/mods-enabled/dir.conf
<IfModule mod_dir.c> DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule>
Move the PHP index file (highlighted above) to the first position after the
DirectoryIndex specification, like this:
<IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm </IfModule>
When you are finished, save and close the file by pressing
CTRL+X. Confirm the save by typing
Y and then hit
ENTER to verify the file save location.
After this, restart the Apache web server in order for your changes to be recognized. Do this by typing this:
sudo systemctl restart apache2
You can also check on the status of the
apache2 service using
sudo systemctl status apache2
5. Testing PHP Processing on your Web Server
In order to test that your system is configured properly for PHP, create a very basic PHP script called
In order for Apache to find this file and serve it correctly, it must
be saved to a very specific directory, which is called the “web root”.
In Ubuntu 18.04, this directory is located at
/var/www/html/. Create the file at that location by running:
sudo nano /var/www/html/info.php
This will open a blank file. Add the following text, which is valid PHP code, inside the file: info.php
<?php phpinfo(); ?>
When you are finished, save and close the file.
Now you can test whether your web server is able to correctly display content generated by this PHP script. To try this out, visit this page in your web browser. You’ll need your server’s public IP address again.
The address you will want to visit in your browser is: