How to Install LAMP (Linux, Apache, MySQL, PHP) on Ubuntu

How to Install LAMP (Linux, Apache, MySQL, PHP) on Ubuntu

How to Install LAMP on Ubuntu

 Step 1: Update Your Package List

sudo apt update sudo apt upgrade -y

Step 2: Install Apache Web Server

sudo apt install apache2 -y

Check if Apache is running:

sudo systemctl status apache2

Test in browser:
Visit http://localhost/ or http://your-server-ip/
You should see the Apache2 Ubuntu Default Page.

Step 3: Install MySQL (Database)

sudo apt install mysql-server -y

Secure the MySQL installation:

sudo mysql_secure_installation

You’ll be asked to:

  • Set root password (if not set by default)

  • Remove anonymous users? → Yes

  • Disallow root login remotely? → Yes

  • Remove test database? → Yes

  • Reload the privilege tables? → Yes

Log in to test:

sudo mysql

Then exit:

exit;

Step 4: Install PHP and Required Modules

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

You can install more PHP extensions if needed, like:

sudo apt install php-cli php-curl php-gd php-mbstring php-xml php-zip -y

Check PHP version:

php -v

Step 5: Test PHP

Create a PHP file to test if it works:

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

Paste this:

<?php phpinfo(); ?>

Save and exit.

Visit in browser:
http://localhost/info.php

You should see the PHP info page.

After testing, delete the file to avoid security risk:

sudo rm /var/www/html/info.php

Step 6: Enable Apache mod_rewrite (Optional but common)

sudo a2enmod rewrite sudo systemctl restart apache2

You're Done!

The LAMP stack is now fully installed on your Ubuntu system!

You can now:

  • Run PHP applications (like Laravel, WordPress)

  • Host MySQL databases

  • Use Apache as your web server

Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close