Support the ongoing development of Laravel.io →
posted 11 years ago
Installation

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 :).

Last updated 2 years ago.
0

Nice tuts man

using Cpanel , I install it via softaculous :D

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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 :)

Last updated 2 years ago.
0

great tutorial man much appreciated!

Last updated 2 years ago.
0

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!!!!

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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).

  1. Create my subdomain (or domain) and configure the document root to be the "public" folder.
  2. Upload my already completed laravel app.
  3. Go to the control panel and select the "PHP Configuration" option in the "Advanced" section.
  4. Navigate to the "public" folder and change the PHP version to be 5.5 (just to be safe). It appears they add a suPHP configuration option (or could be since I'm on shared hosting)
  5. Save changes, and wait a moment for the changes to propagate to the server.

A quick hard refresh and I was rolling with Laravel!

Hope this helps!

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

what should i do for Nginx?

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

It says /opt/php55/bin/php: No such file or directory

Last updated 2 years ago.
0

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

http://lifethumb.url.ph/

i use .htaccess for freehosting to manage test

Last updated 2 years ago.
0

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 !!!!!!!!!!!!!!!!!!

0

Thank you very much! Really helpful.

0

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.

0

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!

0

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?

0

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.

0

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/

0

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/

0

Sign in to participate in this thread!

Eventy

Your banner here too?

expositor expositor Joined 11 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.