This is my first post in this blog, and I hope you find it useful. Everything you find here has been tested in Hostgator.
As you know Laravel as a great php framework, involves some work when you try to install it on shared hosting. people using Hostgator are very aware of this. Because you first BIG problem is that your php version doesn’t meet the Laravel system requirements which is 5.3.17 or greater. This is one of the problem solved within this tutorial. So lets dive in.
- Upload your files
- php 5.3 is not used by default
- Installing composer
- Install the framework dependencies using composer
- Where to put things
- Update your index.php / paths.php files include the correct paths
Uploading your base files
Laravel has been designed so that you can keep your app files out of the public_html folder which adds extra security for your app. So what I suggest is that you create a folder in your root home directory, name it something like ‘app_base’, and put everything in there, assuming you have downloaded Laravel as a zip file from github. We will work on that folder for the next steps.
Your next option is to use git command via ssh. Hostgator has git installed for you.
login via ssh using the command bellow:
ssh -p 2222 [email protected]
Once logged in, and you are in your root home folder, type git just to make sure you have it installed.
Next, clone the Laravel repository in the app_base folder using this code:
git clone https://github.com/laravel/laravel.git app_base
git will start downloading the framework for you.
Once finished, we are ready to install composer’s phar file. getComposer.org has a command line that you can use to download composer.phar into your app_base folder.
curl -sS https://getcomposer.org/installer | php
Obviously this won’t work, composer will tell you that it needs php 5.3.x to work.
PHP 5.3 is not used by default
Hostgator has php 5.3.7 installed on every shared hosting account. but to use it you need to do 2 small changes. The first is to add some code to your .htaccess file, and the second change is to use another command in your terminal to reference php 5.3.
Create an .htaccess file in your app_base folder
Yes you are right, there is no .htaccess in your app_base folder, but we will need to create one and add some code to it.
once created (And don’t forget the dot in front of htaccess), put this code in:
# Use PHP 5.3 AddType application/x-httpd-php53 .php
Using php 5.3
Now your app will be using php 5.3 instead of 5.2. but this is not everything, now when trying to use php in your terminal (or putty or whatever you are using) via SSH, you need to use/opt/php53/bin/php and it will work. Now let’s get back to install composer.
here is a little trick if you want to use php instead of/opt/php53/bin/php, add an alias:
Using ssh, cd into your app_base folder, and install composer using this code:
curl -sS https://getcomposer.org/installer | php
curl -sS https://getcomposer.org/installer | /opt/php53/bin/php
Composer will be installed without a problem if you followed all the steps from the beginning.
do a little ls just to verify that the composer.phar file is there.
Install the framework dependencies using composer
This is the fun part, all you have to do is shoot a composer install on your terminal, and every single package used by laravel will be downloaded and installed for you.
/opt/php53/bin/php composer.phar install
php composer.phar install
If you notice that the last artisan command fails, don’t worry, you can run it yourself after composer is done installing.
The command is simply php artisan optimize
Now you have everything installed. Nothing will be accessible yet from the web. because we still need to move the public folder’s content to the public_html folder, so that you can point to that folder from the web.
Where to put things
Create a folder inside your public_html folder, name it say DEMO. And move the content of your laravel’s public folder into the demo folder.
If you point to the demo folder from the web, it won’t work. this is because you still need to update your paths.php file to include the correct paths to different parts of the application.
Update your public/index.php && paths.php files to include the correct paths
In order for the application to know where your App is, open the index.php file inside DEMO folder you created and change all the paths you find there. You need to provide valid paths to your bootstrap files.
And so on.
Now open your bootstrap folder inside your laravel app, and change the public path inside paths.php
'public' => __DIR__.'/../public'
'public' => __DIR__.'/../../public_html/demo'
If you got here, everything should work now, point your browser to your demo folder and see if your laravel app boots up with a default view saying YOU HAVE ARRIVED!
I hope this was helpful for you. let me know if you get stuck.