install Laravel in cPanel

Laravel is a free, open-source PHP web framework intended for the development of web applications. Some of the features of Laravel are a modular packaging system with a dedicated dependency manager, different ways for accessing relational databases.  Laravel is regarded as one of the most popular PHP frameworks, together with Symfony2, Nette, CodeIgniter, Yii2 and other frameworks. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, queueing, and caching. Laravel is accessible, providing powerful tools needed for large, robust applications. It supports multi-platform and allows users to develop MVC web applications.

Server Requirements

The Laravel framework has a few system requirements. You will need to make sure your server meets the following requirements:

  • PHP >= 5.6.4
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

Login to your VPS via SSH

ssh root@my_server

Update the system and install necessary packages

yum update
yum install git curl

Install composer

Composer is a dependency manager for PHP with which you can install packages. Composer will pull in all the required libraries and dependencies you need for your project.

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

Install Laravel

Installing Laravel is a pretty straightforward process, in this post we will install Laravel using the composer create-project command.

Switch to the domain root directory:

cd /home/USERNAME/public_html/

and install Laravel using the composer create-project command (Be sure to include the dot (.) at the end of the command.):

composer create-project --prefer-dist laravel/laravel .

If you are logged in as a root or another sudo user you will need to set the correct ownership and permissions:

chown -R USERNAME:USERNAME /home/USERNAME/public_html/

Do not forget to change ‘USERNAME’ with the actual username.

Configure cPanel

We need to edit the default web server document root and change it from public_html to public as required by Laravel.

Change Document Root for an Addon domain

Login to your cPanel at: https://YOUR_SERER_IP:2083 and in the ‘Domains’ section click on the ‘Addon Domains’. In the new window you will see a list of all your addon domains, click on the edit icon next to the domain’s document root path and enter the new path, for example /public_html/laravel-addon-domain.com/public.

Change Document Root for a Primary domain

To change the main/primary domain Document Root you need to have SSH root access to your server. Open the following file:

nano /var/cpanel/userdata/USERNAME/MY_LARAVEL_DOMAIN.COM

and change the documentroot value, just add public at the end of the path, for example:

documentroot: /home/USERNAME/public_html/public

If you have an SSL certificate for your domain you also need to edit the documentroot value in the following file:

/var/cpanel/userdata/USERNAME/MY_LARAVEL_DOMAIN.COM_SSL

Do not forget to change ‘USERNAME’ with the actual username and MY_LARAVEL_DOMAIN.COM with the actual domain.

Finally save the file and rebuild the Apache configuration:

/scripts/rebuildhttpdconf && service httpd restart

That’s it. You have successfully installed and configured Laravel on your cPanel VPS. For more information about Laravel, please refer to the official Laravel documentation and for more information about cPanel please refer to their official cPanel documentation .

Leave a Reply