Development and databases
Deploy WordPress and Laravel on cPanel with Deployer
If you'd rather not maintain your own deployment process, Deploy+ integrates with your GitHub repository and does it from the client area: Deploy+, automatic deployment from GitHub.
Deployer is a tool written in PHP that publishes your application to the server over SSH with a single command. Each deployment is prepared in a new folder and, when it's ready, it's activated by switching a symbolic link. This means:
- The website keeps working while the new version is being prepared.
- You can go back to the previous version instantly with
dep rollback. - The process is always the same, with no manual steps to forget.
All our hosting plans are compatible with Deployer. In this guide you'll see two complete examples: WordPress and Laravel.
1. Set up SSH access
Deployer works over SSH, so you need to:
- Enable SSH access on your hosting.
- Connect with an SSH key from your computer. A password also works, but it would keep asking you for it.
Check that you can connect without any problems (our SSH port is 93):
ssh -p 93 usuario_cpanel@tudominio.com
If your repository is private, the server also needs to be able to download it from GitHub: follow clone a private GitHub repository to create its key and add it as a deploy key.
2. Install Deployer on your computer
Deployer is installed and run on your computer, not on the hosting. The current version is 8 and it needs PHP 8.3 or higher on your machine. The most convenient option is to add it to the project:
composer require --dev deployer/deployer:^8 vendor/bin/dep --version
You can also install it globally with composer global require deployer/deployer and use the dep command directly. In the examples we use vendor/bin/dep.
3. Choose where to deploy
Deployer creates this structure inside the deployment path (deploy_path):
/home/usuario_cpanel/apps/miapp/ ← deploy_path ├── releases/ │ ├── 1/ │ ├── 2/ │ └── 3/ ← latest version ├── shared/ ← what is kept between versions │ ├── .env (Laravel) │ ├── storage/ (Laravel) │ ├── wp-config.php (WordPress) │ └── wp-content/uploads/ (WordPress) ├── current -> releases/3 ← published version └── .dep/
In Deployer's files that path is written {{deploy_path}}, so the published version is {{deploy_path}}/current.
Use a folder outside public_html, for example /home/usuario_cpanel/apps/miapp. The website has to be served from:
- WordPress:
/home/usuario_cpanel/apps/miapp/current - Laravel:
/home/usuario_cpanel/apps/miapp/current/public
How you achieve this depends on the domain:
- Addon domain or subdomain: in cPanel, go to Domains, click Manage on the domain and change its Document Root to that path. The steps are in change the path of an addon domain.
- Main domain: it always uses
public_htmland its path can't be changed. The solution is to turnpublic_htmlinto a symbolic link, as you'll see in step 7.
If it's your first time with Deployer, start with a test subdomain, for example pruebas.tudominio.com.
4. WordPress example
This example assumes the repository contains a standard WordPress installation with its plugins and theme. Create deploy.php in the root of the project:
<?php namespace Deployer; require 'recipe/wordpress.php'; set('repository', 'git@github.com:tu_usuario/tu_repo_wordpress.git'); set('branch', 'main'); set('keep_releases', 3); // Kept between versions set('shared_files', ['wp-config.php']); set('shared_dirs', ['wp-content/uploads']); set('writable_dirs', ['wp-content/uploads']); set('writable_mode', 'chmod'); set('writable_chmod_mode', '0755'); host('produccion') ->setHostname('tudominio.com') ->setRemoteUser('usuario_cpanel') ->setPort(93) ->setIdentityFile('~/.ssh/id_ed25519') ->set('deploy_path', '/home/usuario_cpanel/apps/miapp'); after('deploy:failed', 'deploy:unlock');
Before the first deployment, prepare the shared folder on the server:
-
Create the database and its user in cPanel's MySQL Databases.
-
Over SSH, create the folders:
mkdir -p /home/usuario_cpanel/apps/miapp/shared/wp-content/uploads -
Create
/home/usuario_cpanel/apps/miapp/shared/wp-config.phpfromwp-config-sample.php, with the database details and new keys generated at api.wordpress.org/secret-key/1.1/salt. If you're moving an existing website, copy itswp-config.phpas it is, with the same table prefix. -
If the website already has images, copy them to
shared/wp-content/uploads.
Don't upload wp-config.php or uploads to the repository.
Bear in mind that plugins and the theme are published from Git: if you update them from the WordPress dashboard, the next deployment will take them back to the repository version. Update them in your local copy, commit and deploy.
5. Laravel example
<?php namespace Deployer; require 'recipe/laravel.php'; set('repository', 'git@github.com:tu_usuario/tu_repo_laravel.git'); set('branch', 'main'); set('keep_releases', 3); set('writable_mode', 'chmod'); set('writable_chmod_mode', '0755'); // Hosting PHP used to run Composer and artisan set('bin/php', '/opt/alt/php83/usr/bin/php'); host('produccion') ->setHostname('tudominio.com') ->setRemoteUser('usuario_cpanel') ->setPort(93) ->setIdentityFile('~/.ssh/id_ed25519') ->set('deploy_path', '/home/usuario_cpanel/apps/miapp'); task('deploy', [ 'deploy:prepare', 'deploy:vendors', 'artisan:storage:link', 'artisan:config:cache', 'artisan:route:cache', 'artisan:view:cache', 'artisan:migrate', 'deploy:publish', ]); after('deploy:failed', 'deploy:unlock');
The Laravel recipe already shares .env and storage between versions. Change php83 to the version your project needs (the same one the domain has in cPanel): the available paths are /opt/alt/php81/usr/bin/php, /opt/alt/php82/usr/bin/php, etc. If you don't want migrations to run automatically, remove the artisan:migrate line.
Before the first deployment, create the database in cPanel and, over SSH, the shared .env file:
mkdir -p /home/usuario_cpanel/apps/miapp/shared
nano /home/usuario_cpanel/apps/miapp/shared/.env
With contents like these:
APP_NAME="Mi aplicación" APP_ENV=production APP_KEY=base64:... APP_DEBUG=false APP_URL=https://tudominio.com LOG_LEVEL=error DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=usuario_cpanel_basedatos DB_USERNAME=usuario_cpanel_usuario DB_PASSWORD=la_contraseña CACHE_STORE=file SESSION_DRIVER=file QUEUE_CONNECTION=database
For APP_KEY: if the application is already in production, copy the one it has (if you change it, sessions are closed and you won't be able to read encrypted data). If it's new, generate it on your computer with php artisan key:generate --show and paste it.
If the project needs to build CSS and JS (Vite, Mix…), build them and upload them in the repository, or add a task that runs npm run build before deploy:publish. You can find how to use Node on the hosting in install Node.js and build assets.
6. Deploy
From the project folder on your computer, first check which tasks are going to run:
vendor/bin/dep deploy --plan produccion
And deploy:
vendor/bin/dep deploy produccion
Deployer clones the repository into a new releases folder, installs the dependencies, links the shared files and, finally, points current to the new version. Open the website and check that it works.
To go back to the previous version:
vendor/bin/dep rollback produccion
Rollback changes the published code, but it doesn't undo changes to the database or to the shared files. If a migration has modified tables, you'll have to revert it separately.
7. Main domain: link public_html
The main domain is always served from public_html. The solution is to replace that folder with a symbolic link pointing to the published version. Do it only once, after the first deployment (when current already exists):
cd /home/usuario_cpanel mv public_html public_html.antiguo # Laravel ln -s /home/usuario_cpanel/apps/miapp/current/public public_html # WordPress ln -s /home/usuario_cpanel/apps/miapp/current public_html
Check it with ls -l /home/usuario_cpanel: you should see public_html -> /home/usuario_cpanel/apps/miapp/current/public (or .../current for WordPress). As current changes with each deployment, the link always leads to the latest version, including after a rollback.
Before you do this, check whether there are folders for other domains or subdomains inside public_html: they would stop working. Move them to another path first and change those domains' document root. Once you've checked that everything is working, you can delete public_html.antiguo.
Common errors
It won't connect over SSH
- Test the connection manually:
ssh -p 93 -i ~/.ssh/id_ed25519 usuario_cpanel@tudominio.com. - The public key has to be authorised in cPanel, under SSH Access > Manage SSH Keys.
- The private key on your computer must have restricted permissions:
chmod 600 ~/.ssh/id_ed25519. - If connection reuse causes problems, add
set('ssh_multiplexing', false);.
Cloning the repository fails
- It's the server that clones: its key (
~/.ssh/id_ed25519on the hosting) must be in GitHub as a deploy key. Test it over SSH on the hosting withssh -T git@github.com. - Alternative: add
->setForwardAgent(true)to the host so it uses your computer's key, loaded withssh-add.
deploy:vendors fails (Composer)
- The PHP in
bin/phpdoesn't meet the requirements ofcomposer.lock: set the path to the correct version. - If it runs out of memory, see Composer memory errors.
artisan:migrate fails
- Check the database details in
shared/.env. In cPanel, the database and the user are prefixed with your cPanel username (usuario_cpanel_). - The database user needs all privileges on it.
The website gives a 404 or 500 error, or shows the old version
- Check with
ls -lthat the domain's document root orpublic_htmlpoints tocurrent/public(Laravel) orcurrent(WordPress). - In Laravel, look at the error in
/home/usuario_cpanel/apps/miapp/shared/storage/logs/laravel.log. - If you use LiteSpeed cache or OPcache and still see the previous version, clear the cache.
Deployer says the deployment is locked
A previous deployment was interrupted. If you're sure no other one is running, run vendor/bin/dep deploy:unlock produccion.
Deployer's cPanel recipe
Deployer includes a contrib/cpanel.php recipe that creates test domains and databases automatically. It doesn't work on shared hosting: it needs a WHM token with server administrator access (root user, port 2087). Create the test subdomain and database from cPanel and deploy to them with the configuration in this guide.
You may also find useful
- Automate deployment in cPanel with the .cpanel.yml file How to write the .cpanel.yml file with the tasks for each deployment in cPanel's Git, when it runs (...
- Clone and deploy from a private remote repository Authorise a hosting SSH key on GitHub, clone a private repository, check the connection and apply ch...
- Automatic deployment from GitHub to cPanel with Git and .cpanel.yml (Laravel example) Step by step to clone a private GitHub repository in cPanel, define the deployment tasks in .cpanel....
- Automatic deployment from GitHub, GitLab or Bitbucket with instant rollback Connect a Git repository to your hosting, run per-release scripts with deployment and .env variables...
Something wrong or out of date? Tell us and we will review it.