How to Deploy A Laravel Project on Cpanel?

15 minutes read

To deploy a Laravel project on cPanel, follow these steps:

  1. Access cPanel: Start by logging in to your cPanel account provided by your hosting provider.
  2. Create a new subdomain: Create a subdomain (e.g., laravel.yourdomain.com) from the cPanel's Domains section. Make sure to link it to the desired directory where the Laravel project will be deployed.
  3. Upload the project files: Use the cPanel's File Manager or an FTP client to upload your Laravel project files into the previously created subdomain's directory.
  4. Set up a database: Go to the MySQL Databases section in cPanel and create a new database. Note down the database name, username, and password as they will be needed later.
  5. Update database credentials: In your Laravel project folder, find the .env file and update the database credentials (DB_HOST, DB_DATABASE, DB_USERNAME, DB_PASSWORD) with the details of the database you created in the previous step.
  6. Set folder permissions: Ensure that the storage and bootstrap/cache directories, located in your Laravel project folder, have the necessary permissions (usually 755 or 777). This can be set using the File Manager or through SSH.
  7. Run composer install: From the cPanel's terminal or via SSH, navigate to your Laravel project folder and run the composer install command. This will install the necessary dependencies.
  8. Generate an application key: While still in the terminal or SSH, run the php artisan key:generate command in your Laravel project folder to generate an application encryption key.
  9. Migrate the database: Run the php artisan migrate command to create the required tables in the database.
  10. Set up cron jobs (optional): If your Laravel application relies on scheduled tasks, you can set them up through the "Cron Jobs" section in cPanel, specifying the command to execute at the desired intervals.
  11. Configure your .htaccess file: Create a new .htaccess file in the public folder of your Laravel project (if it doesn't exist) and add the following code to it:
1
2
3
4
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>


  1. Access your deployed Laravel project: You can now access your deployed Laravel project by visiting the subdomain (e.g., laravel.yourdomain.com) in your web browser.


That's it! Your Laravel project should now be successfully deployed and accessible through cPanel.

Best Laravel Cloud Hosting Providers in 2024

1
DigitalOcean

Rating is 5 out of 5

DigitalOcean

2
AWS

Rating is 4.9 out of 5

AWS

3
Vultr

Rating is 4.8 out of 5

Vultr

4
Cloudways

Rating is 4.7 out of 5

Cloudways


What are the common pitfalls or errors faced while deploying Laravel on Cpanel, and how can they be resolved?

  1. Incorrect file permissions: A common issue while deploying Laravel on Cpanel is incorrect file permissions. Laravel requires specific file permissions to function properly. Ensure that all files and directories have the proper ownership and permissions based on your server's requirements. Use the following commands to set the correct permissions:
1
2
3
chown -R youruser:yourgroup /path/to/yourproject
chmod -R 755 /path/to/yourproject/storage
chmod -R 755 /path/to/yourproject/bootstrap/cache


  1. Incorrect folder structure: Another common mistake is not properly uploading Laravel's folder structure to the server. Make sure you upload all the files and folders from your Laravel project, including the hidden files (e.g., .env).
  2. PHP version mismatch: Laravel has specific PHP version requirements, and Cpanel may not have the required version set as the default. Check the PHP version set in Cpanel and make sure it meets Laravel's requirements. You can change the PHP version in Cpanel by modifying the .htaccess file or contacting your hosting provider.
  3. Missing PHP extensions: Laravel relies on certain PHP extensions to work correctly. Ensure that all required extensions are installed and enabled on your Cpanel server. Common extensions needed for Laravel include OpenSSL, PDO, Mbstring, Tokenizer, and XML.
  4. Incorrect .env file configuration: The .env file holds important configuration values for your Laravel application. Ensure that all database and environment configuration variables are correctly set in the .env file. Double-check the database connection details, cache driver, and other settings relevant to your application.
  5. Improperly configured Apache/Nginx virtual host: When deploying Laravel on Cpanel, you may need to configure the Apache or Nginx virtual host settings. Ensure that your virtual host points to the "public" directory of your Laravel project and has the necessary rewrite rules to enable URL rewriting.
  6. Insufficient memory limit: If you encounter memory-related errors or performance issues, it could be due to an insufficient memory limit set on your Cpanel server. Increase the memory limit in your php.ini or .htaccess file to meet the requirements of your Laravel application.


If you face any issues while deploying Laravel on Cpanel, it is recommended to check the Laravel documentation, contact your hosting provider for support, or seek assistance from the Laravel community.


What are the system requirements for deploying a Laravel project on Cpanel?

To deploy a Laravel project on cPanel, the minimum system requirements are:

  1. PHP version: Laravel 7.x and above require PHP 7.2.5 or higher. Ensure that your cPanel environment supports at least this version.
  2. PHP extensions: Enable the required PHP extensions for Laravel to run. Some important extensions are OpenSSL, PDO, Mbstring, Tokenizer, XML, Ctype, JSON, BCMath, and FileInfo.
  3. Composer: Install Composer on your cPanel server. Composer is a dependency manager for PHP and is used to install Laravel and its dependencies.
  4. Database: Ensure that your cPanel has a supported database such as MySQL or PostgreSQL. Laravel relies on a database to store application data.
  5. Web server: cPanel typically uses Apache or LiteSpeed as the web server. Both servers work fine with Laravel, but you may need to configure some server settings or rewrite rules for proper Laravel routing.
  6. Storage and cache permissions: Ensure that the storage and bootstrap/cache directories within your Laravel project have proper write permissions for the server. Laravel requires write access to these directories for file storage and caching.
  7. SSL certificate: It is highly recommended to have an SSL certificate installed on your cPanel server. Laravel performs better over HTTPS, and an SSL certificate ensures secure communication with the website.


It's important to note that these are minimum requirements, and for optimal performance, you may need a server with higher specs or additional features.


Are there any specific PHP modules or extensions that need to be installed for Laravel on Cpanel?

To run Laravel on cPanel, you need to ensure that the following PHP modules or extensions are installed:

  1. OpenSSL
  2. Mbstring
  3. JSON
  4. Tokenizer
  5. Fileinfo
  6. Ctype
  7. PCRE
  8. XML
  9. BCMath
  10. cURL


Generally, most cPanel installations already have these modules installed. However, if any of these modules are missing, you can enable them by following these steps:

  1. Log in to cPanel.
  2. Navigate to the "Software" section and click on "Select PHP Version."
  3. On the PHP Selector page, make sure the version of PHP being used by your Laravel application is selected from the drop-down menu.
  4. Click on the "Extensions" tab.
  5. Enable the required modules by checking the corresponding checkboxes.
  6. Click on "Save."


After enabling the required modules, your Laravel application should be ready to run on cPanel.

Top Rated Laravel Books of May 2024

1
Laravel: Up and Running: A Framework for Building Modern PHP Apps

Rating is 5 out of 5

Laravel: Up and Running: A Framework for Building Modern PHP Apps

2
Battle Ready Laravel: A guide to auditing, testing, fixing, and improving your Laravel applications

Rating is 4.9 out of 5

Battle Ready Laravel: A guide to auditing, testing, fixing, and improving your Laravel applications

3
Laravel: Up & Running: A Framework for Building Modern PHP Apps

Rating is 4.8 out of 5

Laravel: Up & Running: A Framework for Building Modern PHP Apps

4
High Performance with Laravel Octane: Learn to fine-tune and optimize PHP and Laravel apps using Octane and an asynchronous approach

Rating is 4.7 out of 5

High Performance with Laravel Octane: Learn to fine-tune and optimize PHP and Laravel apps using Octane and an asynchronous approach

5
Beginning Laravel: Build Websites with Laravel 5.8

Rating is 4.6 out of 5

Beginning Laravel: Build Websites with Laravel 5.8

6
Murach's PHP and MySQL (4th Edition)

Rating is 4.5 out of 5

Murach's PHP and MySQL (4th Edition)

7
PHP & MySQL: Server-side Web Development

Rating is 4.4 out of 5

PHP & MySQL: Server-side Web Development


Are there any specific considerations for deploying Laravel API projects on Cpanel?

There are a few considerations you should keep in mind when deploying Laravel API projects on cPanel:

  1. PHP Version: Make sure the server has the required PHP version (Laravel typically requires PHP 7 or above). You can check the PHP version by creating a PHP info file or contacting your hosting provider.
  2. Composer: Ensure that Composer is installed on your server. Composer is a dependency management tool used by Laravel. If it's not installed, you may need to contact your hosting provider to install it or consider using a different hosting environment.
  3. Environment Configuration: Laravel relies on environment configuration files such as .env to store sensitive information like database credentials. Ensure that your configuration files are properly set up or copied to your production environment, and make sure you have a backup copy.
  4. File Permissions: Set the appropriate file and directory permissions for Laravel files on your cPanel account. Laravel requires certain directories to have write access to cache files and logs. Directories like storage and bootstrap/cache should typically have write permissions.
  5. Apache Configuration: Verify that your cPanel server's Apache configuration supports the necessary requirements of Laravel, such as mod_rewrite. Some hosting providers might disable certain Apache modules, so you may need to reach out to them to enable those modules if necessary.
  6. Cron Jobs: If your Laravel project relies on scheduled tasks or cron jobs, you may need to set up a cron job on your cPanel account to trigger Laravel's schedule:run command. This ensures that Laravel's scheduled tasks are executed.
  7. VPS/Dedicated Server Considerations: If you have a VPS or dedicated server, you have more control over the server environment. In such cases, you might need to configure additional server settings like SSL certificates, virtual hosts, and permissions.


Always ensure to review the official Laravel documentation and consult with your hosting provider to ensure that your specific cPanel configuration is compatible with Laravel requirements.


Is it possible to deploy multiple Laravel projects on the same Cpanel account?

Yes, it is possible to deploy multiple Laravel projects on the same cPanel account. Here's how you can achieve it:

  1. Make sure you have access to the cPanel account where you want to deploy the Laravel projects.
  2. Upload all the Laravel projects to the server using FTP or the cPanel File Manager. Make sure each project is in its own separate folder.
  3. Access the cPanel account and navigate to the "Addon Domains" or "Parked Domains" section. Add a new domain/subdomain for each Laravel project you want to deploy. Make sure to point each domain/subdomain to the respective project's public folder.
  4. Once the domains/subdomains are set up, you will need to configure each Laravel project's files to reflect the correct domain/subdomain. For this, you may need to update the .env file in each project and set the appropriate APP_URL to match the domain/subdomain.
  5. Additionally, you may need to update the site's document root in the cPanel account. In the "Domains" section of cPanel, find the domain/subdomain you want to configure and update the document root to point to the respective Laravel project's folder.


By following these steps, you can deploy multiple Laravel projects on the same cPanel account and access them using their respective domains/subdomains.

Facebook Twitter LinkedIn Telegram

Related Posts:

To use React.js in Laravel, follow these steps:Install Laravel: Start by installing Laravel on your local machine. You can do this by following the official Laravel installation guide. Set up Laravel Project: Create a new Laravel project or use an existing one...
To install Laravel using Composer, follow these steps:Ensure that Composer is installed on your system. You can download and install Composer from the official Composer website. Open a command prompt or terminal window. Navigate to the desired directory where ...
To deploy a Laravel project on a server, follow these general steps:Prepare the Server: Start by ensuring that your server meets the Laravel framework&#39;s requirements. This includes having PHP, Composer, and necessary extensions installed. Additionally, con...