Today we will know How to install Laravel on cPanel. Laravel is one of the most popular PHP frameworks today for building modern web applications. In this tutorial, you will discover how to set up a Laravel project in cPanel. To install and use Laravel you must have Composer installed on your system. Before continuing let’s first clarify what Composer is and what it means in Laravel.
What is cPanel?
cPanel is a user-friendly control panel used to streamline website and server management. It is an online GUI based on Linux. You can publish websites, manage domains, organize web files, and create email accounts.
The web host manager administration interface allows users to manage their websites and also provides hosting providers with the tools they need to manage servers.
What is Composer?
The composer is the package manager of the PHP ecosystem. With Composer, you can install third-party libraries, build and distribute your own modules, and automate PHP application installation and distribution. So before using Laravel, make sure Composer is set up on your machine.
Step 1: Create a subdomain
You can open cPanel administration dashboard on port 2083 or “cpanel” subdomain: http://yourdomain.com:2083 or https://cpanel.yourdomain.com
To enter a new subdomain for your brand-new Laravel project, click Subdomain on the Domains menu. Skip this section if you want to host it under the main domain.
Since the Laravel project starts from the public folder, enter the subdomain name, such as “myapp”, and put “public_html/myapp” under the document root.
Step 2: Create a database
To enter a new database for your brand-new Laravel project, click MySQL Database Wizard under Databases.
Enter the database name eg “myapp_db”.
To access the database, create a new user account. Grant all privileges to the newly created database user, then click the Next button. Save all of this information. You need them to configure the database connection in your Laravel project .env file.
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=xxxx DB_USERNAME=xxxx DB_PASSWORD=xxxx
Step 3: Configure Composer
A Laravel project can be loaded into cPanel in two different ways. File upload, or using Terminal. In this tutorial, we will use Terminal to take advantage of Composer. Since Composer is installed as a remote script, you need to make sure that the allow_url_fopen directive is enabled in your server’s .bashrc configuration file.
Run the following command in your terminal:
echo 'alias composer="php -d allow_url_fopen=On /home/$USER_NAME/composer.phar"' >> ~/.bashrc source ~/.bashrc
Download Composer using the command below. Curl will give you an error message if you try to connect to a website that has a self-signed SSL certificate because Curl was unable to verify the certificate.
In that situation, you can skip certificate validation by using the -k or —insecure flag.
The -O option will save the file with the same name as the remote in the current working directory.
curl -k -O https://getcomposer.org/installer
Set up Composer using:
php -d allow_url_fopen=On installer
Step 4: Bring your application to the server
To organize your application, create a folder. Consider the myapp folder and place your project there.
mkdir myapp cd myapp git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY .
Step 5: Install Dependencies
Composer installs dependencies in the vendor directory inside your project:
composer install
Generate a new application key. This command changes the APP_KEY setting in your .env file.
php artisan key:generate
Next, you must configure the database connection with the credentials created in step 2:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=xxxx DB_USERNAME=xxxx DB_PASSWORD=xxxx
Next, migrate your database. With this command, all our schemas are published to the database. Database tables are also created by this operation.
php artisan migrate
Set the appropriate permissions for the storage folder:
chmod -R 775 storage
Step 6: Make your app publicly accessible
To make your application publicly accessible it should be loaded into the web server’s public_html folder.
To link your application’s installation to the web server’s public_html folder, simply create a symbolic link.
ln -s /home/user/myapp/public /home/user/public_html
A symbolic link, or symlink, is a file or folder on your computer that points to another file system attached to it. Do the same for the storage directory:
ln -s /home/user/my_laravel_app/storage/my_laravel_app/public /home/user/public_html/storage
Then activate the storage link by running the following command:
php artisan storage:link



