Laravel in Xampp - php

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.

Related

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

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.

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

Laravel basic routing returns 404

I've recently started learning Laravel but there is one problem which I don't know why it occurs. My current Laravel project is located at wamp/www/codebright. When I access localhost/codebright/public I see the welcome page to Laravel.
When I create a simple routing:
Route::get('my/page', function()
{
return "Harro world";
});
and trying to access:
localhost/codebright/public/my/page it returns with 404 error, not even with Laravel error. I've also tried to access: localhost/codebright/my/page and still.
However, if I type in CMD php artisan serve and open a server on 8000 port and then access:
localhost:8000/my/page it works just fine. I would like to know why my first method without the artisan command didn't work.
Thanks in advance!
Note
It seems like that if you have XAMPP installed, none of the problems mentioned above and in the answer comment section are occurring. Basically, if you are using XAMPP, you most likely won't get any error and the program will work just fine.
It is indeed possible to do what you want but if you're not using artisan serve you must have a webserver set up correctly. From your original post you obviously have a webserver set up as you get the welcome page, but it looks to me like one of the following:
You don't have the .htaccess file in place
Your base vhost (or Apache config if not using a vhost) on your web server setup does not AllowOverride All (which is required to allow .htaccess files to work)
You don't have mod_rewrite turned on
You should check these out. As a minimum, Laravel requires a way to turn URIs that don't exist as real files (my/page) into something it can fake a page for. This pretty much requires the use of mod_rewrite and an .htaccess file to specify the rules.
Explanation of the difference between using Apache and artisan serve: artisan serve does not use a 'dumb' webserver like Apache and instead uses a webserver built into PHP which has knowledge of how to handle 'non-existing' URIs that you browse to, which is why you don't need mod_rewrite and the .htaccess file.
Have you created virtual host for your laravel project?
If no here is how to create virtual host in window
Step 1: Open apache conf file
apache\conf\extra\httpd-vhosts.conf
Add below code in last line.
<VirtualHost *:80>
ServerName www.mark-thomas.loc
DocumentRoot E:\wamp\www\codebright\public
SetEnv APPLICATION_ENV "development"
<Directory E:\wamp\www\codebright\public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
E:\wamp\www\codebright\public is your laravel app path, you can replace it with your folder path.
Step 2:
Open-> Windows\System32\drivers\etc\hosts
Add your ip address in list of IP address
192.168.1.231 www.laravel.loc
Restart your apache server hit http://www.laravel.loc/my/page. Now you will see your message!

XAMPP localhost returns object not found after installing Laravel

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

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.

Categories