Before you begin: what a production LAMP server actually requires
LAMP means Linux, Apache, MySQL or MariaDB, and PHP. Installing packages is only the first step. A reliable server also needs controlled SSH access, operating-system updates, a firewall, TLS, backups, monitoring and a documented restore procedure. These instructions assume a single host; critical or high-traffic applications may need split services and redundancy.
Prerequisites: a clean supported OS, authorized sudo user, emergency console access, DNS control, 80/443 available, and an independent backup plan. Do not apply these standalone commands to servers already running cPanel, Webuzo or DirectAdmin: control panels manage their own stacks and parallel packages can break the installation.
Step 1 — Update a clean host and install the stack
These examples target a clean Ubuntu 24.04 LTS server with authorized sudo access and standard distribution repositories. Verify the release using cat /etc/os-release; take a snapshot before modifying any existing production machine and confirm the application supports the chosen PHP version.
cat /etc/os-release
sudo apt update
sudo apt upgrade
sudo apt install apache2 mariadb-server php-fpm php-cli php-mysql php-curl php-xml php-mbstring php-zip
The default packages in this distribution normally provide PHP 8.3. Use PHP-FPM to separate PHP workers from Apache, and check the actual installed versions with php -v and the package manager.
Step 2 — Enable services and connect Apache to PHP-FPM
sudo systemctl enable --now apache2 mariadb php8.3-fpm
sudo a2enmod proxy_fcgi setenvif rewrite ssl
sudo a2enconf php8.3-fpm
sudo apache2ctl configtest
sudo systemctl reload apache2
If you use third-party repositories or customized PHP pools, verify the real FPM service/configuration name before enabling it. Do not mix runtime versions without a deliberate pool and site configuration.
Step 3 — Firewall, inbound traffic and HTTPS
Before enabling a firewall, verify that SSH remains permitted on your actual management port and console recovery works. The standard UFW example below assumes the OpenSSH service profile applies; modify the rules if you changed SSH ports.
sudo ufw status verbose
sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'
# Verify SSH access before optionally running: sudo ufw enable
Point DNS to the server, allow ports 80 and 443, then issue a TLS certificate using a trusted ACME client after the domain resolves correctly. Validate renewal and redirects before putting an e-commerce application into production.
Next — Configure a safe Apache virtual host
Create a dedicated site user and directory, an Apache VirtualHost with the correct DocumentRoot, a site-specific error log and least-privilege filesystem ownership. Test with apache2ctl configtest on Ubuntu/Debian or httpd -t on the RHEL family. Separate PHP-FPM pools can help isolate tenants. Avoid universally writable directories and do not expose diagnostic phpinfo() pages to the public.
Harden MariaDB and use an application-specific database account
Use mariadb-secure-installation if available and appropriate for the installed authentication model. Create a separate database and local user with only the required permissions. Generate a unique long password in a password manager, not in a shell command argument that may be stored in history. Review SQL engine version and application compatibility.
sudo mariadb
-- Inside the interactive SQL prompt, replace placeholders:
CREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'REPLACE_WITH_UNIQUE_LONG_SECRET';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
EXIT;
This is a simplified single-application database example. Narrow the privileges further where feasible; never use the literal placeholder as a real password.
Verify services without exposing credentials
sudo systemctl --no-pager status apache2 mariadb
php -v
sudo mariadb -e "SELECT VERSION();"
curl -I http://127.0.0.1
Validate PHP application execution through an access-restricted, non-sensitive health endpoint. Remove any temporary phpinfo() diagnostics immediately because they reveal environment details. Review error logs using a redaction procedure if they may contain customer information.
Production maintenance, backups and recovery
- Plan security updates and subscribe to distro/PHP advisories; monitor for end-of-support releases.
- Back up application code, uploads, consistent SQL dumps and Apache/PHP-FPM configuration to independent storage, and periodically test restoration.
- Monitor TLS renewals, disk, PHP-FPM worker limits, database health, cron/queues, service errors and capacity. A healthy homepage does not prove checkout or background jobs function.
Troubleshooting: common symptoms
- HTTP 403: wrong DocumentRoot, ownership, permissions or SELinux/AppArmor labels.
- 502/503: PHP-FPM unavailable, misconfigured socket or worker saturation.
- Database refused: service down, wrong SQL host, credentials, privileges or incompatible schema/version.
- HTTPS failure: incorrect DNS, blocked validation port or ACME/renewal error.
Self-managed LAMP or Gotekky-managed infrastructure?
An unmanaged LAMP VPS requires someone to own patching, monitoring, backups and incidents. Gotekky can help build an appropriate stack, migrate applications and provide recurring Linux administration under a clearly defined scope. Application-level WordPress updates, custom-code repair and integrations are separately scoped work.
Explore VPS Hosting, Infrastructure Management or a free requirements conversation.
Frequently asked questions
- Can I substitute LiteSpeed or Nginx? Yes, but then the configuration is no longer this Apache-specific LAMP example.
- Does MariaDB behave exactly like MySQL? Not always. Check application/version requirements before choosing.
- Does a Canadian VPS alone satisfy privacy law? No. Document hosting locations, processors, access, encryption and your organizational responsibilities separately.
Distribution reference: Ubuntu 24.04 LTS official documentation.
Example Apache VirtualHost for your first application
Create /etc/apache2/sites-available/example-site.conf with the following configuration file contents, after creating the directory with appropriate deployment permissions. Replace example.com with a domain you control; this block is not a shell command.
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example-site/public
<Directory /var/www/example-site/public>
Require all granted
AllowOverride None
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example-error.log
CustomLog ${APACHE_LOG_DIR}/example-access.log combined
</VirtualHost>
Enable it with sudo a2ensite example-site.conf, check sudo apache2ctl configtest, and reload Apache. This is HTTP-only until you deploy a valid TLS certificate and redirect policy.
Other Linux distributions
Other installations: Debian 13 (Trixie), AlmaLinux 9 / Rocky Linux 9, Red Hat Enterprise Linux 9.
Gotekky
Need help deciding what to do next?
Tell us what you are seeing and what outcome you need. We will identify whether a managed service, scoped project or paid technical assessment is the right next step.