Introduction:
Deploying a Laravel application on shared cPanel hosting may seem complex, but with Prabhu Host's cloud infrastructure and SSH access, it’s smooth and manageable. This step-by-step guide helps you properly set up and run your Laravel project without running into common errors.
Step-by-Step Laravel Deployment on cPanel
Step 1: Log in to cPanel
Access your cPanel account via:
https://cpanel.yourdomain.com
Or:
http://yourdomain.com:2083
Step 2: Install Composer in Terminal
To install and use Composer on your hosting environment:
- Open the cPanel Terminal (from the "Advanced" section).
- Run the following commands (replace USERNAME with your actual cPanel username):
echo 'alias composer="php -d allow_url_fopen=On /home/USERNAME/composer.phar"' >> ~/.bashrc
source ~/.bashrc
- Download and install Composer:
curl -k -O https://getcomposer.org/installer
php -d allow_url_fopen=On installer
Step 3: Set Up Git Integration
Generate an SSH key to connect your GitHub or Bitbucket repository:
ssh-keygen -t rsa -b 4096 -C "YOUR_EMAIL"
Then view the key:
cat ~/.ssh/id_rsa.pub
- For GitHub: Go to your repo → Settings → Deploy Keys → Add key
- For Bitbucket: Go to your repo → Settings → Access Keys → Add key
Paste the copied key in the appropriate location.
Step 4: Laravel Project Setup
- Create a folder outside public_html, for example ~/myapp.
- Clone your Laravel repository:
git clone git@github.com:username/repo.git myapp
- Navigate into the project directory:
cd myapp
composer install
- Set your environment:
cp .env.example .env
php artisan key:generate
- Set file permissions:
chmod -R 775 storage
- Run database migrations (make sure DB credentials are set in .env):
php artisan migrate
Step 5: Make Laravel Accessible via Public Directory
- Back up and remove the existing public_html folder:
rm -rf ~/public_html
- Create a symbolic link from Laravel's /public to public_html:
ln -s ~/myapp/public ~/public_html
- Link Laravel’s storage directory to make uploads work:
php artisan storage:link
With these steps, your Laravel application is now accessible to the public, and you can conveniently perform Git pulls directly from cPanel. As an added convenience, you can create a deployment script to automate the process:
php artisan down
git pull origin master
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
php artisan migrate --force
php artisan cache:clear
php artisan route:clear
php artisan route:cache
php artisan config:clear
php artisan config:cache
php artisan up
With Prabhu Host’s cPanel Cloud Hosting, deploying your Laravel application is fast and hassle-free — so you can focus on developing powerful applications while we handle the infrastructure. Build smarter with Prabhu Host.
