How to deploy Laravel on our shared hosting
Follow these steps for a clean Laravel deployment on a shared plan. If you get stuck, send our support team a message on WhatsApp and we will finish it with you.
1. Create the database. In the control panel, create a MySQL database and user. Keep the name, user and password for your .env file.
2. Put the code outside the web root. Connect over SSH and clone your repository into a folder such as ~/laravel-app, next to public_html rather than inside it. That way your .env file, storage and source code can never be downloaded.
3. Install dependencies. Inside the project folder run composer install --no-dev --optimize-autoloader. Build your front-end assets with npm run build on your computer or on the server, so the compiled files in public/build are ready.
4. Configure the environment. Copy .env.example to .env, fill in the database details, set APP_ENV=production, APP_DEBUG=false and your APP_URL with https, then run php artisan key:generate.
5. Point your domain at the public folder. Laravel must be served from its public directory. The simplest way is to replace public_html with a link to it (ln -s ~/laravel-app/public ~/domains/yourdomain.pk/public_html, after moving the old folder aside). Our support team can set this up for you.
6. Migrate and optimise. Run php artisan migrate --force, php artisan storage:link and php artisan optimize. Make sure storage and bootstrap/cache are writable.
7. Add the scheduler and queue. Add a cron job that runs every minute: cd ~/laravel-app && php artisan schedule:run. For queued jobs on shared hosting, use the database queue driver and schedule queue:work --stop-when-empty, so jobs are processed without a permanent worker.
For future updates, the routine is short: git pull, composer install --no-dev, php artisan migrate --force and php artisan optimize.