LAMP means Linux, Apache, MariaDB and PHP. Apache's big advantage is .htaccess support: many PHP applications and WordPress plugins ship rewrite and security rules in .htaccess files, and Apache applies them without any extra work.
This guide uses PHP-FPM with Apache's event engine, which uses less memory than the older mod_php approach.
Which VPS is this for? These steps are for an Unmanaged VPS, where you log in as root and look after the server yourself. On a Managed VPS we take care of the operating system and server software, and you manage your websites in StackCP instead.
LAMP or LEMP?
- Choose LAMP if your app relies on
.htaccessor you are moving from shared hosting and want things to work the same way. - Choose LEMP (Nginx) for slightly lower memory use and high-traffic static files. See How to Install a LEMP Stack.
Don't install both web servers on the same ports; they will fight over port 80.
Step 1: Install the packages
Ubuntu and Debian
Install php-fpm explicitly. (The plain php package would pull in mod_php instead.)
sudo apt update sudo apt install -y apache2 mariadb-server php-fpm php-mysql php-curl php-gd \ php-mbstring php-xml php-zip php-intl php-bcmath php -v
Now connect Apache to PHP-FPM. Replace 8.3 with your version (8.1 on Ubuntu 22.04, 8.2 on Debian 12):
sudo a2enmod proxy_fcgi setenvif rewrite headers sudo a2enconf php8.3-fpm sudo systemctl restart apache2
AlmaLinux and Rocky Linux 9
sudo dnf install -y httpd mariadb-server sudo dnf module reset -y php sudo dnf module enable -y php:8.3 sudo dnf install -y php-fpm php-mysqlnd php-gd php-mbstring php-xml php-intl php-bcmath php-opcache php-cli sudo systemctl enable --now httpd mariadb php-fpm
On these systems Apache is already set up to hand .php files to PHP-FPM through /etc/httpd/conf.d/php.conf. The service is called httpd.
Step 2: Secure MariaDB
Run sudo mariadb-secure-installation and create a database and user for your site, as explained in How to Secure MySQL or MariaDB.
Step 3: Create the site folder
sudo mkdir -p /var/www/example.com/public # Ubuntu / Debian sudo chown -R www-data:www-data /var/www/example.com # AlmaLinux / Rocky sudo chown -R apache:apache /var/www/example.com
Step 4: Create a virtual host
The file goes in /etc/apache2/sites-available/example.com.conf on Ubuntu/Debian, or /etc/httpd/conf.d/example.com.conf on AlmaLinux/Rocky:
<VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com/public <Directory /var/www/example.com/public> AllowOverride All Require all granted </Directory> ErrorLog /var/log/apache2/example.com-error.log CustomLog /var/log/apache2/example.com-access.log combined </VirtualHost>
On AlmaLinux/Rocky, change the two log paths to /var/log/httpd/. AllowOverride All is what makes .htaccess files work.
Enable it
# Ubuntu / Debian sudo a2ensite example.com.conf sudo a2dissite 000-default.conf sudo apache2ctl configtest sudo systemctl reload apache2 # AlmaLinux / Rocky sudo apachectl configtest sudo systemctl reload httpd
You want to see Syntax OK before reloading.
Step 5: Test
echo '<?php phpinfo();' | sudo tee /var/www/example.com/public/info.php
Open http://example.com/info.php. The Server API line should say FPM/FastCGI. Then delete the file with sudo rm /var/www/example.com/public/info.php.
Finish by adding HTTPS: How to Install a Free SSL Certificate with Certbot (use the --apache option).
PHP settings
Edit /etc/php/8.3/fpm/php.ini (Ubuntu/Debian) or /etc/php.ini (AlmaLinux/Rocky) to change upload_max_filesize, post_max_size and memory_limit, then restart PHP-FPM (php8.3-fpm or php-fpm). With PHP-FPM, php_value lines in .htaccess are not supported and cause a 500 error; use php.ini or a .user.ini file in the site folder instead.
Common problems
| Symptom | Fix |
|---|---|
| PHP code is shown as text or downloaded | PHP-FPM isn't connected. On Ubuntu/Debian run the a2enconf php8.3-fpm step again and restart Apache. |
| Pretty permalinks or rewrites give 404 | mod_rewrite is off (sudo a2enmod rewrite) or AllowOverride All is missing. |
| 403 Forbidden | Missing Require all granted, wrong ownership, or on AlmaLinux an SELinux label problem (sudo restorecon -Rv /var/www). |
| 500 Internal Server Error | Usually an invalid line in .htaccess. Check the site's error log. |
| Apache won't start: Address already in use | Another web server (often Nginx) is using port 80. Stop and disable it. |
Need help?
If something about the VPS itself is not working (it won't start, you can't reach it, or you need console access, an upgrade or a reinstall), open a support ticket from your client area or message us on WhatsApp at 01818160926. Include your VPS IP address and what you have already tried so we can help faster.
Categories
Written by
FimuroHost Team
Technical Writer