November 14, 2026 · by Alex M.
The LAMP stack (Linux, Apache, MySQL, PHP) remains one of the most popular technology combinations for hosting web applications. From WordPress and Joomla to custom PHP applications, LAMP provides a stable, well-documented and highly flexible foundation.
In this guide, you'll learn how to fully install and configure a LAMP stack on a SSD VPS running Ubuntu 22.04, step by step, with real commands and optimization tips.
LAMP is an acronym for:
This combination powers millions of websites and web applications around the world. Key advantages:
If you want to run a PHP application in production without the overhead of a hosting panel, an NVMe VPS with a manually configured LAMP stack is the ideal solution.
Before starting, make sure you have:
If you don't have a server yet, you can quickly order a VPS SSD from CLIQHOST and have it active within minutes.
Before any installation, update the package list and existing system:
sudo apt update && sudo apt upgrade -y
Reboot the server if there are kernel updates:
sudo reboot
Apache is the web server that will process HTTP requests and serve your application's files.
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2
If everything is working correctly, you'll see active (running) in the output.
Allow HTTP and HTTPS traffic through UFW:
sudo ufw allow 'Apache Full'
sudo ufw enable
sudo ufw status
Now, if you access your server's IP from a browser, you'll see the default Apache page: "Apache2 Ubuntu Default Page".
💡 Tip: You can disable the default Apache page with
sudo a2dissite 000-default.confafter configuring your own VirtualHost.
MySQL will manage the databases for your web applications.
sudo apt install mysql-server -y
Run the MySQL security script:
sudo mysql_secure_installation
You'll be guided through a set of questions:
Y (enables password validation)YY (important for security)YYConnect to MySQL:
sudo mysql
Create a database and a dedicated user (don't use root for applications):
CREATE DATABASE myapp_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'VerySecurePassword123!';
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
⚠️ Warning: Always use complex passwords and separate users per application. Never use the MySQL
rootaccount in application connections.
PHP is the scripting language that bridges Apache and MySQL, executing your web application's logic.
sudo apt install php libapache2-mod-php php-mysql php-cli php-curl php-gd php-mbstring php-xml php-zip php-bcmath php-intl -y
php -v
Expected output:
PHP 8.1.x (cli) (built: ...)
Edit the php.ini file:
sudo nano /etc/php/8.1/apache2/php.ini
Modify or verify these settings:
; Memory limit per script
memory_limit = 256M
; Maximum uploaded file size
upload_max_filesize = 64M
post_max_size = 64M
; Maximum execution time
max_execution_time = 300
; Hide PHP version from HTTP headers (security)
expose_php = Off
; Enable error logging (don't display errors in browser on production)
display_errors = Off
log_errors = On
error_log = /var/log/php_errors.log
Restart Apache to apply the changes:
sudo systemctl restart apache2
Create a test file:
sudo nano /var/www/html/info.php
Content:
<?php
phpinfo();
Access http://SERVER_IP/info.php in your browser. You'll see the PHP Info page with all installation details.
⚠️ Important: Delete this file after verification — it exposes sensitive server information!
sudo rm /var/www/html/info.php
Virtual Hosts allow you to host multiple websites on the same server.
sudo mkdir -p /var/www/example.com/public_html
sudo chown -R $USER:$USER /var/www/example.com
sudo chmod -R 755 /var/www/example.com
sudo nano /etc/apache2/sites-available/example.com.conf
Content:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>
sudo a2ensite example.com.conf
sudo a2enmod rewrite
sudo systemctl reload apache2
Every modern website must run on HTTPS. Certbot automates obtaining and renewing free SSL certificates from Let's Encrypt.
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d example.com -d www.example.com
Certbot will automatically modify the Apache configuration and redirect HTTP → HTTPS.
Verify automatic renewal:
sudo certbot renew --dry-run
If you need a commercial SSL certificate for business projects, CLIQHOST offers certificates from globally recognized certificate authorities.
sudo a2enmod deflate
sudo a2enmod expires
sudo a2enmod headers
sudo systemctl restart apache2
Add to your .htaccess file or directly in the VirtualHost:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE application/javascript application/json
AddOutputFilterByType DEFLATE application/x-font-ttf application/vnd.ms-fontobject
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType text/html "access plus 1 day"
</IfModule>
Apache has multiple processing modules (MPM). The default is mpm_prefork, but for better performance with PHP-FPM, mpm_event is recommended.
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo apt install php8.1-fpm -y
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.1-fpm
sudo systemctl restart apache2 php8.1-fpm
💡 PHP-FPM manages PHP processes separately from Apache, significantly improving performance under heavy load. Ideal for medium-to-high traffic sites on an NVMe VPS.
# Error logs
sudo tail -f /var/log/apache2/error.log
# Access logs
sudo tail -f /var/log/apache2/access.log
# CPU and RAM usage
htop
# Disk space
df -h
# Apache processes
ps aux | grep apache2
For advanced monitoring (Prometheus, Grafana, Zabbix), CLIQHOST offers server management services where our team configures and monitors your infrastructure.
Create a simple PHP file that tests the database connection:
sudo nano /var/www/example.com/public_html/test_db.php
<?php
$host = 'localhost';
$dbname = 'myapp_db';
$username = 'myapp_user';
$password = 'VerySecurePassword123!';
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "✅ MySQL connection successful!";
} catch (PDOException $e) {
echo "❌ Connection error: " . $e->getMessage();
}
Access https://example.com/test_db.php. If you see the success message, the LAMP stack is fully functional.
⚠️ Delete the test file immediately after verification!
sudo rm /var/www/example.com/public_html/test_db.php
If you have an /admin directory, add password protection:
sudo htpasswd -c /etc/apache2/.htpasswd admin_user
In VirtualHost or .htaccess:
<Directory /var/www/example.com/public_html/admin>
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
<LimitExcept GET POST HEAD>
deny from all
</LimitExcept>
Edit /etc/apache2/conf-available/security.conf:
ServerTokens Prod
ServerSignature Off
You've installed and configured a complete LAMP stack on a Linux VPS, including:
A properly configured LAMP stack gives you a solid foundation for any PHP application, from a simple WordPress blog to a complex enterprise application.
If you want to skip the manual configuration stage or prefer a professionally managed environment, the CLIQHOST team is here to help. Explore our SSD VPS plans, NVMe VPS or server management services — or contact us for a custom solution.
Real reviews from customers who trust CLIQHOST for performance, reliability and expert technical support.
"We moved our online shop from a foreign host and the difference is night and day — pages load instantly and support replies in minutes, in Romanian."
"Migrated 12 client sites to CLIQHOST. Free migration, zero downtime, and the cPanel setup is exactly what my team needed. Highly recommend."
"Our NVMe VPS handles traffic spikes without a sweat. Full root, local datacenter, and billing in MDL — everything we wanted from a provider."