How to remove 'public' from Laravel URL hosted on child folder? - php

I have a Laravel 5.3 project on shared hosting located at the following address.
How to remove the public from URL?
Now the same question was asked at Remove public from URL Laravel 5.3 on shared hosting but many answers were asking to move all public content to root domain, but my root domain is already hosting something with index.php in it.
Can you please tell me how to do it? All other information is same as the question shared, i.e default .htaccess file in public as well as home (laravel installation) folder. Second I am in shared hosting, I cant change Vhost or something.
Here is my folder structure inside https://yourdomain.tld/home folder

I think there are 3 possible solutions:
Since you use vhost instead of localhost, the problem might be the DocumentRoot declaration. I use Xampp, so the path and code will be based on that. In my case, the file that creates vhost is located:
C:\Xampp\apache\conf\extra\httpd-vhosts.conf
The vhost code is this:
<VirtualHost *:80>
DocumentRoot "C:/Xampp/htdocs/mydomain/home/public"
ServerName mydomain.tld/home
ErrorLog "logs/mydomain-e1rror.log"
CustomLog "logs/mydomain-access.log" common
</VirtualHost>
BTW, make sure you 127.0.0.1 mydomain.tld in "etc" file if you use a Windows machine.
When you enter www.mydomain.tld it should hit the index.php file that is located in public folder.
Since you use very old version of Laravel, I suppose you download it from liveserver. When we deploy our app, we make some changes in public/index.php file to tell our app where Laravel is. Look for
require __DIR__.'/../vendor/autoload.php'; //
I think this is different in your index.php file. BTW, I don't know if this path is different in version 5.3.
Your folder structure is incorrect. You might try to compare it with freshly installed Laravel.

Related

Why I can't correctly deploy this Laravel web site on my remote Linux server? Is it a virtual host configuration issue?

I am very new in PHP and moreover in Laravel (I came from Java) and I am going totaly crazy trying to correctly deploy a Laravel 5.4 projects that works fine in my XAMPP local environment on my Linux server. The problem should be related to virtual host configuration but I can't find a solution also asking question and reading documentation.
In my local environment (I am using XAMPP on Windows) I have setted this virtual host into the C:\xampp\apache\conf\extra\httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
ServerName laravel.dev
</VirtualHost>
So opening the laravel.dev URL I obtain the standard Laravel homepage (I have yet not replaced it with a landing page).
Then if I open this URL: http://laravel.dev/registration
I obtain the user registration page developed by me, this because I have this route into my web.php file into my project:
Route::resource('/registration', 'RegistrationController');
Then into my RegistrationController.php there is this method showing the resources/views/registration/index.blade.php view
public function index(){
return view('/registration/index');
}
In local environment, with the laravel.dev vhost pointing to the document root of my Laravel website, it works fine.
Now I have uploaded this Laravel website into my remote Linux server, into this folder: /var/www/html/HotelRegistration
But now my problem is that in this remote environment I had not virtual host (correct me if I am doing wrong assertion: from what I have understand the virtual host is used on the local environment to simulate a domain that Laravel need to point to the public folder, is it this reasoning correct?)
Anyway, this is the URL of the public folder of my deployed web site on my remote server:
http://89.36.211.48/HotelRegistration/public/
As you can see opening it the Laravel landing page is correctly shown, the problem is that I can access to the previous registration page, the only way that I have found is to open this URL:
http://89.36.211.48/HotelRegistration/public/index.php/registration
but it is pretty horrible and above all when the registration form is submitted it is generated a POST request toward this URL http://89.36.211.48/registration that end into a 404 Not Found error.
In the past I explained the situation here: What is wrong in the deploy of this Laravel application? Need I an effective domain instead the vhost used on my local environment?
but now I have do some changes to my Apache configuration followint the suggestion given in the previous post (adapting the answer to my folder structure).
So into this Apache folder /etc/apache2/sites-available I created and enabled the laravel.dev.conf related to my new vhost, having this configuration:
<VirtualHost *:80>
ServerAdmin mymain#gmail.com
ServerName 89.36.211.48
ServerAlias www.laravel.dev
DocumentRoot /var/www/html/HotelRegistration/public/
ErrorLog /var/www/html/HotelRegistration/storage/logs/error.log
CustomLog /var/www/html/HotelRegistration/storage/logs/access.log combined
<Directory /var/www/html/HotelRegistration/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
The path are related to where this website is installed on my remote server I am absolutly not sure if these configuration are ok, expecially about the ServerName value (I put here the IP of my server, is it correct?)
Then I enabled this virtual host using this statment:
sudo a2ensite laravel.dev.conf
and I restart apache.
Ok, the problem now is: what have I to do to correctly access to this website?
I still have the same problem, that is:
I still access to the Laravel landing page by this URL: http://89.36.211.48/HotelRegistration/public/
I still access to the registration form page by the horrible URL: http://89.36.211.48/HotelRegistration/public/index.php/registration
Submitting the form I still go to http://89.36.211.48/registration and obtain the same 404 Not Found error page.
So my doubts are:
Is it the virtual host correctly configured?
If it is correct what have I to do to correctly access to this web site? Need I a domain (if yes: what have to point this domain?) or can I use a path into my server in some way (something like: http://89.36.211.48/HotelRegistration/)
I am expanding my comment here.
Set folder structure like on image:
In index.php change paths like this:
line 22
require __DIR__.'/system/bootstrap/autoload.php';
line 36
$app = require_once __DIR__.'/system/bootstrap/app.php';
Thats all what I do when transferring Laravel app to server (and changing .env for database). Sometimes I have to change permissions for storage folders but thats it.

Laravel in Xampp

Recently I have installed laravel 5.2 but my home page is not showing at 'localhost' address. It is showing at 'localhost/public' address. I have installed the all files in htdocs folder.Why this 'Public' thing showing up?
Assuming you installed xampp in the default location, a httpd.conf file should be available here:
C:\xampp\apache\conf\httpd.conf
Look for 2 adjacent lines:
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
And change them to point to laravel's public folder:
DocumentRoot "C:/xampp/htdocs/public"
<Directory "C:/xampp/htdocs/public">
I find this tutorial helpful.
https://www.youtube.com/watch?v=ybJYyU5FPv4
Just set up a vhost for your page with the right Document Root like mentioned above. But you dont need to handle Laravel Projects like a default web project. Use php artisan serve via console inside your project folder and the page will run at localhost:8000 default.

Laravel 5.1 - Remove "public/" of the URL whith Method bind?

I need some help Please, for I'm beginner with Laravel and MVC.
I want to remove the "public/" of the URL.
The only two "solutions" that I found in Google, are:
Either with .htaccess. But with me (and obviously not with me) it's not working.
Either by putting what is in the "public" folder at the root of the project Laravel. This is not good for security reasons.
There is a real solution to remove the "public/" URL? So that for example this URL:
localhost/Laravel/public/test
Accessible only with this URL:
localhost/Laravel/test
Because if it or has no solution, it is of no use that I continuous to take courses on this Frameworks.
_I had read, that there may be a solution with this in AppServiceProvider:
http://www.creerwebsite.com/medias/upload/larav2.png
Or with this in the Router or a container:
App::bind('path.public', function() {
return base_path().'/public_html';
});
But I am beginner, so I do not find the solution.
Thank you.
The best option is to configure your local installation of WAMP to use Laravel's public folder as the document root. You have two options here:
Option 1. Use wamp just for this project alone
Find your httpd.conf file. This is the server config, and should be located in C:\wamp\bin\apache\Apache2.4.4\conf. (it's a good idea to make a backup of this file before editing)
Open the config file in notepad, find the line DocumentRoot "c:/wamp/www" and change to DocumentRoot "c:/wamp/www/public" (assuming you have your laravel project in the www folder)
save the httpd.conf and restart wamp.
Now when you visit http://localhost you should see the Laravel welcome screen.
Option 2. Set up a virtual host
This option is a bit more complicated, but will allow you to have multiple websites running alongside each other in wamp, each with their own subdomain that you can use to access them in your browser.
1. open the httpd.conf file in notepad and find the line DocumentRoot "c:/wamp/www". Change it to DocumentRoot "c:/wamp/www/default".
2. add the following snippet below this line:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot 'c:/wamp/www'
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName myproject.localhost
DocumentRoot 'c:/wamp/www/myproject/public'
</VirtualHost>
This will create two new virtual hosts running on your local ip. One will work on the domain localhost and serve files from the www/default folder, the other will work on the domain myproject.localhost and serve files from the www/myproject/public folder.
locate your hosts file at C:\Windows\System32\drivers\etc and open it in notepad. add the following lines:
127.0.0.1 localhost
127.0.0.1 myproject.localhost
This will add two domain mappings that point traffic to your local ip for wamp to handle.
Now navigate to the www folder and create C:\wamp\www\default and C:\wamp\www\myproject. Move your laravel project into the \myproject folder ensuring that the public folder is here as well.
finally restart wamp and now you should be able to go to http://myproject.localhost and see your laravel website.
The solution :
_In His Laravel project: Rename the "public" folder like this: "www."
_In An accommodation (example OVH): remove all that is at the root, including the "www" (except: .ovhconfig).
_Send His project on accommodation.
I hope it will not cause conflict. After I think we should also rename in his Laravel the "public/" in "www/".
thank You

Netbeans and Zend-Framework

I have just started using the Zend-Framework. On advice of a friend I use NetBeans for PHP development with Zend. I have installed NetBeans and referenced the Zend-Framework under Tools>Options>PHP>Zend, registered it since I am using a version newer then 1.10.
Under PHP>General I have inluded the Zend-library path as a Global-Include-Path.
Since I've read that the beginners tutorial provided on the website (http://framework.zend.com/manual/en/learning.quickstart.create-project.html) has some errors and since it does not use NetBeans I started with this video tutorial: http://netbeans.org/kb/docs/php/zend-framework-screencast.html
Creating the project as a Zend-Framework Project worked just fine, all default folders and files are created. However, when I run the project with this defauilt setup the browser should diplay the index.php provided by the Framework under localhost/quickstart, instead of that it just displays a listing of the files of directories:
Index of /quickstart
Parent Directory
.zfproject.xml
application/
docs/
library/
nbproject/
public/
tests/
I suppose there is something wrong with the configuration of the apache server but the video screencast did not mention any needed configuration when using netbeans.
I am using xampp and one of the things that might be the problem is the httpd.conf file as described in the tutorial (http://framework.zend.com/manual/en/learning.quickstart.create-project.html) since no NameVirtualHost-propperty is defined there and no VirtualHost configured. However I didn't want to change the httpd.conf without knowing if that is the problem.
Also adding a line "127.0.0.1 quickstart.local" to the hosts file turned out to be impossible under Windows 7, so in case this is actually neccesary, I would apreciate any help.
Thanks,
Lukas
Have you set the DocumentRoot in the apache httpd-vhost.conf to the public folder?
All you should need to do is add public to the end of your current document root...
Also to change the vhosts file in windows 7 you need to find notepad in the start menu -> all programs -> accessories
Right click and run as Administrator
File -> open -> C:\Windows\System32\drivers\etc\hosts
Now add your records and save.
Opening as Administrator allows the save to attually save the changes.
Ironically, I just went through all of this yesterday. First, what happens when you type: localhost/quickstart/public, into your browser instead of: localhost/quickstart ? The controller is accessed via the index action and .htaccess file inside that directory.
Second, in regards to editing the hosts file... I have windows 7 as well, and all i did to find it was type "system32" in the Search Programs and files, then follow the path to the hosts file. I was able to edit it using notepad and it worked great!
there are two steps to configuring the vhost after that. You will need to uncomment a line in the httpd.conf file under the apache folder, remove the # from httpd.conf:
#Include conf/extra/httpd-vhosts.conf
Then go to the extras folder and add the following to the bottom of your httpd-vhosts.conf file like so:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.localhost
DocumentRoot "C:/path_to_local_webroot/quickstart.com/public"
ServerName quickstart.com
ServerAlias quickstart.com
ErrorLog "logs/quickstart.com-error.log"
CustomLog "logs/quickstart.com-access.log" common
</VirtualHost>
For your hosts file, just add one line to the bottom:
127.0.0.1 quickstart.com
Then restart your server and you should be good to go.

How to setup private folders for PHP includes files for local testing AND live use.

Bit of a noob here. There is a probably a simple solution here - but I can’t get it to work or create a non-kludgey environment for testing. This may be answered in part elsewhere, but I'm still pulling hair out - so I'm going to ask.
The live path on a Linux VPS (with many sites in vhosts directory):
/var/www/vhosts/mysite.com/subdomains/mysubDomain/httpdocs/index.php /* the public, everyone can see web root directory */
I want to be able to configure a private level includes file folder:
/var/www/vhosts/mysite.com/subdomains/mySubdomain/includes/myincludes.php /*where I want the webserver only to read */
Note: I’d also like to use a same-level directory for moving private files after upload.
Locally, I’ve tried to create a similar structure at:
C:\xampp\htdocs\mySubdomain\httpdocs
One bad ideas is to set DocumentRoot in a local vHosts file to the mySubdomain folder – but that exposes the directory structure in things like:
<img src=”/httpdocs/images/image.png">
– and will not be acceptable in the live site.
On my XAMPP testing server, I’ve set up the vhosts file, for mysite.local to create the following
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
DocumentRoot C:/xampp/htdocs/
ServerName localhost
</VirtualHost>
<VirtualHost mysite.local>
DocumentRoot "C:/xampp/htdocs/mySubDomain/httpdocs"
ServerName mysite.local
<Directory "C:/xampp/htdocs/mysite" ></Directory>
</VirtualHost>
But, then I can't access my includes in the the mySubdomain folder.
Questions:
Is this whole approach provide any real benefit over htaccess in ‘live’ level folders (ie httpdocs/includes)? I’ve seen multiple references that storage “below public” will be a more secure file and preferred folder structure.
Is it includepath and the Document Root settings? Some other magic and delicate balance of settings? How does one create local testing access where the httpdocs(not the htdocs local folder is identified as the public directory?
Bonus (and the noob giveaway), if it’s possible to setup DreamweaverCS5.5 in this config for leveraging some of it’s fine features(like auto-discovery of the includes file) for testing and browser checking.
Yes, it does. For instance, if somehow something or somebody screws up the webserver enough the break PHP, but not the webserver itself, people maybe able to download public/somebusinesslogic.php, but NOT private/somefilewithpasswords.php. .htaccess files can also be disabled on Apache, which depending on the actual contents of it can take a while to notice.
At no single point did you provide the contents of your errors, so I cannot tell you what goes wrong, but it should not be a problem to mimic this setup on Windows, provided you use relative includes...
I have enough hate for products created with DreamWeaver that I have seen then I wouldn't touch it with a ten foot pole. Granted, this was 5+ years ago. It may have become less awful.

Categories