Deploying a Laravel site on Shared Hosting Subdomain
Tags: webdev, laravel, php, beginners
Published: 2024-04-01 17:01:46

**Introduction**
In recent years, Laravel has emerged as one of the most popular PHP frameworks for web development, thanks to its elegant syntax, powerful features, and robust ecosystem. While deploying a Laravel site on a dedicated server or cloud platform is straightforward, deploying it on a shared hosting environment, particularly on a subdomain, can present some challenges. In this article, I will guide you through the process of deploying a Laravel site on a shared hosting subdomain using a real-world example.

**Step 1: Prepare Your Laravel Application**
Before deploying your Laravel application, ensure that it is fully configured and functional on your local development environment. This includes setting up database connections, configuring environment variables, and testing the application thoroughly.

**Step 2: Zip Your Project Files**
Once your Laravel application is ready for deployment, zip the project files, including all directories and files, from your local computer. This compressed archive will be uploaded to your shared hosting subdomain.

**Step 3: Upload the Zipped File to Your Subdomain**
Access your shared hosting account's control panel or file manager and navigate to the directory corresponding to your subdomain. Upload the zipped project file to this directory.

**Step 4: Unzip the Project Files**
After uploading the zipped file, unzip it directly in the subdomain directory. This will extract all the project files into the appropriate location for your Laravel application to run.

**Step 5: Adjust File Paths in index.php**
Open the `index.php` file located in the public directory of your subdomain for editing. Update the file paths to reflect the correct location of the Laravel application's maintenance.php file. Modify the following line:

```php
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php'))
```

to:

```php
if (file_exists($maintenance = __DIR__.'/storage/framework/maintenance.php'))
```

This change ensures that Laravel can locate the maintenance.php file correctly.

Do the same for the other locations url

**Step 6: Copy Files to the Public Directory**
By default, Laravel's entry point is the `public` directory. Therefore, you need to **copy all files and folders from the extracted and edited public directory** into the **root folder of the project files of your subdomain**. This ensures that the Laravel application's index.php file is accessible from the web.

**Step 7: Modify the .env File**
Open the **.env** file in the root directory of your Laravel application and update the environment variables to match your shared hosting environment. This includes **database connection settings, application URL, and any other configuration variables relevant to your deployment**.

**Step 8: Test Your Laravel Application**
Once you have completed the deployment steps and made modifications to the **.env** file, it's time to test your Laravel application. Access your subdomain URL in a web browser to verify that the application is running correctly. Ensure that all pages, routes, and functionalities are working as expected.

**Conclusion**
Deploying a Laravel site on a shared hosting subdomain may require some additional steps compared to other hosting environments. However, by following the steps outlined in this guide, you can successfully deploy your Laravel application and make it accessible to users on your shared hosting subdomain. With your application up and running, you can now focus on delivering a seamless experience to your users and continue to enhance your Laravel project.