I have a new laptop, and am now trying to run a laravel application.
First, am trying to setup a virtual host for the project so that I can access blog.local
I went my hosts file and setup the drivers like the following:
127.0.0.1 localhost
127.0.0.1 test.local
127.0.0.1 blog.local
The for the apache configuration I have the following:
<VirtualHost *:80>
DocumentRoot "C:\XAMPP\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\XAMPP\htdocs\blog"
ServerName blog.local
</VirtualHost>
When I try to access my url I do not see the site but the files only:
For this and future projects, how can I create a local url and see the front-end when I visit it?
You need to address your public folder,
<VirtualHost *:80>
DocumentRoot "C:\XAMPP\htdocs\blog\public"
ServerName blog.local
</VirtualHost>
The document root is a directory (a folder) that is stored on your host's servers and that is designated for holding web pages. When someone else looks at your website, this is the location they will be accessing.
Change the DocumentRoot to according to your PHP project is located.
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/blog/public"
ServerName blog.local
</VirtualHost>
Restart the servers after making any changes! If you don’t reset the server to apply the changes, nothing will work even though you know you’ve done everything right.
Related
I am XAMPP on my localhost. When I go to localhost it's redirecting me to localhost/dashboard/ That's good.
now, I want If I type laravel.dev It's should load the laravel public folder
For that I configure httpd-vhosts file as below:
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/laravel-practice/public/"
ServerName laravel.dev
</VirtualHost>
windows hosts file like below:
127.0.0.1 localhost
127.0.0.1 laravel.dev
now, If I go to laravel.dev it's redirecting me to localhost/dashboard/ location. but its should be redirecting me to laravel public folder which is D:/xampp/htdocs/laravel-practice/public/
can you tell me how can I fix it?
If everything else is ok then change * to laravel.dev
<VirtualHost laravel.dev:80>
DocumentRoot "D:/xampp/htdocs/laravel-practice/public/"
ServerName laravel.dev
</VirtualHost>
Two important points:
Always restart apache after edit httpd-vhosts
Include NameVirtualHost laravel.dev:80 before <VirtualHost laravel.dev:80>
UPDATE
Xampp has a default index.php on htdocs folder, try deleting this file, because index.php redirects to /dashboard and let me know if worked
I have installed Laravel Project with all its dependencies. Also, Setup Virtual Hosts for the same. But, When I hit the url like say "dev.laravelProject.com" it immediately opening Xampp Dashboard.
I don't know why is that happened.
Any Help Appreciated
First, change your /etc/hosts file to have a mapping of your desired website name(s) (www.example.com), and target IP address (127.0.0.1). I used my local IP address.
IPAddress Hostname Alias
----------- -------------------------- ------------------
127.0.0.1 www.librarymodule.com librarymodule.com
127.0.0.1 www.dev.librarymodule.com dev.librarymodule.com
So, you can set only one domain
<VirtualHost *:80>
DocumentRoot "/var/www/html/LibraryProject/public"
ServerName librarymodule.com
ServerAlias *.librarymodule.com
<Directory "/var/www/html/LibraryProject/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
or add first the main one and then the subdomain:
<VirtualHost *:80>
DocumentRoot "/var/www/html/LibraryProject/public"
ServerName www.librarymodule.com
ServerAlias librarymodule.com
</VirtualHost>
<VirtualHost *:80>
ServerName www.dev.librarymodule.com
ServerAlias dev.librarymodule.com
DocumentRoot "/var/www/html/LibraryProject/public"
</VirtualHost>
As a final step, you may need to add the websites to Apache by issuing the below commands:
# a2ensite librarymodule.com
# a2ensite dev.librarymodule.com
- Reload apache.
I am new to Laravel and while creating a new project, I wanted it to be named in Virtual Host. By this way,
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/logo/public"
ServerName logo.local
</VirtualHost>
I named it, defined IP address for it (127.0.0.1) in HOSTS file but now, when I write localhost/ in the address bar, instead of going to Xampp("Welcome to XAMPP"), it goes to my laravel project. I know that if I will define my localhost the same way, like
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
the problem will be solved but I don't know the reason of doing this. Why do I need to name C:/xampp/htdocs/ as localhost, if it was default before my laravel project?
if i get your meanings correct, you need add a default virtual host before other virtual host, so in your case, should be like this,
add the code block to end of the httpd.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/logo/public"
ServerName logo.local
</VirtualHost>
and edit hosts file to
127.0.0.1 localhost
127.0.0.1 logo.local
I am preparing to create my portfolio site and this is something I always thought. I find XAMPP default admin page useful in some ways to me, but as I am developing website, I can't access it any more.
I want to know is there a way to keep XAMPP default page as I am developing other websites.
I know I can setup virtual hosts for several websites, but is it same for XAMPP? I have done virtual host one time as work. At, first it didn't work(what was CakePHP app), but later I have managed to make it work.
UPDATE:
So I found out this post about Hosting multiple local sites with XAMPP and have edited my Virtual Host config file like this:
<VirtualHost *:80>
ServerName localhost/xampp
DocumentRoot "C:/xampp/htdocs/xampp/"
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs/"
</VirtualHost>
My windows host file:
127.0.0.1 localhost
127.0.0.1 localhost/xampp
For now, accessing both 127.0.0.1 and 127.0.0.1/xampp redirect me to XAMPP home page, which is in C:/xampp/htdocs/xampp/
When I access localhost, browser redirects me to index.php file(As 127.0.0.1 also should), which is for testing purposes in htdocs folder. However if I try to access localhost/xampp I get error in Chrome - "This webpage has a redirect loop".
I have no idea how to progress on from here.
I found out answer. THe issue was with my naming of xampp admin page domain, instead of using someting, which include localhost for xampp page, I had to use something else, as it will not conflict when using your own naming.
So my hosts file now:
127.0.0.1 localhost
127.0.0.1 xampp-admin
And Apache Virtual Host file:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs/"
</VirtualHost>
<VirtualHost *:80>
ServerName xampp-admin
DocumentRoot "C:/xampp/htdocs/xampp/"
<Directory "C:/xampp/htdocs/xampp/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This part(below) didn't change anything, I added, because I saw it in examples, but I still have no idea, what it's useful to:
<Directory "C:/xampp/htdocs/xampp/">
Order allow,deny
Allow from all
</Directory>
Still, maybe someone can suggest me more conventional name for Xampp admin page?
All you need to is place this at the top of your httpd-vhost.conf before other virtual host configurations.
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/dashboard/"
ServerName xampp.admin
<Directory "C:/xampp/htdocs/dashboard/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
How can I set up virtualhost for multiple domain name on Windows?
I will use it for my own test projects. I have three projects that I need to set up and at the moment I'm using xampplite for the portable Apache.
www.foo-bar.com --> direct to c:\xampplite\htdocs\foo-bar\
www.abcdef.com --> directo to c:\xampplite\htdocs\abcdef\
www.qwerty.com --> direct to c:\xampplite\htdocs\qwerty\web\
I also need to access on another project, but it just like typing
http://localhost/my-project/
How can I write the vhost configuration for that?
You need to do several steps in order to make this work.
Update the hosts file. On Windows XP, you can find it under c:\WINDOWS\system32\drivers\etc\. You should already see the first line from below. It takes care of your mentioned other project. Add the additional ones to make any requests to the mentioned virtual hosts routed back to your own machine.
127.0.0.1 localhost
127.0.0.1 foo-bar.com
127.0.0.1 abcdef.com
127.0.0.1 qwerty.com
Update the vhosts file in Apache configuration. Under your XAMPP folder, add the following to apache\conf\extra\httpd-vhosts.conf and if needed change the ports (i.e., if you use 8080 instead of port 80).
<VirtualHost *:80>
DocumentRoot C:/xampplite/htdocs/foo-bar/
ServerName www.foo-bar.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/xampplite/htdocs/abcdef/
ServerName www.abcdef.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/xampplite/htdocs/qwerty/web/
ServerName www.qwerty.com
</VirtualHost>
Do a quick configuration check. Open {XAMPP-folder}\apache\conf\httpd.conf your file and make sure that the following part is not commented out by a preceding # character:
Include conf/extra/httpd-vhosts.conf
Restart XAMPP.
... and you should be all setup now. Your other project should be accessible at the URI you mentioned if you just put it under C:/xampplite/htdocs/my-project/.
To get C:/xampp/htdocs/my-project/ working, I had to add the following (default?) VirtualHost to apache\conf\extra\httpd-vhosts.conf (in step 2 of MicE's tutorial).
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
127.0.0.5 abcd.com
< VirtualHost 127.0.0.5 >
ServerName abcd.com
DocumentRoot "C:\xampp\htdocs\laravel\public"
<Directory "C:\xampp\htdocs\laravel\public">
DirectoryIndex index.php
AllowOverride All
Order allow, deny
Allow from all
</Directory>
< / VirtualHost >