DEV Community

bundle Hub
bundle Hub

Posted on

Deploying a Laravel PHP Script to Shared Hosting Without Breaking It

Deploying a Laravel application to shared hosting feels different from deploying to a VPS. You do not get full control over the server, you cannot always run long commands, and a small mistake can leave visitors staring at a blank page or a 500 error. Most of the time the cause is a missed step before the upload. This guide walks through the deployment in the order I now follow, so you can move a working local project to shared hosting without breaking it.

1. Check the PHP version and extensions first

Before you upload anything, check what your hosting plan actually supports. Open the PHP selector in your hosting panel and compare it with the version in your project's composer.json file. If the project needs PHP 8.2 and your host is still running PHP 8.0, stop and fix that first. Also check the extensions the project needs, such as BCMath, Ctype, Fileinfo, JSON, Mbstring, OpenSSL, PDO, Tokenizer, and XML. A missing extension often shows up as a strange error during installation, long after you thought the upload had worked.

2. Upload the files and point the domain to public

Upload your project one level above the public folder when you can, so files such as .env and the vendor folder are not directly reachable from a browser. Then point your domain or subdomain to the project's public folder. In cPanel this is usually done through Domains, where you can change the document root. If your host does not let you change it, you can move the contents of public into public_html and adjust the paths, but that is a workaround, not the clean setup. Upload the files as a compressed archive when possible and extract them on the server. It is faster and less likely to miss a file than uploading thousands of small files one by one. If you are starting from a ready-made project, browse PHP scripts and source code and read its requirements before you upload anything.

3. Configure .env safely

Copy .env.example to .env on the server and edit it there. Never upload your local .env file as it is, and never commit it to a public repository. Set the app name, app URL, and database details for the live site. Keep APP_DEBUG false on a live site, because debug pages can expose sensitive details. Generate a fresh key with php artisan key:generate and check that it is present in the live .env file.

4. Run migrations and seeders carefully

Create an empty database in your hosting panel first, then add a database user and give that user access to it. Put those details in .env, then run the migrations. The usual command is php artisan migrate --force. The --force flag matters on a live server because Laravel will otherwise ask for confirmation. If the project comes with seeders for an admin account or basic settings, run them only if the documentation says to. Back up the database before migrating a live site.

5. Set file permissions

Laravel needs to write to the storage and bootstrap/cache folders. If those folders are not writable, you will see errors when the app tries to log something, store a session, or save an uploaded file. Set the folders to 775 where your host allows it, and keep files at 644. Avoid 777 unless your host specifically tells you to use it, because it gives everyone write access. After that, clear the cached configuration and load the site again.

6. Enable HTTPS

Turn on the free SSL certificate in your hosting panel and force HTTPS in your app. Set the app URL in .env to start with https, and check that images, styles, and scripts load over HTTPS too. Mixed content can break the layout and show a warning in the browser. Visit the site in a private window after the certificate is active, so you are not looking at a cached version.

7. Post-deploy test checklist

Before you share the link, run through this list:

  • Home page loads without a 500 error.
  • Login, registration, and password reset work.
  • Forms save data and show the right message.
  • File uploads, images, and emails work.
  • Admin panel opens and the main pages load.
  • The site works on a phone as well as a desktop.

Deployment is mostly careful preparation. Check the requirements, keep the document root and .env file correct, migrate with a backup in place, and test the site as a visitor would. Do that, and shared hosting can run a Laravel project reliably. For more ready-made projects and learning resources, visit Bundle Hub.

Top comments (0)