Setup LAMP Stack For Web Development In Ubuntu 22.04

Setup LAMP Stack For Web Development In Ubuntu 22.04

LAMP stack is a set of open-source software which can prepare your local environment capable for PHP web development. In this tutorial we will know how can we setup LAMP stack in our local machine.

So, let’s start the process…

First of all we need to update our package manager

sudo apt update
sudo apt upgrade

Then we need to install Apache web server:

sudo apt install apache2

Start Apache and enable it to start on boot:

sudo systemctl start apache2
sudo systemctl enable apache2

Now we need to install MySQL database in our local machine:

sudo apt install mysql-server

During the installation, you will be prompted to set a root password for MySQL. Start the MySQL service and enable it to start on boot:

sudo systemctl start mysql
sudo systemctl enable mysql

Now we are in the last step of MySQL setup. We need to secure the mysql installation. For this we can use the following code:

sudo mysql_secure_installation

Now we need to install PHP with there required Apache module. for this we need to run the following code:

sudo apt install php8.1 libapache2-mod-php8.1 php8.1-mysql

Let’s test the PHP installation:

sudo echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Edit the Apache default configuration file to allow the use of .htaccess files:

sudo nano /etc/apache2/sites-available/000-default.conf

Add the following block within the <VirtualHost> section:

<Directory /var/www/html>
    AllowOverride All
</Directory>

Now save the file & restart the Apache service:

sudo systemctl restart apache2

Congratulation! We setup the LAMP server in our local machine. Now we can run any PHP or Laravel project in our localhost.

Thanks for stay with us. Subscribe for every latest programming related solutions & tutorials..
Happy coding…..

1 Comment

Leave a Reply

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