How to Install Composer and Laravel 5 in cPanel




Installing LARAVEL on our Linux Shared plans via Softaculous:

NOTE: This will only install the framework under your user, however if you are on a Shared Hosting plan (restricted or no SSH access) you won't be able to use most of it's functionalities. How to properly deploy your LARAVEL Project on a Shared Plan will be covered below in the next section.


1. Login to your Cpanel.




2. Under SOFTWARE section, choose Softaculous Apps Intaller.





3. Type Laravel in the search-bar and on the next window click Install Now.


4.
 On the next page fill in the requested information and choose Quick Install.


* Choose Protocol: choose SSL or non-SSL protocol (http/https)

Choose Domain: the domain to install the software

In Directory: name of the directory to which you wish the application be installed




5. Click Install.




6. If the Laravel application is installed properly, you will see the message below:


DEPLOYING YOUR LARAVEL 5 APPLICATIONS ON A SHARED HOSTING:


After you have finished building your LARAVEL 5x application on your local machine and assuming your project is called laravel50, please proceed to compress (.zip) your whole project on your local PC.

Once this is done, please follow the steps below:

1. Open your cPanel.

2. Click on File Manager.



3. Click on Upload.


4. Upload the laravel50.zip to the root directory – not the public_html.

5. Extract the laravel50.zip. Your cPanel file manager should be looking something close to this:



6. Open the laravel50 folder and MOVE the CONTENTS of the public folder to your cpanel’s public_html folder (or to the folder where you want your LARAVEL project to reside).

7. Navigate to the public_html folder and locate the index.php file. Right click on it and select Code Editor from the menu.


8. This will open up another tab showing the cpanel Code Editor, change the following lines (22 and 36) from...

`require __DIR__.'/../bootstrap/autoload.php';
 ...
 $app = require_once __DIR__.'/../bootstrap/app.php';`

to

`require __DIR__.'/../laravel50/bootstrap/autoload.php';
 ...
 $app = require_once __DIR__.'/../laravel50/bootstrap/app.php';`


NOTE: According to your projects folder name.

9. The .htaccess file should look something like this (do not change it unless you are familiar with what you want to do):

  `<IfModule mod_rewrite.c>
                  <IfModule mod_negotiation.c>
                  Options -MultiViews
                  </IfModule>
                  RewriteEngine On
                # Redirect Trailing Slashes…
                  RewriteRule ^(.*)/$ /$1 [L,R=301]
                # Handle Front Controller…
                  RewriteCond %{REQUEST_FILENAME} !-d
                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteRule ^ index.php [L]
                  </IfModule>`


10. If everything went well, your website should now throw a database error, this is because you haven't migrated your database yet.


RESTORING YOUR DATABASE:


To do that, you will first need to create a MySQL database  and user from the CPanel. This can be done by following this TUTORIAL and this TUTORIAL.

After this you will need to restore your MySQL backup done on your local machine to the newly created MySQL database you have made. This can be done by following this TUTORIAL.

Comments