Laravel 4 subdomain routing on VPS/WHM - laravel-4

I have been trying to get Laravel 4 subdomain routing to work for a couple of hours now and I just cannot seem to figure it out. I have a VPS and I'm fairly new to a lot of VPS concepts.
The domain in question is an account on the VPS - the main domain of the VPS is different. So, main domain is example.com and the account I am trying to get subdomain routing working on is foobar.com - a cPanel account on example.com
I put the following above the document root route on foobar.com's Routes file -
Route::group(array('domain' => '{account}.foobar.com'), function()
{
Route::get('/', function($account, $id)
{
echo $account;
});
});
I was expecting this to output the subdomain entered - for example something.foobar.com would echo something. Instead I get Error code: ERR_NAME_RESOLUTION_FAILED.
Since this is a cPanel account, I tried adding a subdomain in cPanel. This of course creates a directory of the same name as the subdomain in public_html, which is the doc root for that subdomain. When I navigate to the subdomain after adding it in cPanel, it says cannot list the directory.. blah blah.. basically it's an empty directory and the server will not show anything. If I attempt to delete the directory in public_html, I get a generic 500 error.
Clearly I'm missing something, the Laravel documentation either falls short or this type of server configuration requires something else. Help please! Thanks!

Woohoo! I got it working after a little more reading.
I had to log in as root to my VPS WHM control panel and add a wildcard A DNS entry (*) for the domain. Then I modified /etc/httpd.conf and modified the line ServerAlias to *.foobar.com foobar.com. Restarted httpd and viola!
This is awesome!

Related

Why do i get the "index of" page? (Laravel Nova Web App)

I have uploaded a Laravel Nova project into bluehost and made the changes on the DB name, user, and password, and I assigned the domain to the directory but I'm still getting the (Index of/) page when I open the domain.
That happens because your vhost is pointing to an incorrect directory.
Your apache/any web server should be pointing to /dir/your-project-name/public, however now its currently pointing to /dir/your-project-name (public is missed)
If you have ssh option, edit your vhost to point to /your-project-name/public directory.
If you don't have ssh option (most probably if you're in shared hosting you won't have access to), try renaming the public to public_html and see if that works.
If that still doesn't work, you would need to change the app configuration. Please see this answer

Laravel project custom domain

I am using custom configuration of domain names for my laravel project test as test.local . When I ran this project as test.local in google chrome , it shows laravel homepage. But, when I go to any other routes it shows internal server error.
Can anyone have any solution?
Just add index.php after the url, and then go to specific route
test.local/index.php/login
So in your routes file eg. web.php, do this if you need to, this adds on a domain limitation.
Route::group(['domain' => env('APP_URL', 'test.local')],function () {
//routes...
});
In you .env file, define the app url, you may use https if required
APP_URL=http://local.test
After all, I would strongly suggest you to check you nginx file to see if you are pointing the path to the right one. And also check if index.php is added into the index file property.

1 Laravel Installation with 2 TLDs

I'm allowing my customers to upload large files. Because I'm using Cloudflare, anything over 100 MB gets rejected, which is no good.
So what I'm thinking of doing is switching the upload form action from mysite.com/upload to mysite.net/upload. This way I'm using a domain name that isn't going through Cloudflare, so file sizes won't be restricted.
I've set up mysite.net as a site in Forge to mirror mysite.com by setting the root location in nginx to point to the current folder of mysite.com. So now when someone goes to mysite.net they see the contents of mysite.com.
Unfortunately, mysite.net is now open to DDOS attacks because it isn't running through Cloudflare.
So what I'd like to do is make it so that mysite.net/upload is the only route that's open under that domain, and that it's only accessible from my load balanced servers.
Is this possible, and if so: how do I do it?
I've been researching this and haven't really come across an answer that applies to me, the most common scenario is using subdomains, which is not applicable in my situation.
Figured it out; I decided to use a subdomain as it was easier.
I went into Cloudflare, added the subdomain upload.example.com (of course, use your real domain) so traffic could hit it, and then turned off protection for the subdomain so that large files could be uploaded.
I updated my .env file and added the SESSION_DOMAIN variable, so that the user's session will work across both example.com and upload.example.com domains.
SESSION_DOMAIN=".example.com"
Notice that the domain starts with a period, and the value is enclosed in quotes. If you omit the quotes your users will not be able to login to your app, and if you use Envoyer omitting quotes will break the decryption when editing your .env file.
I then added a new group to my routes file to handle traffic to the subdomain. I added a route to redirect all GET traffic back to the original site (https://example.com), and added a POST route to handle the uploads.
Route::group(['domain' => 'upload.example.com'], function () {
Route::get('/', function () {
return redirect(url('https://example.com'));
});
Route::post('upload', 'UploadController#store')->middleware('throttle:4,1');
});
And then in my form...
<form action="https://upload.example.com/upload" enctype="multipart/form-data">
Finally, I cleared my browser's cache and cookies, then logged into the site and uploaded a large file! :)

Laravel directory to welcome page on a VPS

Before I was in a shared hosting and had no problem installing and accessing (click next next), Laravel welcome page but I have moved to a bare metal VPS and I am having difficulties to get to the Laravel 5 welcome page. My host tells me to upload the framework to the htdocs directory, but that is exactly what I did and where the app et al are found.
This is the URL scenario.
My web VPS by default shows me its own index.html like this
/var/www/virtual/myweb.com/htdocs/index.html
and yes, I can correctly access that index through myweb.com
but, of course, all my views are in their Views folder, like this:
/var/www/virtual/myweb.com/htdocs/resources/views/welcome.blade.php
my routes page (as it is a freshly installed) naturally
Route::get('/', function() {
return view('welcome');
});
and the URL in my config/app.php file
'url' = >env('APP_URL', http://myweb.com');
If I do something like this in the URL browser box of course, I get to the file of Laravel 5 welcome page
http://www.myweb.com/resources/views/welcome.blade.php
but obviously I don't want to show such path
so, I would like to be able to write myweb.com and directly show my welcome.blade.php
Any ideas as to how?
You should point you web server (Apache) to a public directory of Laravel's project. For example:
DocumentRoot "/var/www/virtual/myweb.com/public/"
<Directory "/var/www/virtual/myweb.com/public/">
After rebooting web server normal URLs should work (if you'll set up correct settings).

Routing problems with Laravel 5 on BlueHost Shared Server

I am in the Beta stage of a Laravel 5.0 project using BlueHost as the server. I have not finalised the domain so I am using a temporary address as follows:
IP Address/username
In a normal Laravel project the root URL is the domain name of the website and routing starts from there. However, in this environment, I have to adjust the route.php file. For instance, instead of the familiar
Route::get('/', 'WelcomeController#index');
I've had to do this:
Route::get('/username/', 'WelcomeController#index');
With the usual adjustment in the .htaccess to re-route everything to the public Laravel folder, I can use the temporary address and access the welcome page. However, when I start adding security with the Auth controller, the re-directs don't work. When accessing a secure URL, you are re-directed to IP Address/auth/login instead of IP Address/username/auth/login. In the .htaccess file in the public folder I've added:
RewriteBase /username/
with both slashes, but that doesn't help. Does anyone know how to set up a Laravel project with a secure area, secured by the Auth controller which has a URL that includes a second segment?

Resources