How to Install LAMP in Ubuntu 25.04 Plucky Puffin
In this guide, we will see how to install LAMP in Ubuntu 25.04 Plucky Puffin using apt, the default package manager.
Introduction
In our Linux Support interventions, LAMP (Linux, Apache, MySQL, PHP), LEMP (NginX) stacks and the like are critical for Web Apps, CMS and e-commerce such as WordPress, Magento, Drupal and many others.
To install LAMP in Ubuntu 25.04 Plucky Puffin we start by installing the Apache web server with HTTPS, the first component of the stack, which will be responsible for serving content.
To optimize web server performance, we recommend using PHP-FPM, mpm_event and HTTP2. Most websites use secure connections. We will also see how to generate a valid and free HTTPS certificate with Let's Encrypt.
Installing LAMP in Ubuntu 25.04
1. Install Apache2
By default, the mpm_prefork multi-process module is provided, which allows you to use mod_php or php8.3, the in-house interpreter. This approach is not recommended for heavily visited sites, since having reached the maximum number of threads, the web server stops responding until a thread is freed.
Let's install Apache2
sudo apt install apache2Let's make sure that the
mpm_preforkmodule is disabled, as it is a performance bottleneck.sudo a2dismod mpm_prefork.Let's enable
mpm_eventandhttp2.sudo a2enmod mpm_event http2.Let's restart Apache2.
sudo service apache2 restart
2. Install PHP-FPM
PHP-FPM is an alternative implementation of PHP FastCGI, known for its speed, three times faster than the classic module, with additional functionality. FPM is a real daemon that stays listening for PHP requests via a UNIX port or socket. It represents the P of our LAMP.
Let's install FPM and FastCGI.
sudo apt install php-fpmLet's enable the modules.
sudo a2enmod actions proxy_fcgi alias headersLet's restart the PHP FPM process.
sudo service php8.4-fpm restartLet's restart Apache2.
sudo service apache2 restart
PHP-FPM Virtual Host Configuration.
You can now configure all Apache2 virtual hosts to use FPM by adding this handler in their definition:
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>Testing PHP with info.php:
<?php
phpinfo();
phpinfo(INFO_MODULES);
?>Let's install the necessary modules and PHP-MySQL.
We can choose to install some of the most common modules.
sudo apt-get install php-pear \ php8.3-{mysql,curl,gd,intl,imap,mcrypt,ps,pspell,snmp,sqlite,tidy,xmlrpc,xsl}Alternatively, we can use the modules found in Plesk.
sudo apt-get install php-pear \ php8.3-{bcmath,enchant,imap,ldap,mysql,curl,dba,enchant,gd,intl,ldap,mbstring,mcrypt,odbc,opcache,pgsql,sqlite3,pspell,soap,tidy,xml,xmlrpc,xsl,zip}
3. Install Let's Encrypt for Free SSL Certificates.
Using Let's Encrypt and the certbot daemon, you can generate universally recognized, secure and free SSL certificates. You need to configure the DNS name of the website to reach the IP of our server.
Example of DNS configuration.
To configure DNS, we access our provider's panel and create a record of type "A".
mydomain.ext A 1.1.1.1We install Let's Encrypt and generate the SSL and TLS certificates.
sudo apt-get install certbot python3-certbot-apacheLet's create the Apache2 configuration.
sudo certbot --apacheLet's test the renewal of certificates.
sudo certbot renew --dry-run.We check that Cron's scheduled process for renewal is present.
sudo cat /etc/cron.d/certbot.If the resolution of our domain is correct, our virtual hosts will respond in HTTPS, returning the famous "green lock" to us on the browser.
Apache2 Virtual Hosts
HTTP Virtual Hosts
To configure an HTTP virtual host, we can use a simple definition like the one listed below. It is available in the /etc/apache2/sites-available directory as the default vhost, from which we can start.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>HTTPS Virtual Hosts.
HTTPS virtual hosts include the necessary paths for using SSL and enabling PHP.
<VirtualHost *:443>
ServerAdmin [email protected]
DocumentRoot "/var/www/data/online"
ServerName mydomain.ext
ServerAlias www.mydomain.ext
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Protocols h2 h2c http/1.1
SSLEngine on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/mydomain.ext/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.ext/privkey.pem
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
</VirtualHost>4. Install MySQL or MariaDB
To install MySQL or MariaDB, we use the corresponding packages mysql-server and mariadb-server.
To install MySQL server:
sudo apt install mysql-serverTo install MariaDB (I personally prefer it):
sudo apt install mariadb-server
For detailed configuration, you can refer to our MySQL installation and configuration guide for Ubuntu 25.04.
Looking for professional support?
Rely on one of our Linux Consultants, 30' analysis of your system for Free!
Conclusion
We managed to install LAMP in Ubuntu 25.04, now our server is ready to host a CMS or Web App
If you found this guide useful, please share it on social, others may need it.