XAMPP new VH replaces localhost? - php

I am trying to create a new virtual host for one of my domains. I use XAMPP as my local test environment, and in the htdocs folder i have a folder with me website.
So i have this structure:
htdocs/mysite
I wanna be able to create a virtual host for mysite. So i have done the following:
httpd-hosts in apache
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/mySite"
ServerName mySite.test
ServerAlias *.mySite.test
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "C:/xampp/htdocs/mySite"
ServerName mySite.test
ServerAlias *.mySite.test
SSLEngine on
SSLCertificateFile "crt/mySite.test/server.crt"
SSLCertificateKeyFile "crt/mySite.test/server.key"
</VirtualHost>
I also installed an SSL certificate, but that is not my issue.
Then i changed the:
host file
127.0.0.1 mySite.test
So i restart everything, and this happens:
i try to go to mySite.test => Does NOT work, cannot find it.
If i go to mySite.test.localhost => it works.
Maybe this is working as intended? However, the weird issue is then that i cannot access my "regular" localhost anymore. If i try to go to localhost/dashboard to get the default dashboard, it goes to mySite again?
So it is like what i have done have completely "replaced" the localhost somehow? Yet, i always have to include it in my url adress, i cannot just say mySite.test?
I am pretty new to do virtual hosts, so please let me know what i am missing here.
thanks all

Related

Virtual Host on Xampp for Laravel is not working

Hello i am learning Laravel and trying to modifying vhost file of my xampp server for laravel practice project, but its not working.
code of vhost file is
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/laravel5Prc/public"
ServerAdmin admin#localhost
ServerName laravel5.prc
ServerAlias laravel5.prc
<Directory "D:/xampp/htdocs/laravel5Prc/public">
AllowOverride All
Options Indexes FollowSymLinks
Require local
# if you want access from other pc's on your local network
#Require ip 192.168.1.121
# Only if you want the world to see your site
#Require all granted
</Directory>
</VirtualHost>
i have taken this code from this url
How to enable Virtual Host on Xampp for Laravel?
its not working form me, anyone please guide me what am i doing wrong in it ?
I'm strongly recommend you to use Laravel's vagrant box called Homestead instead of xampp, it's really amazing! You can read about it here. It's much more flexible and easier to understand than anything else.
I was using php-7.3.2 and had similar problem. This is not the solution to the problem, but an alternative. I went back to php-7.1.25 and ran again. I'm still going to check out what the problem is with version 7.3 and laravel, but maybe this will help some people who come here with the same problem.
This is what you should do, add or uncomment this below at the top of the xampp vhost file
NameVirtualHost *:80
Change this to you valid assumed domain and add the Directory index
ServerName laravel5.test
ServerAlias laravel5.test
DirectoryIndex index.php
And then go to the this folder C:\Windows\System32\drivers\etc\hosts in windows and add your domain of choice for example see this below
127.0.0.2 laravel5.test
127.0.0.3 anotherdomain.test
**** Please note don't use the localhost or 127.0.0.1 created by default to set yours's
you should create you own e.g. (127.0.0.2, 127.0.0.3, 127.0.0.4) in that order
After then restart you xampp server you should be good to go
**** I notice your Document and Directory has this "D:/xampp/htdocs/laravel5Prc/public"
change the D to C and please I would advise your laravel project should be outside the xampp folder, you can use the Document folder for this.
//Open C:\Windows\System32\drivers\etc\hosts
127.0.0.1 laravel5.prc
//Open xampp/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/xampp/htdocs/laravel5Prc/public"
ServerName laravel5.prc
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/d`enter code here`ummy-host2.example.com-access.log" common
</VirtualHost>
why you don't use
php artisan serve
to run laravel on localhost.
from https://laravel.com/docs/5.4/

Test apache site on mobile phone locally

I am using ubuntu 16.04 and working on a laravel project.
I have a new laravel project in /var/www/html named myproject and can access it by going to
localhost/myproject/public/
But in order for the routes to work, I found a solution to create a site in /etc/apache2/sites-available like this:
<VirtualHost *:80>
ServerName myproject.dev
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/myproject/public
<Directory /var/www/html/myproject>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and then added a new entry in /etc/hosts file, like this:
127.0.0.1 localhost
127.0.1.1 myhostname
127.0.0.1 myproject.dev
restarted apache now can access the project using http://myproject.dev in the browser.
Now I want to test some responsive stuff using an actual phone.
I tried http://myproject.dev it doesn't work, also if I do
http://myhostname/myproject/public
It takes me to the landing page, but accessing any other route gives a 404. and this format also doesn't work on the computer browser.
However this works on the computer:
http://localhost/myproject/public
but not on the phone.
How can I access the myproject site on my phone? And also both my computer and phone are connected to the same wifi access point.
Remember you phone does not know about your sites url as it is not in any DNS server and you cannot fiddle with the hosts file on the phone unless you jailbreak it.
What I normally do is create a new Virtual Host to be used when accessing the site from a phone. But on this Virtual Host I use another port number as adding a port number is easy on the phones browser.
So add another VH like this and another Listen command
Listen 81
<VirtualHost *:81>
ServerName myproject.dev
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/myproject/public
<Directory /var/www/html/myproject>
AllowOverride All
# add access from any ip on your subnet
Require ip 192.168.1
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then assuming the Server is running on 192.168.1.100 you use this url to get to the site
http://192.168.1.100:81
and your routes should work without any fiddling
Add an alias on the IP address to your <VirtualHost>-directive. Something like ServerAlias 192.168.1.100. Then, you should be able to reach the web application on that IP address, like this: http://192.168.1.100/myproject/public.
The main principles at work here are pretty independent of laravel, but more related to DNS and networking, and apache configuration.
Consider using .xip.io solution.
Example:
if your local computer IP address is 192.168.1.2 , and you can visit your local site as http://192.168.1.2/somepage.html, in your phone you can access it with http://192.168.1.2.xip.io/somepage.html. To make this solution work, you need to edit your apache virtualhost, something like:
<VirtualHost *:80>
DocumentRoot "/path/to/site"
ServerAlias site.*.xip.io
ServerName site.dev
</VirtualHost>
Note: Don't forget to restart apache.

Apache VirtualHost Issues

I have two installations of laravel. One in a folder called "laravel" and the second in a folder called "learningLaravel". Both of them are siblings in the same parent folder. Before i installed "learningLaravel" i used to access the site in "laravel" through localhost/laravel/public, and everything works fine .
After i installed "learningLaravel", i decided to create a virtual host for it on my WAMP server with the name "learningLaravel.dev" . My [windows/system32/drivers/etc/hosts] file looks like this:
127.0.0.1 localhost
127.0.0.1 localhost
// I added this entry. The first two entries above was already there
127.0.0.1 learninglaravel.dev
I added the following to my Apache "httpd-vhosts.conf"::
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/learningLaravel/public"
ServerName learningLaravel.dev
</VirtualHost>
Now i can access "learningLaravel" through learningLaravel.dev. But when i want to access the site in the "laravel" folder through localhost/laravel/public, i get a message ::
Not Found
The requested URL /laravel/public was not found on this server.
I try localhost also and i get ::
Not Found
The requested URL / was not found on this server.
The problem i have now is anything that begins with localhost doesn't work, but learningLaravel.dev works.
What changes do i need to make? thanks.
Just define 2 virtual hosts:
The first catches all domains which don't have their own virtual host. In this example these are domain1.dev, domain2.dev, domain3.dev and localhost.
The second host catches the domain learninglaravel.dev
httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/"
ServerName localhost
ServerAlias *.localhost
</VirtualHost>
<VirtualHost learninglaravel.dev:80>
DocumentRoot "c:/wamp/www/learningLaravel/public"
ServerName learninglaravel.dev
ServerAlias *.learninglaravel.dev
</VirtualHost>
windows/system32/drivers/etc/hosts
127.0.0.1 learninglaravel.dev
# you don't need the following this is just for explanation:
127.0.0.1 domain1.dev
127.0.0.1 domain2.dev
127.0.0.1 domain3.dev

configuring virtual host in xampp for magento installation

I am very new to magento and php and i am trying to create a virtual host url for my magento site.
Currently the url is
http://localhost:8080/Magento/
And if i create any website i have to use url's such as below
http://localhost:8080/Magento/website1
http://localhost:8080/Magento/website2
...
After referring to several examples such as this http://sawmac.com/xampp/virtualhosts/ i have managed to configure my files such as below
Step 1:
In the file C:\Windows\System32\drivers\etc\hosts i have append the below mapping
127.0.0.1 clientA.local
Step 2:
And in the file C:\xampp\apache\conf\extra\httpd-vhosts.conf i have append the below code
NameVirtualHost *:8080
<VirtualHost *:8080>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "C:\xampp\htdocs\magento"
ServerName clientA.local
<Directory "C:\xampp\htdocs\magento">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
After step 1 typing typing clientA.local:8080/magento opens localhost:8080/magento
But step 2 doesn't change anything.
I want to do something as below
clientA.local should open http://localhost:8080/Magento/website1
clientB.local should open http://localhost:8080/Magento/website2
...
I have tried changing the Document root , directory in several ways nothing helped.
If any one has any idea on this senario please contribute here.
thanx

Wordpress site returning 404 error when requesting content from subfolders

I'm using WAMPSERVER to run a wordpress site that has to be acessible by the users in my network, like a environment for testing together.
Localhost works fine, but at first i couldn't access the aplication from other computers in the network. I created a rule to open the port 80, created an Alias in the Apache configuration, and it worked but the theme and any images inside subfolders wouldn't load and the console was returning lots of 404 responses.
I want to map the subfolders and its files that are under the 'base dir' of the site. I tried tons of options in the Apache conf. file but i couldn't make it.
Attached a printscreen of the responses, the apache conf file and the windows hosts file
Httpd.conf :
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "c:/wamp/www"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#animamidia
DocumentRoot "C:\wamp\www\website"
ServerName www.animamidia
ErrorLog "logs/animamidia-error.log"
CustomLog "logs/animamidia-access.log" common
<Directory "C:\wamp\www\website\*">
Options FollowSymLinks Includes
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
Windows hosts file:
127.0.0.1 www.animamidia
The site with it's theme broken because the requisition returned a 404
Well i found the problem.
Even though i couldn't enter the wordpress-admin i decided to check the 'wp-config.php' file just in case something is wrong or missing.
And what i did find is that the 'Home-URL' and the 'WP-URL' were set at 'localhost/website' which means that all the requisitions would point at this location as a base directory.
All i had to do was to use the 'define' comand and set the site's URL to the machine's IP and now the environment is all set up for the guys over here to develop and test their stuff.

Categories