Ultimate Guide: Installing LAMP on Ubuntu [Step-by-Step] 2023

When setting up a web server on Ubuntu, one of the most popular configurations is LAMP, which stands for Linux, Apache, MySQL, and PHP. In this comprehensive guide, we will walk you through the step-by-step process of installing and configuring LAMP on your Ubuntu server. By the end of this tutorial, you’ll have a fully functional web server ready to host your websites and web applications.

Step 1: Updating Your System

Before diving into the installation process, it’s essential to ensure your system is up to date. Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade
Bash

This ensures you have the latest software packages and security updates.

Step 2: Installing Apache

Apache is a widely used web server that will serve as the backbone of our LAMP stack. To install Apache, use the following command:

sudo apt install apache2
Bash

After the installation, Apache should start automatically. You can verify its status by running:

sudo systemctl status apache2
Bash

Step 3: Installing MySQL

MySQL is a popular relational database management system. To install MySQL, run:

sudo apt install mysql-server
Bash

During the installation, you will be prompted to set the root password for MySQL. Make sure to choose a strong password and remember it for future use.

After the installation, you can run a security script that comes with MySQL to enhance its security:

sudo mysql_secure_installation
Bash

Follow the prompts to secure your MySQL installation.

Step 4: Installing PHP

PHP is a server-side scripting language used to develop dynamic web pages. To install PHP, run:

sudo apt install php libapache2-mod-php php-mysql
Bash

Once the installation is complete, you need to configure Apache to process PHP files. Open the Apache configuration file:

sudo nano /etc/apache2/mods-enabled/dir.conf
Bash

Add “index.php” at the beginning of the DirectoryIndex line, so it looks like this:

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
Bash

Save and close the file.

Step 5: Testing PHP

To confirm that PHP is working correctly, create a test PHP file in the Apache web root directory:

sudo nano /var/www/html/info.php
Bash

Add the following PHP code:

<?php
phpinfo();
Bash

Save and close the file. Now, access the test page in your web browser by navigating to “http://your_server_ip/info.php.” If PHP is installed correctly, you will see a page displaying PHP configuration details.

Conclusion

Congratulations! You have successfully installed the LAMP stack on your Ubuntu server. You now have a fully functional web server capable of hosting websites and web applications like wordpress. Feel free to explore additional configurations and packages to suit your specific needs. Happy web development!

Leave a Reply

Your email address will not be published. Required fields are marked *