In this tutorial, we'll learn how to install and configure LAMP stack on Ubuntu 24.04 server.
Setting up a powerful and efficient web server is one of the first things every web developer or system administrator needs to do. With the release of Ubuntu 25.04, it's the perfect time to build a fresh and optimized server using the LEMP stack – Linux, Nginx, MariaDB, and PHP. This guide provides you with a professional, step-by-step approach from basic installation to advanced configurations.
Prerequisites
Before we begin, let’s ensure we have the following in place:
- A Ubuntu 25.04 dedicated server or KVM VPS.
- A basic programming knowledge.
- A domain name pointing at server IP.
Step 1: Update Ubuntu 25.04 Packages
Before starting, always ensure your server is up-to-date.
sudo apt update && sudo apt upgrade -y
Step 2: Install Nginx on Ubuntu 25.04
Nginx is a lightweight and fast web server used to serve static and dynamic content.
sudo apt install nginx -y
Once installed, enable and start the service:
sudo systemctl enable nginx
sudo systemctl start nginx
Allow HTTP and HTTPS through the firewall:
sudo ufw allow 'Nginx Full'
Check if Nginx is running:
sudo systemctl status nginx
Test in browser: open http://your_server_ip
and you should see the Nginx welcome page.
Step 3: Install MariaDB (MySQL Alternative)
MariaDB is a fast, secure, and reliable database server.
sudo apt install mariadb-server mariadb-client -y
Secure your database installation:
sudo mysql_secure_installation
Follow the prompts to set root password, remove anonymous users, disable remote root login, and remove test databases.
Login to test:
sudo mysql -u root -p
Then exit with:
exit;
Step 4: Install PHP 8.3 and Necessary Modules
Ubuntu 25.04 supports PHP 8.3, the latest and fastest PHP version as of now.
sudo apt install php8.3-fpm php8.3-mysql php8.3-cli php8.3-curl php8.3-mbstring php8.3-xml php8.3-common php8.3-zip -y
Check PHP version:
php -v
Step 5: Configure Nginx to Use PHP Processor
Create a sample virtual host config:
sudo nano /etc/nginx/sites-available/example.com
Paste the following configuration:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Enable the site:
sudo mkdir -p /var/www/example.com
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Test config:
sudo nginx -t
Reload Nginx:
sudo systemctl reload nginx
Step 6: Create a PHP Test File
To verify PHP and Nginx are working:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/example.com/index.php
Visit http://your_server_ip/index.php
to see the PHP info page.
Step 7: Set Proper Permissions
Set ownership of your web root:
sudo chown -R www-data:www-data /var/www/example.com
Step 8: Advanced Configuration Tips
Enable Gzip Compression
Edit your Nginx config:
sudo nano /etc/nginx/nginx.conf
Add inside the http block:
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
Optimize PHP-FPM
Edit:
sudo nano /etc/php/8.3/fpm/php.ini
Tweak common settings:
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
max_execution_time = 300
Restart PHP-FPM:
sudo systemctl restart php8.3-fpm
Step 9: Enable HTTPS with Let’s Encrypt (Free SSL)
Install Certbot:
sudo apt install certbot python3-certbot-nginx -y
Run the command:
sudo certbot --nginx -d example.com -d www.example.com
Auto-renew setup:
sudo systemctl status certbot.timer
Step 10: Monitor and Secure Your Server
Install Fail2ban to protect against brute-force attacks:
sudo apt install fail2ban -y
Set up monitoring tools like htop, netstat, or more advanced ones like Netdata.
Final Thoughts
Congratulations! In this tutorial, we've learnt how to install and configure LAMP stack on Ubuntu 24.04 server, fully optimized for modern web hosting. Whether you're launching WordPress, Laravel, or a custom PHP project, this setup gives you security, speed, and scalability.
As a web hosting provider, I recommend always keeping your stack updated, monitoring resource usage, and using firewall rules and fail2ban to harden your server. This tutorial is part of our knowledge base — freely available to empower developers and entrepreneurs building on Linux.
Stay tuned for more Linux server tutorials and advanced DevOps configurations.