Linux

Setting Up a LAMP Stack on Ubuntu: A Step-by-Step Tutorial

If you want to run a dynamic website or web application, a LAMP stack is a great choice. LAMP is an acronym for Linux, Apache, MySQL, and PHP, and it’s a combination of open source software that is commonly used to power web servers and dynamic websites.

In this tutorial, we’ll guide you through the process of setting up a LAMP stack on an Ubuntu machine. We’ll cover everything from installing Ubuntu, to setting up Apache, MySQL, and PHP, to configuring your web server.

Step No. 1: Ubuntu Installation

To start, install Ubuntu on your device. Go to ubuntu.com to download the latest version of Ubuntu. After downloading the ISO file, create a bootable USB drive or DVD and start the installation process.

Step No. 2: Apache Installation

Once you have installed Ubuntu, the next step is to install Apache. Apache is a commonly utilized web server for serving web pages on the internet. To install Apache, open a terminal and input this command:

`sudo apt-get install apache2`

Once the installation is complete, you can start the Apache service by typing the following command:

`sudo systemctl start apache2`

You can also check the status of the Apache service by typing:

`sudo systemctl status apache2`

Step No. 3: MySQL Installation

Next, proceed to install MySQL which is a well-known open source database management system. To install MySQL, open a terminal and type the following command:

`sudo apt-get install mysql-server`

When installing, you’ll be prompted to set a root password for MySQL. Take note of the password for it will be needed later.

Once the installation is complete, you can start the MySQL service by typing the following command:

`sudo systemctl start mysql`

You can also check the status of the MySQL service by typing:

`sudo systemctl status mysql`

Step No. 4: PHP Installation

To complete the process, install PHP, a commonly-used server-side scripting language for dynamic web page creation. Open a terminal window and type in the following command:

`sudo apt-get install php libapache2-mod-php php-mysql`

This will download and install PHP and the necessary modules on your machine.

Step No.5: Configure Apache

Now that you have installed Apache, MySQL, and PHP, you need to configure Apache to work with PHP by launching a terminal and running this command:

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

This command opens the Apache configuration file using the Nano text editor. You need to modify this file to tell Apache to use PHP when serving web pages.

Find the line that says:

`DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm`

And change it to:

`DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm`

Ensure to save the file before exiting the text editor.

Step No. 6: Test Your Setup

Now that you have set up your LAMP stack, it’s time to test it to ensure that everything is working correctly.

Generate a new file named info.php in the /var/www/html directory. Then launch a terminal and run this command: 

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

Paste this code `<?php phpinfo(); ?> ` into the file.

Ensure to save the file before exiting the text editor.

To check if everything was done correctly, go to  http://localhost/info.php. You’ll see a page with information regarding your PHP installation. If this page appears, it confirms that your LAMP stack is functioning as expected.

Conclusion

In this tutorial, we walked you through the process of setting up a LAMP stack on an Ubuntu machine. We covered everything from installing Ubuntu, to setting up Apache, MySQL, and PHP, to configuring your web server. With this setup, you can develop and deploy dynamic websites and web applications on your own Ubuntu machine.

For more tutorials, browse www.intogeeks.com

 

 

Related Articles

Leave a Reply

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

Back to top button