-
Signed up for an AWS account.
-
Logged in as IAM user
-
Launched an EC2 instance
-
I selelected the Ubuntu free tier instance
-
I set the required configurations (Enabled public IP, security group, and key pair) and finally launched the instance.
-
Next I SSH into the instance using Windows Terminal
-
In the Terminal, I typed cd Downloads to navigate to the locxcation of my key-pair.
-
Inside the Downloads directory, I connect to my instance using its Public DNS.
-
Install Apache using Ubuntu’s package manager ‘apt', Run the following commands: To update a list of packages in package manager: sudo apt update
-
To run apache2 package installation: sudo apt install apache2
-
Next, verify that Apache2 is running as a service in the OS. run: sudo systemctl status apache2
-
The green light indicates Apache2 is running.
-
Open port 80 on the Ubuntu instance to allow access from the internet.
-
Access the Apache2 service locally in our Ubuntu shell by running: curl http://localhost:80 or curl http://127.0.0.1:80 This command would output the Apache2 payload indicating that it is accessible locally in the Ubuntu shell.
-
Next, test that Apache HTTP server can respond to requests from the Internet. Open a browser and type the public IP of the Ubutun instance: http://3.235.248.184/:80 This outputs the Apache2 default page.
In this step, I install a Database Management System (DBMS) to be able to store and manage data for the site in a relational database.
-
Run ‘apt’ to acquire and install this software, run: sudo apt install mysql-server
-
Confirm intallation by typing Y when prompted.
-
Once installation is complete, log in to the MySQL console by running: sudo mysql
-
Next, run a security script that comes pre-installed with MySQL, to remove some insecure default settings and lock down access to your database system. run: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'PassWord.1'; then exit MySQL shell by typing exit and enter.
-
Run interactive script by typing: sudo mysql_secure_installation and following the instrustions.
-
Next, test that login to MySQL console works. Run: sudo mysql -p
-
Type exit and enter to exit console.
-
To install these 3 packages at once, run: sudo apt install php libapache2-mod-php php-mysql
-
After installation is done, run the following command to confirm your PHP version: php -v
-
At this point, your LAMP stack is completely installed and fully operational.
- Setting up a domain called projectlamp. Create the directory for projectlamp using ‘mkdir’. Run: sudo mkdir /var/www/projectlamp
- assign ownership of the directory with your current system user, run: sudo chown -R $USER:$USER /var/www/projectlamp
- Next, create and open a new configuration file in Apache’s sites-available directory. Tpye: sudo vi /etc/apache2/sites-available/projectlamp.conf
- This will create a new blank file. Paste in the following bare-bones configuration by hitting on i on the keyboard to enter the insert mode, and paste the text: *<VirtualHost :80> ServerName projectlamp ServerAlias www.projectlamp ServerAdmin webmaster@localhost DocumentRoot /var/www/projectlamp ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined
5.To save and close the file. Hit the esc button on the keyboard, Type :, Type wq. w for write and q for quit and Hit ENTER to save the file. 6. use the ls command to show the new file in the sites-available directory: sudo ls /etc/apache2/sites-available
-
Next, use a2ensite command to enable the new virtual host: sudo a2ensite projectlamp
-
Disable the default website that comes installed with Apache. type: sudo a2dissite 000-default
-
Esure your configuration file doesn’t contain syntax errors, run: sudo apache2ctl configtest
-
Finally, reload Apache so these changes take effect: sudo systemctl reload apache2
-
The website is active, but the web root /var/www/projectlamp is still empty. Create an index.html file in that location so that we can test that the virtual host works as expected: sudo echo 'Hello LAMP from hostname' $(curl -s http://169.254.169.254/latest/meta-data/public-hostname) 'with public IP' $(curl -s http://169.254.169.254/latest/meta-data/public-ipv4) > /var/www/projectlamp/index.html
-
Relaod the public IP to see changes to the apache2 default page.
- With the default DirectoryIndex settings on Apache, a file named index.html will always take precedence over an index.php file. To make index.php file tak precedence need to edit the /etc/apache2/mods-enabled/dir.conf file and change the order in which the index.php file is listed within the DirectoryIndex directive.
- Run: sudo vim /etc/apache2/mods-enabled/dir.conf then: #Change this: #DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm #To this: DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
- Save and close file.
- Next, reload Apache so the changes take effect, type: sudo systemctl reload apache2
- Finally, we will create a PHP script to test that PHP is correctly installed and configured on your server. Create a new file named index.php inside the custom web root folder, run: vim /var/www/projectlamp/index.php
- This will open a blank file. Add the PHP code: <?php phpinfo();
- Save and close the file, then refresh the page to see changes.