Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Set Up a CakePHP Application on an Ubuntu LAMP Stack VPS

Deploy CakePHP reliably on an Ubuntu LAMP VPS by matching PHP versions, installing Composer, pointing Apache at webroot, enabling rewrites, securing MySQL, and finishing DNS and HTTPS setup.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Deploying CakePHP on a LAMP VPS is a matter of aligning four layers: a supported PHP release, Apache pointed at CakePHP’s webroot, working URL rewriting, and a protected MySQL or MariaDB connection. The sequence below takes you from a new Ubuntu server to a production-ready HTTPS site, including the checks that prevent the usual 404, permission, and database failures.

What you need before starting

Use an Ubuntu VPS with sudo access, a public IPv4 address (and IPv6 if your deployment requires it), and a domain name that you control. The server should have enough memory for your application, Composer, Apache, PHP, and MySQL or MariaDB; the exact requirement depends on your CakePHP application and traffic.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Operating system: a currently supported Ubuntu Server image. Package names and the default PHP version vary by Ubuntu release.
  • Web server: Apache 2 with the PHP module and mod_rewrite.
  • PHP: CakePHP 5 requires at least PHP 8.1. CakePHP’s compatibility information lists PHP 8.4 and 8.5 support for CakePHP 5.1 and newer. CakePHP 4.x and 3.x have different PHP support ranges; CakePHP 2.x is end-of-life.
  • PHP extensions: mbstring, intl, SimpleXML, and PDO are required by CakePHP 5. The MySQL PDO driver is needed when the database is MySQL or MariaDB.
  • Database: MySQL 5.7 or newer, or MariaDB 10.1 or newer, are listed among CakePHP’s supported databases.
  • Build tools: Composer, plus unzip and any compiler tools required by extensions used by your application.
  • Production access: DNS control for the domain and a plan for TLS certificate issuance and renewal.

Check the PHP version supplied by the VPS image before choosing a CakePHP branch. Pin the framework’s major and minor version in Composer rather than allowing an unplanned upgrade during deployment.

Check the installed PHP version

php -v

If the image provides PHP 8.0 or older, do not create a CakePHP 5 project until you install a supported PHP release. Changing PHP versions after an application is deployed can require extension, configuration, and dependency changes, so decide the framework/PHP combination first.

1. Update Ubuntu and install the LAMP components

Log in over SSH with a sudo-capable account. Apply security updates before installing application software.

sudo apt update
sudo apt full-upgrade -y

Install Apache, PHP, the Apache PHP module, the command-line interpreter, the MySQL driver, and the extensions CakePHP commonly needs. On Ubuntu, the package names below follow the distribution’s default PHP version; if you deliberately run another supported version, use that version’s package names instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt install -y apache2 libapache2-mod-php php-cli php-mysql php-mbstring php-intl php-xml php-curl unzip
sudo apt install -y mysql-server

php-xml supplies the SimpleXML functionality used by many PHP applications. PDO itself is included with PHP, while php-mysql provides the MySQL PDO driver. If you choose MariaDB, the same PHP MySQL driver is normally used.

Canonical’s Ubuntu guidance recommends restarting Apache after module changes. Enable the service at boot and verify that it is running:

sudo systemctl enable --now apache2
sudo systemctl status apache2

Open the server’s IP address in a browser. The default Apache page confirms that the web server is reachable; it does not confirm that CakePHP is configured yet.

Install Composer securely

Install Composer using the current procedure published by the Composer project. Verify the installer signature as instructed by Composer, place the executable in a system path such as /usr/local/bin/composer, and then check it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
composer --version

Do not copy an installer command from an old tutorial without checking its current signature and PHP requirements. Composer is the supported way to create and update a CakePHP application.

2. Create the CakePHP project outside the public directory

Keep source code, configuration, secrets, and dependency metadata outside the directory Apache exposes. A practical layout is /var/www/myapp for the project and /var/www/myapp/webroot as the only public directory.

sudo mkdir -p /var/www
sudo chown "$USER":"$USER" /var/www
cd /var/www
composer create-project --prefer-dist cakephp/app myapp
cd /var/www/myapp

The create-project command downloads the CakePHP application skeleton and its dependencies. The exact framework version selected depends on the package constraints and your PHP version. To make deployments repeatable, commit the generated composer.json and composer.lock, then review and pin the CakePHP major/minor line you intend to operate.

Never place .env, config, src, or the project root itself under a document root that serves arbitrary files. Apache should expose only webroot.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Configure Apache for CakePHP

CakePHP uses a front controller to route requests. Apache must send requests for non-file URLs through CakePHP’s rewrite rules, and the virtual host must point to webroot.

Enable rewriting

sudo a2enmod rewrite

The application’s webroot/.htaccess file contains the rewrite rules used by the standard CakePHP skeleton. If Apache ignores that file, routes such as /users or /articles/view/1 commonly return 404 even though the home page loads.

Create a name-based virtual host

Create a file such as /etc/apache2/sites-available/myapp.conf:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com

    DocumentRoot /var/www/myapp/webroot

    <Directory /var/www/myapp/webroot>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/myapp-error.log
    CustomLog ${APACHE_LOG_DIR}/myapp-access.log combined
</VirtualHost>

Replace the example hostnames and path with your values. AllowOverride All permits the CakePHP .htaccess rules to operate in this directory. On a tightly controlled server you can replace it with a narrower override policy, but do not disable the rewrite directives the application needs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Enable the site and, if appropriate, disable Apache’s default site so it does not catch requests intended for your domain:

sudo a2ensite myapp.conf
sudo a2dissite 000-default.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

apache2ctl configtest must report Syntax OK before you reload. If your VPS image uses a different service layout, keep the distribution’s equivalent validation and reload commands.

Check the public directory and permissions

The Apache service account on a standard Ubuntu installation is usually www-data, but confirm the account used by your image. Apache needs read and traverse permission for the project’s public files and write permission only for CakePHP runtime directories such as cache and logs.

Use ownership and group permissions that match your release process. Do not make the whole project world-writable. A typical approach is to keep application files owned by the deployment account, grant the web-server group access where required, and grant group write permission only to the runtime directories. If you change ownership, test both SSH-based deployments and web requests afterward.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Create a dedicated database and user

Do not run the application as the database root user. Create a database and an account limited to that database. The following example uses MySQL syntax; MariaDB accepts the same statements in normal installations.

sudo mysql

CREATE DATABASE cake_app CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'cake_app'@'localhost' IDENTIFIED BY 'use-a-long-random-password';
GRANT ALL PRIVILEGES ON cake_app.* TO 'cake_app'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Use a generated password and store it in your deployment secret store or protected server configuration, not in a public repository. If the application and database are on separate hosts, restrict the database account’s host pattern and firewall rules to the application server instead of using a broad wildcard.

Configure CakePHP’s local settings

Put machine-specific database settings in config/app_local.php. The exact surrounding structure depends on the CakePHP skeleton version, but the default datasource should contain the MySQL driver and your connection values:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
'Datasources' => [
    'default' => [
        'className' => 'Cake\Database\Connection',
        'driver' => 'Cake\Database\Driver\Mysql',
        'host' => '127.0.0.1',
        'port' => 3306,
        'username' => 'cake_app',
        'password' => 'use-a-long-random-password',
        'database' => 'cake_app',
        'encoding' => 'utf8mb4',
        'timezone' => 'UTC',
    ],
],

If your provider exposes MySQL through a Unix socket, use the socket setting documented by that provider instead of assuming 127.0.0.1. A TCP host and a Unix socket can authenticate differently, so a connection that works from the command line may still fail when the PHP driver uses another endpoint.

Run your application’s migrations or schema setup using the project’s documented CakePHP command after the connection is configured. Verify both a read and a write before opening the site to users.

5. Set production secrets and disable debug output

The application skeleton includes sample security values intended for development. Replace them before deployment with unpredictable values. Encryption salts and security keys should be generated independently, be kept private, and not be committed to source control. Bitnami’s CakePHP guidance recommends a key of at least 32 characters; use a longer randomly generated value where the configuration permits it.

Set the application environment to production and turn debug mode off before the domain is public. Development mode can expose stack traces, SQL details, file paths, and environment values to visitors. When troubleshooting, enable temporary logging for an authorized maintenance window, then disable debug output again.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Protect configuration files

  • Keep config/app_local.php, environment files, and deployment secrets outside public webroot.
  • Ensure Apache is not configured to serve hidden files or source directories.
  • Use file permissions that let the deployment process read secrets while preventing unrelated system users from reading them.
  • Never commit production passwords, private keys, or encryption salts to a public Git repository.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

6. Point DNS at the VPS and add HTTPS

Register or use a domain, then create an A record for the apex name pointing to the VPS IPv4 address. If you serve www, create a corresponding A record (or an appropriate CNAME) and include that name in the Apache virtual host and certificate. Allow DNS time to propagate before diagnosing an apparent web-server failure.

Issue a TLS certificate through a current certificate authority such as Let’s Encrypt. Configure Apache for HTTPS, test the certificate chain from an external network, and redirect HTTP to HTTPS after the secure virtual host works. Configure automatic renewal and verify that the renewal timer or scheduled job actually runs; an unrenewed certificate eventually takes the site offline.

After HTTPS is enabled, check the browser console and page source for mixed content. Replace hard-coded http:// asset and callback URLs with HTTPS-aware configuration, and ensure reverse-proxy headers are handled correctly if TLS terminates in front of Apache.

7. Perform a controlled production release

For a release that installs dependencies on the server, run Composer in the application directory with development packages omitted and the autoloader optimized:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
cd /var/www/myapp
composer install --no-dev --optimize-autoloader

Run this as part of a controlled deployment rather than during an unplanned request. Keep the lock file consistent with the code release, run migrations in an intentional order, and retain a rollback copy of the previous release.

Production verification checklist

  1. Open the site over HTTPS and confirm the certificate matches every hostname you publish.
  2. Visit the home page and at least one deeper CakePHP route, not just a static file.
  3. Submit a form and verify validation, a database write, and a subsequent read.
  4. Inspect Apache access and error logs and CakePHP logs for warnings, permission errors, and failed SQL connections.
  5. Confirm that visitors see a generic error page rather than PHP notices or stack traces.
  6. Check that cache and log directories are writable by the Apache service account but the rest of the project is not broadly writable.
  7. Remove any temporary phpinfo.php file created while checking PHP.
  8. Test the scheduled TLS renewal process and verify backups or VPS snapshots can be restored.

Common failures and precise checks

Symptom Likely cause What to check
Every route except / returns 404 mod_rewrite is disabled or .htaccess overrides are blocked. Run apache2ctl -M and look for rewrite_module. Inspect the virtual host’s AllowOverride value and confirm webroot/.htaccess exists.
PHP files download or display as text The Apache PHP module is missing, disabled, or Apache was not restarted after installation. Confirm libapache2-mod-php is installed, inspect enabled PHP modules, run sudo systemctl restart apache2, and retest with a protected temporary PHP check.
Database connection failure Wrong host or socket, invalid credentials, missing PDO driver, or insufficient grants. Check php-mysql, compare config/app_local.php with the database account, test the same host and port from the server, and review MySQL/MariaDB grants.
Permission-denied errors in cache or logs Runtime directories are owned by the wrong account or lack group write permission. Identify the Apache service user, inspect ownership and mode bits on CakePHP runtime directories, and grant only the minimum required write access.
HTTPS works but assets are blocked as mixed content Application URLs or asset references still use HTTP. Check the configured base URL, asset helpers, redirects, and proxy headers. Replace hard-coded HTTP links and clear application caches.
The wrong site appears for the domain The DNS record points elsewhere or Apache is selecting another virtual host. Resolve the domain from an external network, verify the VPS address, inspect enabled sites, and ensure ServerName and ServerAlias match the requested hostname.

Choosing a VPS for CakePHP

When comparing VPS plans, evaluate the deployment capabilities rather than headline CPU or disk numbers alone. Confirm the following with the provider and for the specific region you will use:

  • Supported Ubuntu release and the PHP versions available in its image or repositories.
  • Apache and Composer support, including whether you receive root or sudo access.
  • Self-managed MySQL/MariaDB versus a managed database service, and the network path between them.
  • Snapshots, automated backups, retention, and restoration testing.
  • Network transfer limits, storage type, IPv4 and IPv6 availability, and DNS controls.
  • TLS automation, firewall controls, monitoring, and the location’s latency to your players or customers.
  • Total recurring cost, including separate storage, backups, public IPv4 addresses, and managed database charges.

Provider prices and plan limits change frequently, so verify them at the time you purchase. A VPS that supplies an unsupported PHP version can cost more to fix than a slightly larger plan with a current image and reliable snapshots.

Final pre-launch checklist

  • PHP satisfies the selected CakePHP branch, including mbstring, intl, SimpleXML, PDO, and the MySQL driver.
  • Composer dependencies are locked and installed with the intended production flags.
  • Apache’s DocumentRoot is the application’s webroot, never the project root.
  • mod_rewrite is enabled and the relevant directory permits the application’s rewrite rules.
  • The database uses a dedicated, least-privilege account and UTF-8-compatible encoding.
  • Secrets are changed, protected, and excluded from source control; debug output is disabled.
  • DNS points to the VPS, HTTPS is enforced, and certificate renewal is automatic.
  • Routes, forms, database operations, logs, permissions, backups, and error handling have all been tested over HTTPS.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.