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 — Install Apache, MariaDB and PHP-FPM
On AlmaLinux 9 / Rocky Linux 9, first verify the OS minor release, enabled repositories and the support lifecycle of the PHP package stream. PHP availability varies across RHEL-family releases and AppStream streams. Do not assume a particular minor release supplies a particular PHP version. On RHEL, confirm system subscription/registration and authorized repos.
cat /etc/os-release
sudo dnf makecache
sudo dnf update
sudo dnf module list php # Where modular streams are provided
sudo dnf install httpd mariadb-server php php-fpm php-mysqlnd
sudo systemctl enable --now httpd mariadb php-fpm
sudo httpd -t
Inspect dnf module list php for the installed release and plan a supported PHP stream before deploying an application that needs newer PHP. Changing streams on an active application server requires a separate compatibility and rollback plan.
Step 2 — firewalld and SELinux
Keep SELinux in Enforcing mode and fix labels/policy rather than disabling enforcement. If firewalld is active, permit HTTP/HTTPS only after confirming your authorized SSH management rule.
sudo getenforce
sudo firewall-cmd --state
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo restorecon -Rv /var/www
sudo httpd -t
A web application connecting to a local MariaDB socket usually does not need any public SQL port. Avoid exposing port 3306 to the internet to make a connection error disappear.
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 httpd mariadb php-fpm
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: AlmaLinux 9 / Rocky Linux 9 official documentation.
Example Apache VirtualHost for your first application
Create /etc/httpd/conf.d/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 /var/log/httpd/example-error.log
CustomLog /var/log/httpd/example-access.log combined
</VirtualHost>
Validate with sudo httpd -t, set appropriate SELinux labels on the directory and reload Apache using sudo systemctl reload httpd. This is HTTP-only until you deploy a valid TLS certificate and redirect policy.
Other Linux distributions
Other installations: Ubuntu 24.04 LTS, Debian 13 (Trixie), 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.