I'm trying to learn Laravel, but ran into an issue I hope you can help resolve. Recently, while working to learn php programming I installed XAMPP, without problem and used it with both php and MYSql. It uses the localhost IP of http://127.0.0.1. In the new course I'm using to learn Laravel after the installation of Laravel the setup uses http://127.0.0.1:8000/, which I can access using Visual Code Terminal and entering "php artisan serve". Following the course instructions for setting up Visual Code I next installed an Extension titled "Connect to Server". After installation of the extension I get a dialog box to connect to the database and it defaults to the 127.0.0.1:8000/ address. If I click on the connect button I get an error. That said, if I start XAMPP and change the value in the dialog box and use the XAMPP 127.0.0.1 address I make a successful connection to MYSQL.The question I have is this, am I going to have a problem in the near future as the result of the two different 127.0.0... addresses and if so is there any way to resolve it?
If you look at the problem I have outlined the issue and hope I can get some resolution before I get to the point I run into trouble.
You can use php artisan serve if you wish to use the laravel's serve command. If you wish to use xampp/wamp, you can add a virtual host in your httpd-vhosts.conf file.
In case of wamp, httpd-vhosts.conf file is in C:\wamp64\bin\apache\apache2.4.51\conf\extra where 2.4.51 is the apache version if you did not change the installation path.
In case of xampp, it is C:\xampp\apache\conf\extra
As for the vhost setup, add the snippet below (change depending on your project path):
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "path-to-project\public"
ServerName project.local
<Directory "path-to-project">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/project-errors.log"
CustomLog "logs/project-access.log" common
</VirtualHost>
Next is open your notepad as administrator then go to C:\Windows\System32\drivers\etc then open hosts file. add 127.0.0.1 project.local
restart wamp/xampp. You should be able to access your project using project.local
Xampp comes with Apcahe/ Mysql so when you run xampp it runs apache and mysql both.
but php artisan serve starts only a php server so your database related thins will not work if you are not running mysql separately (With xampp or as a standalone installation)
You can find more about what the artisan serve command to here PHP artisan serve code
Related
I am very new to laravel, I am using windows 7 OS. I have a PHP website made on laravel 5 which I want to run on my browser. I have gone through the videos and the various website on "How to run laravel 5 project on browser" but unfortunately I failed to run my project on the browser.
I am using XAMPP and below is my Virtual Hosts file of apache. My localhost port is 7000.
<VirtualHost *:7000>
DocumentRoot "C:\xampp2\htdocs\basicwebsite\public"
ServerName basicwebsite.com
</VirtualHost>
And inside the hosts file within the system32 folder I have put the following line
127.0.0.1 basicwebsite.com
When I am trying to run it on my browser it gives me an error
"This site can’t be reached
basciwebsite.com refused to connect."
Any help is welcome.
When I'm developing locally with Laravel, I simply execute php artisan serve on the terminal. I can then run it on http://localhost:8000
check below points -
1.) .env file should have APP_KEY
2.) have you created "storage/views" , "storage/cache"
Try This:
<VirtualHost *:7000>
DocumentRoot "C:/xampp2/htdocs/basicwebsite/public"
ServerName basicwebsite.com
<Directory "C:/xampp2/htdocs/basicwebsite">
</Directory>
</VirtualHost>
Try using something other than basicwebsite.com in the servername,
Maybe use basicwebsite.local
Explanation:
.com is widely used therefore using something different should do the trick, try http://nameofwebsite.local
(doesn't have to be .local, can be anything really but not .com or .net for example)
I have a running apache/PHP site using XAMPP on my locahost, and i am learning the basics of python/django and have a python manage.py runserver on port 8000, i read about configuring the virtual host on xampp http-vhost.conf but cannot make it work, i just need to run both and somehow remove the port number on my python site, don't know if configuring apache is the best way any advice would be great!
My apache site is running using below url.
http://localhost/myPHPwebiste
My python/django site is running using below url.
http://localhost:8000/myPythonwebiste
My http-vhost.conf on apache server (i saved my python files inside the htdocs)
<VirtualHost 127.0.0.1:8000>
DocumentRoot "D:/xampp/htdocs/myPythonwebiste"
<Directory "D:/xampp/htdocs/myPythonwebiste">
Options All
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
My goal is to make my python site run on url below.
http://localhost/myPythonwebiste
I got a solution from apache documentation closed to what i want to achieve i include below line into my apache http.conf and got it working.
ProxyPass /myPythonwebiste http://localhost:8000/myPythonwebiste
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!
I installed Bitnami WAMP Stack in Windows 7 and I am trying to get my eclipse php code to run. I found a link online that said to add an alias, but that didn't work, how do I get the code to run in
http://localhost/greenmugcafe/
if my eclipse workspace is located here
C:\Users\Robert\Documents\GitHub\greenmugcafe ?
Edit: I could not find anything on doing this for Bitnami WAMP but I found a few for the Bitnami Django stack.
Any Help at all?
Your code would run from http://localhost/greenmugcafe/ if you changed the virtual host directory of localhost to C:/Users/Robert/Documents/GitHub/
Personally, I think it would be better to create a local domain called greenmugcafe.dev rather than having a folder greenmugcafe in the localhost domain.
How to setup virtual hosts in WAMP
Make sure virtual hosts have been enabled:
Edit /installdir/apache2/conf/httpd.conf
Search for line that includes httpd-vhosts.conf and uncomment it by removing the # at the start
Adding a new virtual host:
Edit the hosts file on your windows system (usually located at C:\WINDOWS\system32\drivers\etc\)
Add the following to the end of the hosts file 127.0.0.1 greenmugcafe.dev. This tells your computer that any url with a value of greenmugcafe.dev should be routed to 127.0.0.1 (aka localhost).
Save the hosts file and now edit this file /installdir/apache2/conf/extra/httpd-vhosts.conf
Add the greenmugcafe.dev virtual host entry at the bototm of the /installdir/apache2/conf/extra/httpd-vhosts.conf file, save, and restart the server.
Here's the code:
#greenmugcafe
<VirtualHost *:80>
ServerAdmin webmaster#greenmugcafe.dev
DocumentRoot "C:/Users/Robert/Documents/GitHub/greenmugcafe/"
ServerName greenmugcafe.dev
ErrorLog "logs/greenmugcafe.dev-error.log"
CustomLog "logs/greenmugcafe.dev-access.log" common
<Directory "C:/Users/Robert/Documents/GitHub/greenmugcafe/">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Require all granted
</Directory>
</VirtualHost>
Now http://greenmugcafe.dev will point to C:/Users/Robert/Documents/GitHub/greenmugcafe/
This method will also work for other WAMP stacks like Wamp Server and XAMPP.
For a launched website on a linux server, instead of the windows host file, we would change the a record of the domain name to point to the server IP address. Then we still need to setup the virtual host so the server knows to recognise the domain name and point it to the correct folder on the server.
Hope that helps :-)
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