Creating a LAMP Stack

Linux, Apache, MySQL & PHP

Posted by Tyler on January 29, 2024

Welcome to my first project. Unlike the other projects I plan to upload, this was created before the blog and so is looking back on what I did.
If you would like to try this project yourself more detailed instructions can be found here


LAMP is an Acronym for Linux, Apache, MySQL and PHP. To begin the project, I first had to set up an environment where the LAMP Stack was going to live. I created the below illustration to show how I configured this. Please note that this is not a highly available configuration and I would advise against implementing this this for production applications.

AWS Cloud Structure
Linux
Once the environment was setup, I fired up an EC2 instance using Ubuntu 22.04. I associated an elastic IP and configured a security group (SG) to allow traffic from my Home IP. Next, I created a user and configured Uncomplicated Firewall (UFW) to allow SSH traffic.
Whilst on this step I also added a DNS A record to point at this elastic IP address.

ApacheLanding Page
Now that the server was up and running, next was connecting to the server via SSH, installing Apache and modifying ufw to allow Apache traffic through on port 80. The server could now be reached via http://(elastic_ip) which would take me to the Apache2 landing page.

MySQL
Next I installed MySQL however configuring it was a little more difficult.  I needed to run a command “sudo mysql_secure_installation” to secure my MySQL installation however this was failing due to the script attempting to set a password on the Root MySQL account. This was resolved by running:
“ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';”.

PHP
 The final install was PHP. In addition to the PHP package I also installed php-mysql and libapache2-mod-php in order for it to work correctly with MySql and Apache.

Virtual Host
Now that everything was installed I created a virtual host in /var/www/ as well as updating /etc/apache2/sites-available to look at tylerhardwick.co.uk and uploading an index.html file.

MySQL Database
The penultimate step was creating a MySQL database. In my case I created a database called “tyler” with a table called “todo”. I then added a couple of entries to “tyler.todo”.

I then created a “todo.php” script which essentially connects to the MySQL database and adds each item in the table as an item in a list <li>.

| item_id | content              |
+---------+--------------------------+
|       1 | Finish this list       |
|       2 | Finish this project  |
+---------+--------------------------+

Obtaining SSL Cert
The final step was obtaining SSL to encrypt the website so that it cold be accessed via port 443 for HTTPS traffic. The first part of this process was allowing HTTPS traffic through the UFW. I enabled “Apache Full” which allows traffic on both :443 and :80 and disabled “Apache” which is :80 only. Next  I installed and ran Certbot which uses Let’s Encrypt SA. Certbot automatically generated and modified the correct files in /etc/apache2/sites-available and allowed HTTPS traffic to the site.

Finished Product


  • test

    test