Blog · WebJi® India

How to Install the LAMP Stack on Ubuntu

Quick answer: How to Install the LAMP Stack on Ubuntu from WebJi®, billed in INR with 18% GST on the invoice. Email support@webji.services is 24/7 in Hindi and English (average first reply under 60 minutes). Phone +91 141 4941811 is business hours only. The company has been in this business since 2005.
✓ In business since 2005✓ INR + GST billing✓ 24/7 Email Support — avg reply < 60 min
Festive Diwali scene with marigold garlands, gift boxes, diyas and a laptop with a shopping cart — how to install lamp on ubuntu

What a LAMP stack is

A LAMP stack is four cooperating layers on Linux: Apache (the A) receives HTTP requests and serves them; MySQL/MariaDB (the M) stores the data; PHP (the P) executes the application. Linux is the floor everything stands on. On an Ubuntu VPS:

  1. sudo apt update && sudo apt upgrade -y — always first.
  2. Apache and firewall: sudo apt install apache2 -y, then ufw allow 'Apache Full' (and OpenSSH before enabling ufw).
  3. Database: sudo apt install mysql-server -y (or mariadb-server), then sudo mysql_secure_installation.
  4. PHP: sudo apt install php libapache2-mod-php php-mysql -y plus your app's modules.
  5. Test: create /var/www/html/info.php with <?php phpinfo(); — visit it, confirm, delete immediately.

One database plus one dedicated user per application comes next; the MySQL setup guide details it.

Step 1: Apache and firewall

On Ubuntu 22.04/24.04 LTS, the honest summary is that defaults matter more than brand names — a well-set budget plan outranks a mis-tuned premium one. WebJi® documents its defaults openly and adjusts them per ticket when workloads need it.

Festive Diwali scene with marigold garlands, gift boxes, diyas and a laptop with a shopping cart — how to install lamp on ubuntu

Step 2: MySQL or MariaDB setup

Step two, MySQL or MariaDB: sudo apt install mysql-server -y installs the distribution's MySQL, or sudo apt install mariadb-server for the MariaDB line — identical steps after. Ubuntu's MySQL root uses auth_socket, meaning sudo mysql works without a password — by design, not a bug.

Immediately run sudo mysql_secure_installation: it walks setting a root password method (VALIDATE PASSWORD plugin optional), removing anonymous users, disallowing remote root login, removing the test database, and reloading privileges — answer Y to the removals. Verify: sudo systemctl status mysql, then connect with sudo mysql and SELECT version();. Two habits now save later pain. Create application users with passwords rather than using root, and note that PHP connects over the local socket by default — host localhost is correct in wp-config and .env files.

Step 3: PHP and modules

How this plays out with MariaDB and MySQL: settings that look cosmetic usually decide page speed and uptime under real traffic. The defaults WebJi® ships are tuned for Indian network conditions, and support can review your setup on request.

Step 4: test page and phpinfo

test page and phpinfo. Create a temporary file that only calls phpinfo(), open it in the browser, and read the PHP version, memory_limit and loaded extensions. Delete the file as soon as you have checked it. A blank page usually means the file is outside the document root, or PHP is not enabled for that site.

Creating databases and users

Two practical notes on UFW firewall rules: it interacts directly with caching and database response, and misconfiguration is the most common cause of 'hosting is slow' tickets. WebJi® support checks it as part of standard migrations.

Common install errors

Common install errors. Do the change this heading names on one site first, then check it in a private browser window or in the mail client, depending on the topic. Change one setting at a time, and undo it if the result is wrong before you try the next. If you want the Jaipur desk to look with you, email support@webji.services — that mailbox is staffed 24/7 in Hindi and English. Phone +91 141 4941811 is business hours only.

Frequently Asked Questions

How do I install a LAMP stack on Ubuntu?

A LAMP stack is four cooperating layers on Linux: Apache (the A) receives HTTP requests and serves them; MySQL/MariaDB (the M) stores the data; PHP (the P) executes the application. Linux is the floor everything stands on. On an Ubuntu VPS:

In what order should I install Apache, MySQL and PHP?

A LAMP stack is four cooperating layers on Linux: Apache (the A) receives HTTP requests and serves them; MySQL/MariaDB (the M) stores the data; PHP (the P) executes the application. Linux is the floor everything stands on. On an Ubuntu VPS: The question here is: In what order should I install Apache, MySQL and PHP.

How do I open the firewall for Apache on Ubuntu?

A LAMP stack is four cooperating layers on Linux: Apache (the A) receives HTTP requests and serves them; MySQL/MariaDB (the M) stores the data; PHP (the P) executes the application. Linux is the floor everything stands on. On an Ubuntu VPS: The question here is: How do I open the firewall for Apache on Ubuntu.

How do I test that PHP works with Apache?

A LAMP stack is four cooperating layers on Linux: Apache (the A) receives HTTP requests and serves them; MySQL/MariaDB (the M) stores the data; PHP (the P) executes the application. Linux is the floor everything stands on. On an Ubuntu VPS: The question here is: How do I test that PHP works with Apache.

MariaDB or MySQL for an Ubuntu server?

Step two, MySQL or MariaDB: sudo apt install mysql-server -y installs the distribution's MySQL, or sudo apt install mariadb-server for the MariaDB line — identical steps after. Ubuntu's MySQL root uses auth_socket, meaning sudo mysql works without a password — by design, not a bug.

How do I create a database and user after installing LAMP?

One database plus one dedicated user per application comes next; the MySQL setup guide details it.

Is WebJi® an Indian company?

Yes. WebJi® is headquartered in Jaipur, Rajasthan and has operated since 2005. Billing, support and governance all run from India.

Do you provide GST invoices?

Every purchase and renewal gets a GST invoice with our GSTIN, and hosting prices are quoted exclusive of 18% GST. Claim input credit as applicable.

Need help with this?

WebJi® support does it for you — free. Talk to our Jaipur team →