Trending News

Blog

Install LAMP on Ubuntu: Apache vs Nginx for Building an Ubuntu Web Server
Blog

Install LAMP on Ubuntu: Apache vs Nginx for Building an Ubuntu Web Server 

Pick Apache if you want the easiest classic LAMP setup on Ubuntu; pick Nginx if you care about speed under heavy traffic. Apache still powers a huge slice of the web, while Nginx is very popular for high traffic sites and reverse proxies, with both sitting at the top of web server usage charts [source: W3Techs]. If you are building a small WordPress site, Apache is usually the smoother path. If you are serving lots of static files or many users at once, Nginx may feel snappier.

TLDR: Use Apache for a simple Ubuntu LAMP server with PHP and MySQL. Use Nginx if you expect more traffic and want better static file performance. For example, a blog with 2,000 visits per month will be fine on Apache, while a shop with 80,000 monthly visits may benefit from Nginx plus PHP FPM. If you are new, start with Apache first, then switch later if traffic grows.

What is LAMP?

LAMP means Linux, Apache, MySQL, and PHP. On Ubuntu, Linux is already there. You add the other parts.

  • Linux: The operating system. In this case, Ubuntu.
  • Apache: The web server. It answers browser requests.
  • MySQL: The database. MariaDB is also common.
  • PHP: The language used by WordPress, Laravel, and many apps.

If you use Nginx instead of Apache, people often call it LEMP. The “E” sounds like “engine x.” Yes, naming things in tech is weird.

Find Server IP in Ubuntu 20.04 Yehiweb

Apache vs Nginx in plain English

Apache is like a friendly old toolbox. It has many built in features. It works well with .htaccess files. That matters for WordPress and shared hosting style setups.

Nginx is like a tiny, sharp racing bike. It is fast. It handles many connections well. It is great at serving images, CSS, JavaScript, and acting as a reverse proxy.

The catch is configuration. Apache often lets apps control rules with .htaccess. Nginx does not. You must put rewrite rules in the server config. This is cleaner. It is also annoying when a plugin gives you Apache rules and says, “good luck.”

When to choose Apache

Choose Apache if you want the classic LAMP stack with fewer surprises.

  • You are new to Ubuntu servers.
  • You want to host WordPress fast.
  • You need .htaccess support.
  • You follow tutorials written for cPanel or shared hosting.
  • You want simple PHP setup with libapache2-mod-php.

Apache is forgiving. That is its superpower. You can enable modules with simple commands. You can place rewrite rules inside your site folder. Many old apps expect Apache, and they behave nicely there.

Install Apache LAMP on Ubuntu

Run these commands on Ubuntu 22.04 or 24.04:

  1. sudo apt update
  2. sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
  3. sudo systemctl enable apache2
  4. sudo systemctl start apache2
  5. sudo mysql_secure_installation

Now test Apache:

http://your_server_ip

You should see the Ubuntu Apache page. It is not pretty. It is proof. That counts.

To test PHP, create a file:

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

Add this:

<?php phpinfo(); ?>

Visit:

http://your_server_ip/info.php

If the PHP info page appears, your LAMP stack works. Then delete the file. Seriously. Do not leave it online.

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

When to choose Nginx

Choose Nginx if performance matters more than easy drop in setup.

  • You expect many visitors at the same time.
  • You serve lots of images or downloads.
  • You want a reverse proxy for Node.js, Python, or containers.
  • You like clean config files.
  • You are comfortable editing server blocks.

Nginx often uses less memory than Apache under many open connections. This can matter on a small VPS with 1 GB RAM. It drives me crazy that one bad config line can break the whole site, but once it is tuned, Nginx feels crisp.

Image not found in postmeta

Install Nginx with MySQL and PHP on Ubuntu

This is not classic LAMP. It is a LEMP style setup. Still, it builds the same kind of Ubuntu web server.

  1. sudo apt update
  2. sudo apt install nginx mysql-server php-fpm php-mysql
  3. sudo systemctl enable nginx
  4. sudo systemctl start nginx
  5. sudo mysql_secure_installation

Now create a basic Nginx server block:

sudo nano /etc/nginx/sites-available/example

Add a simple PHP setup:

server { listen 80; root /var/www/html; index index.php index.html; server_name your_domain_or_ip; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.3-fpm.sock; } }

Then enable it:

  1. sudo ln -s /etc/nginx/sites-available/example /etc/nginx/sites-enabled/
  2. sudo nginx -t
  3. sudo systemctl reload nginx

If nginx -t says the config is okay, you are safe to reload. If not, read the error. It often points to the exact line causing trouble.

Security steps you should not skip

Fresh servers are noisy places. Bots will knock on the door within minutes. Keep your setup boring and locked down.

  • Enable the firewall: sudo ufw allow OpenSSH
  • Allow web traffic: sudo ufw allow 'Apache Full' or sudo ufw allow 'Nginx Full'
  • Turn on the firewall: sudo ufw enable
  • Install SSL with Certbot.
  • Use strong database passwords.
  • Update packages often with sudo apt update && sudo apt upgrade.

For SSL, use Let’s Encrypt. It is free and trusted by browsers. Most sites should have HTTPS from day one.

Performance comparison

Here is the simple version.

  • Apache: Great compatibility. Easy rewrites. Nice for WordPress beginners.
  • Nginx: Great speed for static files. Strong under many connections.
  • Apache: Can use more memory with busy traffic.
  • Nginx: Needs PHP FPM and more manual config.

For a small site, the difference may be tiny. Your theme, plugins, database queries, and images may slow things down more than the server choice. A 5 MB homepage is still a 5 MB problem. No web server can magically fix that.

Best choice for common projects

  • Personal blog: Apache.
  • WordPress site: Apache for ease, Nginx for scale.
  • Laravel app: Either one works well.
  • Static site: Nginx.
  • Small business site: Apache if you manage it yourself.
  • API gateway or reverse proxy: Nginx.
  • Learning Linux hosting: Apache first.

Can you use both?

Yes. Many admins run Nginx in front of Apache. Nginx handles public traffic and static files. Apache handles app logic behind it.

This works well, but it adds more moving parts. For your first Ubuntu web server, skip that unless you need it. One server is easier to debug at 1 a.m. when your homepage is blank and your coffee is gone.

Final pick

If you want the fastest path to a working Ubuntu web server, install Apache, MySQL, and PHP. That is the classic LAMP setup. It is friendly, common, and well documented.

If you want lean performance and can handle stricter config, choose Nginx with PHP FPM. It is a great choice for busy sites and modern app hosting.

Simple rule: beginners should start with Apache. Performance focused users should pick Nginx. Either way, keep the server updated, use HTTPS, and do not leave test files sitting in public folders like digital banana peels.

Related posts

Leave a Reply

Required fields are marked *