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
Related
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.
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.
I update my /etc/hosts file as
127.0.0.1 www.mysite.com
Then in the MAMP's httpd-vhosts.conf, i updated the ServerName as
ServerName www.mysite.com
DocumentRoot /Applications/MAMP/htdocs/mysite
Now, it's working fine. So when I input mysite.com in the browser, it shows the index.html that is inside my folder /Applications/MAMP/htdocs/mysite.
My question is, when I first check the internet on how to create virtual host in MAMP, the examples never use www. in the MAMP .conf file above. So what I did, I remove the www. in the /etc/hosts file and remove also from ServerName in MAMP's .conf file. Now it doesn't work. So do we really need to add the www. in these files?
Another question is since I want to put the index.html inside /Applications/MAMP/htdocs/mysite/public_html, so what I did is I set the DocumentRoot to /Applications/MAMP/htdocs/mysite/public_html instead. Is this correct? It seems to work. Sorry for the confusion I'm kinda new to this thing.
There is no need do configure the conf file directly. Just use the MAMP interface. "littleyellowbird.com" as domain and in the alias section put "www.littleyellowbird.com".
Mamp rebuilds a conf each time you save the settings, your changes have a good chance to get overwritten.
If you want to get to "littleyellowbird.com" even when you enter "www.littleyellowbird.com" in the browser, use a rewrite rule in the .htaccess file for this domain.
Greetings,
Peter
After much faffing about I got laravel to work with XAMPP. However, I can't seem to access directories in the htdocs folder via localhost now. Attempt to access a file returns Object not found! along with The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
The changes I made to get laravel working seems like a blur now. The only thing I remember doing is editing the hosts file to enable the virtual host to work by adding 127.0.0.1 laravel.dev in the hosts file (using a mac btw). I also added a virtual host to the httpd-vhost.conf file.
I did undo the above changes but it didn't make a difference.
Any thoughts on whats gone wrong?
Thanks.
Dispelling Confusion
Just thought I'd clarify what my experience is. Before installing laravel 4 I could access all my projects with localhost/someProjectName but now it fails.
I'm trying to identify what change caused this behaviour. Btw, I have no problems accessing my laravel project (my mapping allows me access to it via laravel.dev)
Look into your /etc/httpd.conf file and see if you have Virtual hosts activated.
If so, check your etc/extra/httpd-vhosts.conf file. You might have set up a VirtualHost already.
EDIT: I have found that once you turn on Virtual Hosts, XAMPP needs a default VirtualHost for your basic htdocs files
Try adding a default VirtualHost (at the bottom of the file) like so:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Applications/XAMPP/htdocs"
<Directory "/Applications/XAMPP/htdocs">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
It sounds to me like it is a problem with the way your directories are configured. Be sure to create a Virtual Host (if you're using Apache) that points to the public folder within your application directory.
For example, if your Laravel project is under /Applications/XAMPP/htdocs/Laravel then set up a Virtual Host like this:
<VirtualHost *:80>
DocumentRoot /Applications/XAMPP/htdocs/Laravel/public
# Other directives here
</VirtualHost>
Additionaly, if you're working with PHP >= 5.4, SSH into the application folder and run
./artisan serve
(Be sure that your PHP executable is in your PATH variable). Then go localhost:8000 and you should have your application running.
Running this command runs the PHP built-in webserver and saves you the trouble of configuring virtual hosts.
In your Apache's http.conf, find the DocumentRoot line and add the subdirectory /public on the end.
Once that is done and you've restarted Apache, you'll be able to access everything which is contained within your htdocs/public folder (including subdirectories of that folder), along with any routes you've defined in Laravel.
Laravel is designed to be set up this way as to protect the code and files by not having them in the folder which is served out to the web.
I have same issue and found that there are miss configuration in vhost. So that's are correct configuration.
in etc/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/laravel-master/public"
ServerName laravel.local
ErrorLog "logs/laravel-master-error.log"
<Directory D:/xampp/htdocs/laravel-master/public>
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
In the hosts file
127.0.0.1 laravel.local
I don't know if you're running L4 or L3. However, launch CLI and
$ cd ./path/to/project
Then for L4:
$ php artisan serve
For L3:
$ php -S localhost:8000 -t public
Now you can go to localhost:8000 and see your application.
You're having problem because the object really doesn't exist in your htdocs directory. You don't have to append xampp after localhost or 127.0.0.1 because xampp will treat it as an object or a folder under htdocs.
if you want to access your blog, make sure you have a blog folder under htdocs and put in your URL localhost/blog
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.