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
- Apache
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 .
Of course, you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.
Không có nhận xét nào:
Đăng nhận xét