We will show you, how to install Laravel on cPanel. Laravel is the most starred PHP framework on Github and also the most preferred framework of PHP developers. This guide should work on other Linux VPS systems as well but was tested and written for a cPanel VPS. Let’s get started with the installation of Laravel on your cPanel server.
Table of Contents
This guide assumes that you already have:
- PHP 5.6.4 or later (PHP 7 is highly recommended)
- OpenSSL, Mbstring, PDO, Tokenizer, PHP and XML Extensions
2. Login to your VPS via SSH
3. Update the system and install necessary packages
yum update yum install git curl
4. Install the composer
The composer is a dependency manager for PHP with which you can install packages. The 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
4. 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:
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.
5. Configure cPanel
We need to edit the default web server document root and change it from
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
6. 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:
and change the
documentroot value, just add
public at the end of the path, for example:
If you have an SSL certificate for your domain you also need to edit the
documentroot value in the following file:
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. For more information about Laravel, please refer to the official Laravel documentation and for more information about cPanel please refer to the official cPanel documentation .
Of course, you don’t have to to install Laravel on a cPanel Server, by yourself if you use our Laravel Hosting, in which case you can simply ask our expert Linux admins to to install Laravel on a cPanel Server for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post on installing Laravel on a cPanel Server please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.