There are a lot of wonderful guides out there on installing Laravel on a shared hosting service. However, every hosts have their own idiosyncrasies, and you are pretty much at the whim of the provider's server configuration. This one is Hostgator specific.
If you haven't already, enable SSH. Also, go to your control panel and go to Databases -> Remote MySQL-> and under Add Access Host, simply put a '%' in the empty field. Although this is not really related to installation, this is something you'll need to do in order to remotely access the Mysql database.
Connect to Hostgator's terminal using Putty or some other SSH tool. Once logged in, type 'pwd'. You should see something like this:
-jailshell$ pwd
/home2/CpanelUsername
This is where we want to install Laravel. But in order to do so, we must install Composer. However, Composer requires PHP 5.3.2+ to run. To check the PHP version, type 'php -v' (remember, the terminal PHP can be different from the PHP configuration for your website). Hopefully you'll see someting like this:
-jailshell$ php -v
PHP 5.5.6 (cli) (built: Dec 4 2013 13:50:26)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
PHP 5.5.6! You probably won't. In fact, you'll probably get PHP 5.2, just shy of the requirements to install composer and Laravel. In order to remedy this, create a new file called '.bashrc'. Kind of like .htaccess, the dot makes the file hidden. In the .bashrc file, put in the code:
alias php='/opt/php55/bin/php'
alias composer='/home2/CpanelUsername/composer.phar'
export PATH="/opt/php55/bin:$PATH"
Also, create a file called '.bash_profile'. In it, put:
[[ -s ~/.bashrc ]] && source ~/.bashrc
We've created several aliases. The php alias allows us to simply type 'php' instead of the lengthy '/opt/php55/bin/php' in order to access PHP 5.5. The composer alias allows us to type 'composer' instead of 'composer.phar' before every command. Also, since, we've created a direct path to it, composer.phar can be accessed anywhere, even if the file is not in the Laravel directory. The export PATH line allows Laravel to correctly path to the right PHP during its installation. Aliases do not apply during the installation process. Lastly, the bash_profile file makes it so that the .bashrc file fires up every time you start the linux console.
Upload both of them in your CpanelUsername directory, so it looks something like this:
CpanelUsername/
access-logs/
etc/
perl5/
public_html/
tmp/
www/
.bash_history
.bashrc <-- here
.bash_profile <--here
Your directory may have more files and folders, and I've purposefully ommited the hidden ones. Now, you must activate the bash files. In your console, type: 'source ~/.bashrc' and then check your php version by typing 'php -v'.
-jailshell$ source ~/.bashrc
-jailshell$ php -v
PHP 5.5.6 (cli) (built: Dec 4 2013 13:50:26)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
Awesome! We're good to go. Oh, while we're on the topic of PHP 5.5, we want to make an '.htaccess' file in our public_html folder. Create a file called '.htaccess' and write:
AddHandler application/x-httpd-php55 .php
This will enable PHP 5.5.6 on the website. Eventually, after we integrate Laravel's .htaccess, it should look something like this:
<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>
AddHandler application/x-httpd-php55 .php
Time to install Composer. In your terminal, type:
-jailshell$ curl -sS https://getcomposer.org/installer | php
The above process will download the necessary composer files in the current location. After that, install Laravel by running the following command:
-jailshell$ composer create-project laravel/laravel --prefer-dist
Now your directory should look something like this:
CpanelUsername/
.composer/
access-logs/
etc/
laravel/
perl5/
public_html/
tmp/
www/
.bash_history
.bashrc
.bash_profile
composer.phar
If you open the laravel folder, you'll see a folder structure like this:
CpanelUsername/
.composer/
access-logs/
etc/
laravel/
app/
bootstrap/
public/
...
perl5/
public_html/
tmp/
www/
.bash_history
.bashrc
.bash_profile
composer.phar
You want to take the contents from the public folder and move them to the public_html folder. You can delete the public folder. It should look like this:
CpanelUsername/
.composer/
access-logs/
etc/
laravel/
perl5/
public_html/
packages/
.htaccess
favicon.ico
index.php
robots.txt
tmp/
www/
.bash_history
.bashrc
.bash_profile
composer.phar
At this point, this starts to look a lot like Dries Vint's excellent guide. We are doing the first option. Anyway, open the 'laravel/bootstrap/paths.php' file and correct the bootstrap path like this:
28
29 'public' => __DIR__.'/../../public_html',
30
Do the same in 'public_html/index.php' and change the following lines:
20
21 require __DIR__.'/../laravel/bootstrap/autoload.php';
22
//
34
35 $app = require_once __DIR__.'/../laravel/bootstrap/start.php';
36
And that is it! Fire up your website and enjoy the lovely 'hello' screen :).
Nice tuts man
using Cpanel , I install it via softaculous :D
This is GREAT, I'm waiting in chat to enable ssh now. I was just chatting with them yesterday and asking them why I couldn't use laravel on my shared server, in their support they said you have to have VPS/Dedicated.
With hostgator you don't really need to 'enable' SSH, just download putty and connect to your server with port 2222. Once you are in the server, it's UNIX terminal and everything would seem familiar again.
I followed the steps except for the public folder and the .htaccess changes, as i managed multi-domain with the same account. It works, thanks :)
You are fantastic, and hostgator just told me I can't use Laravel without getting a dedicated server. You made it easy enough to follow that I got it working on the first try!!!!
Nice tutorial. Ran into a little hitch where alias and export path wasn't found but all still went through OK.
FWIW: If anyone encounters an issue with class 'Phar' not being found when trying to create the laravel project using the installed composer, I fixed mine by using this command instead:
php -d extension=phar.so composer.phar create-project laravel/laravel --prefer-dist
Thanks for the tutorial.
One quick note. Hostgator has been migrating their "default" server configurations to PHP 5.4, so I was able to bypass a lot of this by doing the following (no need to install composer or anything like that).
A quick hard refresh and I was rolling with Laravel!
Hope this helps!
Lhamide00 said:
Nice tutorial. Ran into a little hitch where alias and export path wasn't found but all still went through OK.
FWIW: If anyone encounters an issue with class 'Phar' not being found when trying to create the laravel project using the installed composer, I fixed mine by using this command instead:
php -d extension=phar.so composer.phar create-project laravel/laravel --prefer-dist
Thanks.. I believe the tutorial should include your suggestion
First of all Hello to the whole community.
Good for days had the problem of running my application I did in Laravel on a server anywhere in my local server so normal, and tried several free servers and payment and left the problem of the PHP version check detail documentation where it says that this framework runs only on servers that have PHP version 5.3 onwards and I share good link server where I now run my application. (There is explicit that Laravel Framework server and others) www.hostinglaravel.com I hope someone else will serve this information.
It says /opt/php55/bin/php: No such file or directory
here i read for new comer installing laravel
http://driesvints.com/blog/laravel-4-on-a-shared-host
i use laravel 5 for testing deploy in Freehosting demo site
i use .htaccess for freehosting to manage test
Thanks for the great tutorial. I use site5 and have been fighting with this for days.
tried to install with softaculous and then a manual install. looks like all I was missing was the aliases. I was about to give up.
thank you !!!!!!!!!!!!!!!!!!
I would never go for Hostgator. I never recommend shared hosting to my clients. I am using Laravel Hosting by Cloudways. They have given me the power to configure Laravel 5 in one click on a managed DigitalOcean server. I have options to enable Varnish and Redis cache. I have over 50 client sites running on Cloudways and I am extremely happy with their support.
pkanane said:
Lhamide00 said:
FWIW: If anyone encounters an issue with class 'Phar' not being found when trying to create the laravel project using the installed composer, I fixed mine by using this command instead:
php -d extension=phar.so composer.phar create-project laravel/laravel --prefer-dist
This worked for me. Thank you!
Everything seemed to install correctly but I don't see the "hello" screen. Could this be because I have an index.html file for my home page? Laravel is installed in the root and not the public_html. What's the issue?
I'm having a problem. I get through everything all well and good but when i get to the part where i have to change the PATHS.php file in the bootstraps DIR I cant because it seems that it was taken out of laravel.
this is the error Im getting when i try and run index.php on the server.
Warning: require_once(/home2/edwingm/public_html/../laravel/bootstrap/start.php): failed to open stream: No such file or directory in /home2/edwingm/public_html/index.php on line 36
Fatal error: require_once(): Failed opening required '/home2/edwingm/public_html/../laravel/bootstrap/start.php' (include_path='.:/opt/php55/lib/php') in /home2/edwingm/public_html/index.php on line 36
Plz Help I'm at my wits end.
HOSTING LARAVEL 5.4 PHP 7 Shared Hosting It offers web hosting for your projects in Laravel Framework all versions (4.x up to 5.4), we have support for PHP versions 5.3, 5.4, 5.5, 5.6, 7.0 and 7.1, up to 20 times faster thanks to the storage technology SSD. Http://hostinglaravel.com/
Here is the simple and descriptive article: https://medium.com/laravel-news/the-simple-guide-to-deploy-laravel-5-application-on-shared-hosting-1a8d0aee923e
Here is a simple guide to Deploy Laravel Application on Host-gator. And the steps works.
https://www.5balloons.info/hosting-laravel-5-5-project-on-shared-hosting-hostgator/
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community