sudo apt install apache2 mariadb-server php libapache2-mod-php php-mysql, then secure the database with sudo mysql_secure_installation. Apache runs PHP files straight away. On AlmaLinux or Rocky Linux, install httpd mariadb-server php php-mysqlnd and start httpd, mariadb and php-fpm. Test with a small PHP file.
Before you start
- LAMP means Linux, Apache, MariaDB or MySQL, and PHP. Choose it when your app relies on
.htaccessfiles; otherwise a LEMP stack with Nginx works just as well. - Use a user with
sudo. If you areroot, leave outsudo. - Nothing else may use port 80. Stop Nginx first if it is installed.
How to install Apache, MariaDB and PHP
- Ubuntu / Debian
- AlmaLinux / Rocky 10
- AlmaLinux / Rocky 9
libapache2-mod-php loads PHP into Apache, so no extra service is needed.How to open the firewall
- Ubuntu / Debian (ufw)
- AlmaLinux / Rocky (firewalld)
80/tcp and 443/tcp one by one.How to secure MariaDB
How to add your site
Follow the virtual host steps in install Apache: create/var/www/example.com/public_html, add a <VirtualHost *:80> file with ServerName example.com, enable it with sudo a2ensite example.com.conf (Ubuntu / Debian) and reload Apache.
Install the PHP extensions most apps ask for:
- Ubuntu / Debian
- AlmaLinux / Rocky
How to check it worked
Create a test file in the site’s web root:apache2handler means Apache’s PHP module ran the file. On AlmaLinux / Rocky you see fpm-fcgi instead. Delete the file afterwards:
Frequently asked questions
Apache shows the PHP code instead of running it. Why?
PHP is not loaded. On Ubuntu / Debian, check that/etc/apache2/mods-enabled/ contains php8.*.conf and php8.*.load; if not, install libapache2-mod-php and restart Apache. On AlmaLinux / Rocky, make sure php-fpm is running.
Which PHP version do I get?
Ubuntu 22.04 has PHP 8.1, Ubuntu 24.04 has 8.3, Debian 12 has 8.2, Debian 13 has 8.4 and AlmaLinux / Rocky 10 has 8.3. For a different version, see multiple PHP versions.Can I use PHP-FPM with Apache on Ubuntu?
Yes. Installphp-fpm, run sudo a2enmod proxy_fcgi setenvif and sudo a2enconf php8.3-fpm (match your version), disable the module with sudo a2dismod php8.3, then restart Apache.
How do I install phpMyAdmin?
See install phpMyAdmin. Protect it with HTTPS and a strong password.Related guides
VPS and dedicated server guides
Every server guide in one place.
Install Apache
Virtual hosts in detail.
Install WordPress
Run WordPress on your stack.
Free SSL with Certbot
Add HTTPS to Apache.
Install a LEMP stack
The same with Nginx.
Checked against the official Ubuntu Server PHP documentation and Red Hat Enterprise Linux 9 PHP guide on 4 November 2026; Ubuntu commands, SQL and the PHP test tested on Ubuntu 24.04 LTS (Apache 2.4.58, MariaDB 10.11, PHP 8.3.6). Commands can differ on other distributions or releases.
Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026