April 9, 2025 0

In this article, we are going to explore how to deploy laravel project in cpanel using git. Please note that we are not using ci/cd github actions for this deployment. We are using terminal and basic git commands to deploy the projects.

Let’s deep dive into the process of depolyment. Let us first create a subdomain in our hosting service provider’s cpanel.

Read more articles.

Create a subdomain

First, we will add a domain/subdomain on our cpanel. For now , I am creating a subdomain. So, navigate to the Domains section and click on Create a New Domain. Add your desired sub-domain that is linked to your system.

After you add a domain, click on submit, it will create a new directory with that name as well as the domain.

Create Database and Database User

So, the next important things to deploy laravel project in cpanel is to create a database and the user will full privilege. So, for that, navigate to Manage My Database section and create a new database, user and assign that user to that database. Please make sure you assign that user to that database.

Github Repository

Now after we successfully created our subdomain/domain and then the database with user access. We will move forward to clone our project in our cpanel. So, for that make sure your codebase is already on github. If not, then you must push your code to github and make it ready to deploy.

Clone Repository

After your repository is ready, you can open terminal in your cpanel and navigate to your domain/subdomain directory in terminal using cd file, then hit the following command:

git clone yourrepository@git .

The ‘.’ in the above command indicates that the cloned code will be in your own directory.

Here after you clone it, if its private repository, you need to enter your github username and password. But remember password means you need to generate the access token from Settings/Developer Settings/Personal Access Tokens/Tokens(Classic) and copy the token and keep it in a safe place.

Required PHP Artisan Commands

After our code is deployed, we must have to enter some basic php commands right? So, the first one is:

composer update

Also, we need to copy our .env.example file to .env and then update the DB_DATABASE,DB_USERNAME and DB_PASSWORD that we created in step 1.

After that , we can enter more php commands like:

php artisan migrate
php artisan key:generate

Update .htaccess file

The last thing we need to do is to update or create .htaccess file which is the configraiton file. So, you can paste the following code in your .htaccess file which is in the root directory:

# <IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteRule ^(.*)$ public/$1 [L]
# </IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)

# END cPanel-generated php ini directives, do not edit

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
# <IfModule mime_module>
#   AddHandler application/x-httpd-ea-php74 .php .php8 .phtml
# </IfModule>
# php -- END cPanel-generated handler, do not edit

And that’s it now your code is on production level. Now you can turn off debug mode and other things on your requirements.

Conclusion

Hence, in this way we can easily deploy laravel projects in cpanel using github. If you face any challenges, please let me know.

Category: 

Leave a Comment