Knowledgebase | VPSGrid
English
EnglishBeta EspañolPortuguês (Brasil)Coming soonFrançaisComing soonDeutschComing soon
Client Area

Install LAMP Stack on VPSGrid Linux VPS

0 found helpful

Install LAMP Stack on VPSGrid Linux VPS

Short answer

Install LAMP on VPSGrid: apt install apache2 mariadb-server libapache2-mod-php php-mysql, enable mod_rewrite, create VirtualHost with AllowOverride All, test before disabling default site, mysql secure install, allow OpenSSH before UFW, verify PHP and MariaDB.

Overview

Customers preferring Apache httpd on VPSGrid Linux VPS — common for legacy PHP, .htaccess rules, or cPanel migration familiarity via Migrate from cPanel Shared Hosting to VPSGrid VPS.

VPSGrid sells unmanaged VPS with root or administrator access. Guest OS configuration, application data, backups, and patching inside the VM are your responsibility unless a separate product is documented. Review What Is an Unmanaged VPS at VPSGrid? and Security Responsibilities on Unmanaged VPS before expecting support to perform stack work.

US-Based VPS infrastructure

VPSGrid provides unmanaged Linux and Windows VPS on US-Based KVM infrastructure with NVMe storage and Proxmox virtualization. You manage the guest OS, applications, backups, and security. Current plan specifications appear at checkout on vpsgrid.net — articles do not publish fixed pricing.

LAMP Stack on VPSGrid Client Apache mod_php MariaDB NVMe Apache httpd + PHP module + MariaDB on unmanaged VPS
Diagram: Apache serves PHP via mod_php with MariaDB on VPSGrid Linux VPS.

Decision guidance: LAMP vs LEMP

Choose LAMP whenChoose LEMP when
.htaccess / AllowOverride requiredGreenfield Nginx stack
Legacy Apache modulesWordPress guide alignment — How to Deploy WordPress on Ubuntu VPS uses Nginx

Step 2: Enable mod_rewrite

a2enmod rewrite && systemctl restart apache2
What it does
Enables URL rewriting for WordPress permalinks.
Why it matters
WordPress pretty permalinks require rewrite module.
Expected result
apache2ctl -M lists rewrite_module.
If it fails
Syntax error in vhost prevents restart — check error log.

Step 3: Virtual host

Test Apache with the default site before disabling it — browse http://PRIMARY_IP to confirm Apache responds, then create your vhost:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html

    <Directory /var/www/example.com/public_html>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>
AllowOverride All for WordPress

WordPress pretty permalinks and many plugins expect .htaccess — only available when AllowOverride All is set on Apache (not on Nginx/LEMP).

a2ensite example.com.conf && apache2ctl configtest && systemctl reload apache2
What it does
Enables the new site and reloads Apache after syntax check.
Why it matters
configtest prevents a broken vhost from stopping the entire web server.
Expected result
Syntax OK and curl -H "Host: example.com" http://127.0.0.1 returns your index.
If it fails
403 Forbidden — check Directory permissions and DocumentRoot path; chown -R www-data:www-data on web root.
Before disabling default site

Run curl -H "Host: example.com" http://127.0.0.1 and confirm your vhost serves content. Only then run a2dissite 000-default.conf if you no longer need the default page on PRIMARY_IP.

a2dissite 000-default.conf && systemctl reload apache2
What it does
Disables default site after custom vhost verified.
Why it matters
Prevents accidental serving of default page for your domain.
Expected result
curl -H "Host: example.com" http://127.0.0.1 serves your site.
If it fails
Only run after Step 3 vhost test succeeds — see warning in vhost section.

Step 4: MariaDB setup

mysql_secure_installation
What it does
Hardens MariaDB root account interactively.
Why it matters
Removes test database and anonymous users.
Expected result
Prompts complete; remote root login disabled.
If it fails
Run as root on fresh install before creating app databases.
mysql -e "CREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'strongpass'; GRANT ALL ON appdb.* TO 'appuser'@'localhost'; FLUSH PRIVILEGES;"
What it does
Creates application database and user.
Why it matters
Same pattern as LEMP stack and WordPress guides.
Expected result
App user can connect locally.
If it fails
Use strong password; never bind 3306 publicly.

Step 5: Firewall and SSL

Allow SSH before UFW enable

See How to Configure UFW Firewall on Ubuntu/Debian — allow OpenSSH first. Certbot Apache plugin: certbot --apache per Let's Encrypt SSL with Certbot on VPSGrid.

phpMyAdmin not recommended on public VPS

phpMyAdmin increases attack surface. Prefer CLI mysql, WP-CLI, or SSH tunnel. If installed, restrict by IP and use strong auth.

Verify

  1. apache2ctl configtest returns Syntax OK
  2. PHP executes via index.php in DocumentRoot
  3. MariaDB app user connects
  4. WordPress permalinks work with mod_rewrite enabled

Troubleshooting matrix

SymptomLikely causeWhat to check
403 ForbiddenDirectory permissionschown www-data:www-data; AllowOverride All
500 errorPHP fatalCheck /var/log/apache2/error.log
Port 80 conflictNginx also installedStop nginx or choose one stack only

Security considerations

Disable directory listing, keep Apache patched via apt upgrade, use Fail2ban — Fail2ban Setup on VPSGrid Linux VPS.

Certbot with Apache

After vhost works on port 80, run Certbot Apache plugin per Let's Encrypt SSL with Certbot on VPSGrid: certbot --apache -d example.com -d www.example.com. Certificate issuance is not guaranteed — depends on DNS, HTTP validation, and rate limits.

Apache event vs prefork MPM

Default MPM varies by distribution. PHP mod_php traditionally used prefork; php-fpm + Apache proxy_fcgi allows event MPM for better concurrency. This guide uses mod_php for simplicity matching most cPanel migrations.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Post-install patching

Schedule regular apt upgrade windows; test apps after PHP or MariaDB minor bumps.

Log rotation early

Configure logrotate to prevent disk-full recurrence — see Disk Full on VPSGrid VPS: Diagnosis and Cleanup.

Deploy user hygiene

Use non-root deploy users with sudo for service restarts where practical.

Next learning step

Consider LEMP for new Nginx projects — Install LEMP Stack on VPSGrid Linux VPS.

Frequently Asked Questions

What is LAMP on VPSGrid?

Linux + Apache + MariaDB + PHP — alternative to LEMP using Apache httpd. You manage all components on unmanaged VPS.

Apache vs Nginx on VPSGrid?

Both run on VPSGrid Linux VPS. Apache .htaccess suits some legacy apps; Nginx often uses less memory — compare Install LEMP Stack on VPSGrid Linux VPS.

Does VPSGrid provide Apache support?

VPSGrid support covers infrastructure. Apache configuration inside guest OS is customer responsibility — Security Responsibilities on Unmanaged VPS.

Can I run Apache and Nginx together?

Possible but not recommended on small VPS — port 80 conflict. Choose one stack per server unless advanced reverse proxy setup.

Related Articles

Next steps on VPSGrid

Prepare your environment on a VPSGrid Linux VPS when Apache-based workloads require .htaccess or legacy compatibility.

Need More Help?

Search this knowledgebase for related guides. If the issue appears infrastructure-related (provisioning, billing, primary IP assignment), open a ticket at billing.vpsgrid.net with your service ID, primary IP, and steps already tried. See What Information to Include in a Support Request and Security Responsibilities on Unmanaged VPS for scope.

Was this answer helpful?

Related Articles