How To Host A Laravel Website

May 26, 2023 Laravel

How to Host a Laravel Website: Manual Upload Process with cPanel Hosting

Reading Time: 2 minutes

Hosting a Laravel website manually using cPanel provides you with control and flexibility over the deployment process. In this guide, we will walk you through the step-by-step process of hosting a Laravel website using cPanel hosting. This method allows you to upload your Laravel project using cPanel’s file manager and manage your website’s settings easily.

Step 1: Choose a cPanel Web Hosting Provider

Start by selecting a web hosting provider that offers cPanel hosting. Sign up for a hosting plan that meets your requirements and provides support for Laravel’s requirements.

Step 2: Configure Your Domain

After signing up for a cPanel hosting plan, configure your domain to point to the hosting provider’s nameservers. This allows your domain to be associated with your hosting account.

Step 3: Access cPanel and Create a Database

Once your domain is configured, you can access cPanel. Login to your cPanel account using the credentials provided by your hosting provider. Follow these steps to create a MySQL database for your Laravel project:

  1. Locate the “Databases” section in cPanel and click on “MySQL Databases.”
  2. Create a new database by entering a name for the database and clicking on the “Create Database” button.
  3. After creating the database, scroll down to the “MySQL Users” section and create a new user.
  4. Assign the user to the database by selecting the appropriate user and database from the dropdown menus.
  5. Make a note of the database name, username, and password for later use.

Step 4: Prepare Your Laravel Project for Deployment

Before uploading your Laravel project, ensure that it is ready for deployment:

  1. Remove any unnecessary files and directories, such as the tests folder.
  2. Optimize your Laravel application by running the following commands from your project’s root directory:
composer install --optimize-autoloader --no-dev
php artisan config:cache
php artisan route:cache

These commands optimize the autoloader, cache the configuration, and cache the routes for improved performance.

Step 5: Upload Laravel Project Files via cPanel File Manager

Follow these steps to upload your Laravel project files using cPanel’s file manager:

  1. In cPanel, locate the “File Manager” icon and click on it to open the file manager interface.
  2. Navigate to the public_html directory or the document root of your domain.
  3. Click on the “Upload” button in the file manager and select your Laravel project’s ZIP file.
  4. Once the ZIP file is uploaded, select it and click on the “Extract” button to extract the contents.
  5. After extraction, ensure that all Laravel project files are present in the desired directory.

Step 6: Configure Environment Variables

Update the `.env` file in your Laravel project’s root directory with the appropriate environment variables. Use the MySQL database details obtained in Step 3. For example:

APP_URL=http://your_website_url
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password

Replace “your_website_url,” “your_database_name,” “your_username,” and “your_password” with the actual values corresponding to your database setup.

Step 7: Set Folder Permissions

Ensure that the storage and bootstrap/cache directories have proper write permissions. You can set the permissions using the following commands from your Laravel project’s root directory:

chmod -R 775 storage
chmod -R 775 bootstrap/cache

Step 8: Test Your Website

With your Laravel project uploaded and configured, you can test your website by visiting your domain in a web browser. If everything is set up correctly, you should see your Laravel website up and running.

Conclusion:

By following these steps, you can manually host your Laravel website using cPanel hosting. Remember to choose a hosting provider that supports Laravel’s requirements, create a database, upload your project files, configure environment variables, set folder permissions, and test your website to ensure everything is working as expected.

SHARE NOW

Leave a Reply

Your email address will not be published. Required fields are marked *