In this article, we will show you how to install Laravel on CentOS 7 VPS with cPanel control panel. 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.
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
Login to your VPS via SSH
Update the system and install necessary packages
yum update yum install git curl
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
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.
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
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 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 .