For trial sites, and quick to deploy, low traffic tools, its perfectly possible to host your site at Heart Internet using subdomains. Although these instructions are specific to Heart, they will work for other hosts, with and without subdomains.
1. Request subdomain setup
Heart run their subdomains on the same server. A folder is created in the public_html folder for the subdomain. For instance, I’m creating a service that will respond to dj3.mydomain.com on the mydomain.com server, there will be a folder called public_html/dj3
After requesting the subdomain, wait an hour for the DNS to all be in place.
2. Upload your site
Your laravel code base should be located in a folder that is not accessible from the web.
Create a new folder in your root folder based on the name of your subdomain. This is incase you want to install another application, you can put each backend in its own space. Here i have used the name dj3core
FTP everything except your public folder into the back-end folder that you created (dj3core in my example)
FTP the contents of your public folder into the subdomain folder (dj3 in my example)
Make sure that you copy the hidden file .htaccess also into your subdomain folder. Do not put it in the root or the public_html folder
3. Fix the paths in the index.php file
You need different paths in the index.php file to what you have probably been testing with, so before uploading or inplace on the hosted server, edit the index.php (the one in the subdomain, eg /public_html/dj3/index.php) file as follows;
/* |-------------------------------------------------------------------------- | Register The Auto Loader |-------------------------------------------------------------------------- | | Composer provides a convenient, automatically generated class loader for | our application. We just need to utilize it! We'll simply require it | into the script here so that we don't have to worry about manual | loading any of our classes later on. It feels nice to relax. | */ // require __DIR__.'/../bootstrap/autoload.php'; require __DIR__.'/../../dj3core/bootstrap/autoload.php'; /* |-------------------------------------------------------------------------- | Turn On The Lights |-------------------------------------------------------------------------- | | We need to illuminate PHP development, so let us turn on the lights. | This bootstraps the framework and gets it ready for use, then it | will load up this application so that we can run it and send | the responses back to the browser and delight our users. | */ // $app = require_once __DIR__.'/../bootstrap/app.php'; $app = require_once __DIR__.'/../../dj3core/bootstrap/app.php';
I have retained the original lines, and added the modified lines below.
Compared to the distribution, the application can be found up two directories (../) and in the dj3core folder.
Thats it! Your site should now be working in the subdomain dj3.mydomain.com
4. Problems?
If you are still having problems, check that the storage folder is writable.
At the time of writing, I have not tested email, but I don’t expect there to be a problem.
If you are using the HTML and URL helpers make sure the url is set correctly in the config/app.php file.
I have followed the instructions, all I get is a white/empty screen, just to make sure I used a clean L5 copy.
Any suggestions?
I did:
Sub-domain requested (wait 24 hours)
Folders on root:
core_l5clean – With all L5 original/clean folders and files
public_html – A new folder named “l5clean” with content of original “public”
l5clean/index.php lines changed to:
require __DIR__.’/../../core_l5clean/bootstrap/autoload.php’;
$app = require_once __DIR__.’/../../core_l5clean/bootstrap/app.php’;
config/app.php changed to 777
Did you remember to set PHP to version 5.4 or 5.5?
Is this an installation that you have already run locally, or is it literally clean? I think you might need to have run composer dump-autoload at least once in order to generate the autoloader?
Thank you for the time spent in replying to me…
Yes, I have the PHP set to version 5.5 and the L5 is clean and tested locally (homestead).
Just in case I just run composer dump-autoload and re-upload, no luck..
My first attempt was with the real L5 project I have developed, I had the same issue, white/empty screen.
Please if you have any more suggestions, I’ll be happy to hear them.
For anyone having the same problem, my solution…
–>
All working now, the problem was with Heart Internet, for some reason the PHP was not in version 5.5, I reset the PHP version back to 5.2, then, sign-out Heart Internet account, clear my browser cache and finally setting the PHP to 5.5.
Phew! Thank you so much for all your help and time.
<–
This article would be of great help to you. http://laravelmade.com/apps/setting-up-laravel-5-1-on-a-shared-hosting-server/
Unfortunately the approach in the laravelmade.com article leaves the site unsecure with the .env file vulnerable. Make sure there is no secrets in that file. A better approach is as outlined here with the core framework files outside of the externally accessible folders.
I already uploaded my Laravel project to my hosting and the frontpage almost works, but every link is broken so I can not access any of the other routes. Any suggestion?
BTW, the hosting runs PHP 5.6
Do you use the HTML helpers to create the links?
You say the links are broken – do they look ok? For instance, does your link say eg domain.com/about or domain.com/public/about ?
I try your tutorial but it’s just work on frontpage..
i have same situation with Allfarid..
my web himtiumn.com its work but when i try to go with himtiumn.com/jenis_kerusakan
its broken (you can try it) :
Not Found
The requested URL /jenis_kerusakan was not found on this server.
i already double check routes for /jenis_kerusakan and try on localhost it’s work fine
Looks to be working now? I get {“success”:1,”message”:”Jenis Kerusakan berhasil dibuat.”} as a response.
Have you done something to fix it? Care to share what was wrong?
Hi!
Thank you for your article.
I followed your tutorial but didn’t succeed to make it work.
I’m on bluehost, when I open the URL the “view” part is working fine, but no db access and I guess nothing more working.
Could you suggest any help plz.
Regards!
I think you probably need to check your config against the guidance given by bluehost. Have you been able to prepare the database (for instance by using phpmysql)?
I just want to ask, am i going to include the .svn foldder? I mean, on my localhost, i did not see this file, but after I FTP’ed using filezilla, there is a .svn folder inside my public dir. What’s the best thing to do? just leave the .svn folder as is or it’s okay to delete it? I hope someone can answer. I am new to laravel migration and have no idea about laravel to be hosted. Thank you so much for this tip by the way. I will try this step and i hope it’ll work.. Thank you and have a nice day!
Is the .svn folder for your version control (subversion)? Its probably hidden on your local drive but your FTP application is set to show hidden folders and files.
I can’t see any reason why you would want this on your hosting server.
You can delete the .svn file on production server
Hello,
I followed your steps clearly, but I only get a white page.
require __DIR__.’/../../juozcore/bootstrap/autoload.php’;
$app = require_once __DIR__.’/../../juozcore/bootstrap/app.php’;
config/app.php changed to 777
PHP to version 5.5
Do I have to do something with .htaccess?
my .htaccess
———-
Options -MultiViews
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]
Thanks in advance,
To everyone having the same problem, I found the solution myself. The PHP extensions were not active, so I recommend you to set the extensions as its defaults.
that save my life, man. Thanks 🙂
Hi,
I was wondering… does anyone been able to install composer on a Heart Internet shared hosting account?
Any suggestion is welcome…
Thank you.
Hi Again
running composer (and artisan) require SSH access. Some hosts provide this (or at least a cut down version). With Heart, you have to send them signed scanned in copies of proof of address and a signed agreement that you will not do bad things with ssh! After a few days they reply with credentials but the SSH you get is pretty crappy. I tried to use it to apply patches to a magento install and totally failed. Heart support had to apply the patches for me!
Anyway, what I do is ignore trying to use composer, and create a production install on my local machine (separate from the dev build) and then sync that to the hosting space with FTP.
I have also become aware of some tools that provide a sort of PHP command line. These work as like a wrapper GUI for the exec command. I’ve not used these because I was concerned about the security aspects.
https://devcentral.f5.com/articles/webshells
I should also point out that this article and comments relate to SHARED hosting only. VPS and dedicated servers usually support SSH.
Hi Mark,
am trying to make deploy laravel5 in shared server.
forms are displaying but no css were taking whats the problem.can you please tell me.
Open the site in Chrome or Firefox right click on part of the page and choose ‘inspect’ then then using the network analysis tool see what files are loaded and what are not. Its probably just the path to your css files which is incorrect for some reason.
Nice post….I’ve been successful by following the above instructions…….thank u very much
Hi, thank you for the post. It helpped me a lot.
I had problem to follow your post because my page was in blank.
My directory was different of yours, I had the public and core folders in the same directory.
So I changed the require lines in index.php file taking out one “/../”.
Hi Ernandes
Be careful not to have core and public in the same folder. In your browser go you your website and try to access the .env file eg domain.com/.env You will need to alter this to reflect your server structure but if you are not careful, your .env file will be visible downloadable along with all your secrets.
I have followed your steps to deploy my laravel app as a subdomain for nielsvhb.be and it doesn’t show an error when I go to nielsvhb.be/chiro but it does show a blank screen and I don’t know why. As I read some of the comments people suggest stuff like php extensions or different versions of PHP but I’m left in the dark as it comes to these, as I’m quite new to deployment and Laravel. Also how exactly do I make the connection to a database? I was always using localhost as database. Thanks!
Hi Niels
There are unfortunately quite a few reasons to get a white page. You may need to consider each of these;
Make sure you have all pre-requisites
Make sure you understand the file layouts and make public as your document root
Set the key in the .env file
check public folder has .htaccess
turn on error reporting
Check your laravel.log
With respect to your database. The hosting company should give you a means to create a database. This will then give you database IP address, user name, password and database name. Just put these into the .env file.
Good luck!
Thank you very much. It works great for me.
Great tutorial, so I’m trying to figure out this approach on my case. I’m having a shared hosting with public_html folder where all (visible) parts of my webpage should be saved. I’ve saved all laravel app folders (except public) in the root under ‘adminCore’ folder. Then, I’ve copied all laravel’s public folder content to public_html/test_page folder and setup index.php file.
When I run it, I have all views, I can read from the database, store new data. However, if I try to edit or delete data from database, I get a 403 error, i.e. PUT/DELETE requests are not allowed. Is there any way to make this work on shared hosting plan? Locally, it works great. Thanks in advance!
Sounds like a database connection problem rather than the organisation of your hosting. Are you using mysql or sqlite? If sqlite check that your application is allowed to write into the place where you have stored the file.
I would not suggest shared hosting unless you really don’t want to spend much on your hosting. The biggest problem is security. Since more than one website is hosted on the server and more than one person has access to the server, there is little assurance of your website’s security. If one website is infected with something like a worm or another virus, other websites in the server will also become vulnerable to the virus. Instead, go for cloud hosting providers, like Cloudways (http://www.cloudways.com/en/laravel-hosting.php ), that offer dedicated servers with strong security features. If you are hosting your Laravel website on AWS or GCE, then you can be sure it will be really secure.
Of course, but shared hosting is massively popular for people that have only small audiences, budgets or for just testing out their ideas. In terms of security, the risk is FAR greater that the programmer will themselves introduce some vulnerability in their web app versus a professional hosting company allowing one breached site to impact another.
Thank you…. I spend a complete day with this issues
In regards to the section “3. Fix the paths in the index.php file,” another option is to create a symbolic link to solve the issue.
You can do this as follows:
ln -s yoursite/public/ yoursite.com
I deleted storage folder shortcut and created new. Now its fine