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.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Short answer: install a CakePHP-compatible PHP release and required extensions, create the project with Composer outside the public web directory, point Apache at the application’s webroot, enable URL rewriting, connect a least-privilege MySQL or MariaDB account, then add DNS, HTTPS, production secrets and a verification pass. The sequence below is designed for an Ubuntu VPS and CakePHP 5; adjust package names if your image uses a different supported PHP release.

What the finished deployment looks like

A production request should travel through DNS to your VPS, reach Apache, and be served from only the CakePHP application’s webroot directory. CakePHP’s front controller then handles the route and loads the rest of the application from directories that are not directly public.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Ubuntu supplies the operating system and package manager.
  • Apache serves HTTP and HTTPS traffic and passes PHP files to the PHP Apache module.
  • PHP runs CakePHP and its required extensions.
  • MySQL or MariaDB stores application data.
  • Composer installs the framework and locks the dependency tree.
  • DNS maps your domain to the VPS, and a TLS certificate protects the connection.

Keep source code, configuration, environment files and dependency metadata outside Apache’s document root. Only webroot should be exposed.

Check CakePHP and PHP compatibility first

Do this before creating a project. A VPS image can have a PHP version that is too old for the CakePHP branch you intend to use, while a newer PHP release may require a newer CakePHP branch.

Component Requirement or qualification
CakePHP 5.0 PHP 8.1 minimum.
CakePHP 5.1 and newer Compatibility with PHP 8.4 and PHP 8.5 is listed for these newer CakePHP 5 branches; verify the exact minor release before upgrading.
CakePHP 4.x and 3.x Each branch has its own PHP support range. Check the project compatibility information instead of assuming CakePHP 5 requirements apply.
CakePHP 2.x End-of-life; do not select it for a new public deployment.
Required PHP extensions for CakePHP 5 mbstring, intl, SimpleXML and PDO, plus the PDO driver for your database.
Supported database examples MySQL 5.7 or newer and MariaDB 10.1 or newer are listed among supported versions.

After you receive the VPS, run php -v and php -m. Confirm the reported PHP version, then check that mbstring, intl, SimpleXML and pdo_mysql (for MySQL or MariaDB) appear in the module list. Pin the CakePHP major and minor version in Composer rather than allowing an unplanned framework change during deployment.

Choose a VPS that can run the stack

You need an Ubuntu image with sudo access, a public IPv4 address (and IPv6 if you plan to use it), enough storage for the operating system, logs, database and backups, and the ability to install Apache, PHP and Composer. Before ordering, confirm these operational details:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Which Ubuntu release is offered and how long it receives security updates.
  • Which PHP versions are available in that release’s repositories.
  • Whether you will run MySQL or MariaDB yourself or use a managed database.
  • Whether snapshots, off-site backups and restore tests are available.
  • How DNS records, firewall rules, IPv4/IPv6, storage and network limits are managed.
  • Whether TLS automation and your preferred deployment method are practical in the region where your users connect.

The exact monthly price and resource limits vary by provider and change frequently, so verify them at the time you provision the server.

1. Update Ubuntu and install the LAMP components

Log in over SSH with the account supplied by your VPS provider. Use a non-root administrative account with sudo for routine work. Apply updates before adding application software.

sudo apt update
sudo apt full-upgrade -y

Install Apache, PHP, the Apache PHP module, the command-line interpreter, the database driver and the extensions CakePHP needs. Ubuntu package names can differ slightly between releases; use the release’s current package list if one name is unavailable.

sudo apt install -y apache2 mysql-server php libapache2-mod-php php-cli php-mysql php-mbstring php-intl php-xml unzip git

php-xml supplies XML functionality, including SimpleXML on standard Ubuntu builds. If you choose MariaDB, install its server package instead of MySQL’s server package; keep php-mysql because it provides the PHP MySQL/PDO driver used by both.

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

Check the installed versions and service state:

php -v
php -m
sudo systemctl status apache2
sudo systemctl status mysql

The libapache2-mod-php package configures Apache to execute PHP scripts. Restart or reload Apache after changing PHP modules or Apache configuration. If a firewall is enabled, allow SSH and web traffic while keeping the database port private unless a specific architecture requires remote access.

2. Install Composer securely

Install Composer using the Composer project’s current secure installer procedure, including its signature verification step. You can place the verified binary on the system path so the deployment account can call it:

sudo mv composer.phar /usr/local/bin/composer
sudo chmod 0755 /usr/local/bin/composer
composer --version

Do not copy an unchecked installer or a Composer binary from an unknown source. The version output confirms that the shell can find the command, but it does not replace signature verification.

3. Create the CakePHP project outside the public directory

Use a private application directory such as /var/www/cakeapp. The parent directory is not Apache’s document root; the public root will be a child named webroot.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo mkdir -p /var/www
sudo chown "$USER":"$USER" /var/www
cd /var/www
composer create-project --prefer-dist cakephp/app cakeapp
cd /var/www/cakeapp

The create-project command downloads the application skeleton and its dependencies. For a reproducible release, commit the generated lock file to your private repository and use the intended CakePHP version constraint. Do not place .env, config, src, templates or vendor directly under a directory that Apache exposes.

Confirm that the project contains webroot/index.php and a webroot/.htaccess file. The latter is used when Apache is configured to permit overrides.

4. Create a dedicated database and account

Run the database hardening routine supplied by your Ubuntu release, remove anonymous accounts and test databases, and restrict administrative access. Then create an application database and a separate login. The application account should not be the database root account.

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

The password in this example is illustrative; generate a unique secret and store it in a protected deployment secret store or an unreadable local configuration file. If your application does not run schema migrations itself, you can use a separate migration account and give the runtime account only the permissions it needs.

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

5. Configure CakePHP’s database connection

CakePHP keeps machine-specific settings in config/app_local.php. Edit that file on the server, or generate it from protected deployment variables, rather than committing production credentials to a public repository.

'Datasources' => [
    'default' => [
        'className' => 'Cake\Database\Connection',
        'driver' => 'Cake\Database\Driver\Mysql',
        'host' => '127.0.0.1',
        'username' => 'cakeapp_user',
        'password' => 'use-a-long-random-password',
        'database' => 'cakeapp',
        'encoding' => 'utf8mb4',
        'timezone' => 'UTC',
        'cacheMetadata' => true,
    ],
],

Use the Unix socket instead of 127.0.0.1 only when your database installation and PHP configuration require it. A connection failure can result from a wrong host, socket, database name, password, missing PDO driver or missing grant; test each of those independently.

6. Set secrets, environment and file permissions

Replace sample security values

Change the sample security salt and encryption keys in your local configuration. They must be unpredictable and unique to this installation; a key of at least 32 characters is a practical minimum for generated application secrets. Never reuse a value from documentation, source control or another application.

Disable debug output

Set the application environment to production and turn debug mode off before the VPS is reachable from the public internet. Debug pages can disclose SQL statements, filesystem paths, credentials in configuration and full stack traces. Send diagnostic details to protected logs instead.

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.

Give Apache only the writes it needs

Determine the account used by Apache on Ubuntu, normally www-data. The runtime directories for cache, logs and temporary files must be writable by that account, but the entire project should not be world-writable.

sudo chown -R www-data:www-data /var/www/cakeapp/tmp /var/www/cakeapp/logs
sudo find /var/www/cakeapp -type d -exec chmod 0755 {} ;
sudo find /var/www/cakeapp -type f -exec chmod 0644 {} ;

Apply tighter ownership to config/app_local.php if your deployment process permits it, and ensure the SSH user can still perform controlled releases. Do not solve a permission error by applying chmod -R 777 to the project.

7. Point Apache at webroot

Create a name-based virtual host for the domain. The critical setting is DocumentRoot: it must end in /webroot, not the project root.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/cakeapp/webroot

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

    ErrorLog ${APACHE_LOG_DIR}/cakeapp_error.log
    CustomLog ${APACHE_LOG_DIR}/cakeapp_access.log combined
</VirtualHost>

Save the file under Apache’s sites-available directory, then enable the site and rewrite module:

sudo a2enmod rewrite
sudo a2ensite cakeapp.conf
sudo a2dissite 000-default.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

Keep the default site enabled if you intentionally use it for another hostname; the important point is that the requested domain resolves to the CakePHP virtual host. AllowOverride All permits CakePHP’s webroot/.htaccess rules to work. On a tightly controlled server you can replace it with a narrower override policy, but do not block the rewrite directives the application needs.

Check rewrite support directly:

sudo apache2ctl -M | grep rewrite

If the module is absent, routes that are not the front page commonly return 404 even though the application is installed correctly.

8. Add the domain and HTTPS

Register or use a domain you control. Create an A record for the apex name pointing to the VPS IPv4 address and, if you serve www, create the corresponding record or alias. Allow DNS time to propagate and confirm that both hostnames reach the intended virtual host before requesting a certificate.

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

Obtain a certificate from a current certificate authority such as Let’s Encrypt using the certificate authority’s supported Ubuntu client. A common Apache-based workflow is:

sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache -d example.com -d www.example.com

Choose the redirect option so HTTP requests are sent to HTTPS, then test renewal with the client’s dry-run function. Keep renewal automated and monitor its failures. If a reverse proxy or load balancer sits in front of Apache, configure forwarded-protocol headers correctly so CakePHP does not generate HTTP asset URLs for an HTTPS request.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

9. Install production dependencies and release the application

For a controlled release, put the exact source revision and lock file on the server, then install only production dependencies:

cd /var/www/cakeapp
composer install --no-dev --optimize-autoloader

Run database migrations or other CakePHP deployment commands as a deliberate release step, not automatically on every web request. Make a database backup before a schema change, record the migration revision, and keep a rollback plan that covers both code and schema.

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

When replacing a live release, upload to a new versioned directory and switch a symlink, or use an equivalent atomic deployment method. This prevents visitors from seeing a mixture of old and new files while Composer is running. Keep config/app_local.php and generated runtime directories outside the versioned artifact when your deployment design supports that separation.

10. Verify the installation before launch

Test from a client that resolves the real domain, not only from localhost on the VPS.

  1. Open the HTTPS homepage and confirm that the certificate hostname matches.
  2. Visit a non-root CakePHP route. A route that works only at / indicates a rewrite or .htaccess problem.
  3. Submit a form and confirm validation, CSRF protection and the expected response.
  4. Exercise a database read and write, then verify the record directly or through an administrative view.
  5. Inspect Apache’s access and error logs and CakePHP’s application logs for warnings, failed connections and permission errors.
  6. Confirm that visitors see a generic error page rather than PHP warnings or stack traces.
  7. Delete any temporary phpinfo.php file used to inspect PHP.
  8. Check that HTTP redirects to HTTPS and that CSS, JavaScript and image assets load without mixed-content warnings.

Troubleshooting common failures

Symptom Likely cause Checks and corrective action
Every route except / returns 404 mod_rewrite is disabled, or Apache is ignoring .htaccess. Run sudo apache2ctl -M | grep rewrite; confirm AllowOverride All in the active virtual host; verify webroot/.htaccess exists; reload Apache after changes.
PHP source downloads or appears as text The PHP Apache module is missing, disabled or not associated with the installed PHP version. Verify libapache2-mod-php, inspect enabled PHP modules, run apache2ctl configtest, then restart Apache.
Database connection failure Incorrect host or socket, credentials, database name, PDO driver or grants. Check php-mysql and pdo_mysql, re-read config/app_local.php, test the account with the MySQL client, and inspect database and CakePHP logs.
Permission denied while writing cache or logs Runtime directories belong to the wrong account or have restrictive modes. Confirm the Apache service user, inspect ownership and write bits on tmp and logs, and grant access only to those directories.
HTTPS works but assets are blocked as mixed content Hard-coded HTTP URLs, an incorrect application base URL or missing proxy headers. Use CakePHP asset helpers, correct the base URL and redirect settings, and configure forwarded HTTPS headers when a proxy terminates TLS.
The wrong site appears for the domain DNS points elsewhere or Apache selected another virtual host. Check DNS resolution, ServerName/ServerAlias, enabled sites and the Apache access log for the request’s host.
Composer fails during deployment PHP version or extension mismatch, unavailable network access, or a lock file incompatible with the runtime. Compare php -v and php -m with the CakePHP branch requirements, install missing extensions, and run Composer with the committed lock file.

Production checklist

  • PHP meets the selected CakePHP branch’s support range, with mbstring, intl, SimpleXML and the correct PDO driver enabled.
  • Apache’s virtual host serves only webroot.
  • mod_rewrite is enabled and the active directory policy permits the required overrides.
  • The database uses a dedicated non-root account and utf8mb4 with UTC application settings.
  • Security salts, encryption keys and database passwords are unique, unpredictable and absent from public source control.
  • Debug mode is off, and logs are protected from direct web access.
  • Runtime directories are writable by Apache without making the project world-writable.
  • DNS A records point to the VPS, HTTPS covers every hostname you publish, and HTTP redirects to HTTPS.
  • Certificate renewal, operating-system updates, database backups and restore tests are scheduled.
  • Production dependencies are installed with composer install --no-dev --optimize-autoloader from a known lock file.
  • A routed URL, form submission, database transaction, logs, error handling and asset loading have all been tested over HTTPS.

Keeping the VPS maintainable

Apply Ubuntu security updates and CakePHP dependency updates in a staging or maintenance workflow, review Composer changes before deployment, and take a tested database backup before migrations. Monitor disk space, memory, Apache errors, certificate renewal and failed login attempts. When PHP or CakePHP reaches the end of its support window, plan a versioned upgrade rather than changing the runtime in place without testing.

This layout separates public files from application internals, gives Apache the rewrite rules CakePHP expects, and makes the database, secrets, TLS and release process explicit. Those boundaries are what turn a working development page into a defensible VPS deployment.

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

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.