Apache vhost directory not loading sites - macos

I moved from linux to a mac. I have Apache and php setup.
Now apache seems to only load the first virtual host listed. It also only loads it in the browser via local host and not the sitename. Its been 3 days hunting the net or solutions nothing seems to work.
now if i make the document root for the virtual host eg. /Library/WebServer/Documents/ then it works. If i add an extra directory it fails eg. /Library/WebServer/Documents/livingahimsa.co.uk
here is the config: ( I have tried the doc root with quotes and without)
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 ahimsainvestments.com
127.0.0.1 livingahimsa.co.uk
127.0.0.1 ahimsavillage.com
255.255.255.255 broadcasthost
::1 localhost
and vhost:
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents/ahimsainvestments.com
ServerName ahimsainvestments.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents/livingahimsa.co.uk
ServerName livingahimsa.co.uk
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents/ahimsavillage.com
ServerName ahimsavillage.com
pache2/httpd.conf

Related

How to configure virtual hosts to work in htdocs directory of Xampp?

I am following a laravel tutorial, where tutor sets up a virtual host to run their app. The app is located in /opt/lampp/htdocs/first-app. My port for running apache is 8000. So if I visit localhost:8000/first-app/public, I can view my laravel app.
My httpd-vhosts.conf file looks like this:
<VirtualHost *:8000>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/opt/lampp/htdocs"
ServerName localhost
ServerAlias www.localhost
</VirtualHost>
<VirtualHost *:8000>
DocumentRoot "/opt/lampp/htdocs/first-app/public"
ServerName app.test
ServerAlias www.app.test
<Directory "/opt/lampp/htdocs/first-app">
Options All
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
My /etc/hosts file looks like this:
127.0.0.1 localhost app.test
::1 localhost app.test
127.0.1.1 pop-os.localdomain pop-os
127.0.0.1 app.test
I have uncommented httpd.conf like so
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
But I am getting this when I visit app.test
Browser output when app.test is visited
What am I doing wrong?
Edit: I have discovered, if I visit www.app.test:8000, it works fine
Just found out that the browser automatically adds port 80. So since I am running apache on port 8000, I need to specify it.
Thus, the settings above actually worked. All I had to do was go to http://localhost:8000 or http://127.0.0.1:8000

XAMPP Unknown Host in windows

I'm facing below issue while use XAMPP in windows. Same working if I connect with VPN.
Unknown Host
Description: Unable to locate the server named "d8.kali" --- the server does not have a DNS entry. Perhaps there is a misspelling in the server name, or the server no longer exists. Double-check the name and try again.
C:\Windows\System32\drivers\etc: hosts
127.0.0.1 localhost
127.0.0.1 d8.kali
C:\xampp\apache\conf\extra: httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/drupal-8"
ServerName d8.kali
ErrorLog "logs/d8.kali-error.log"
CustomLog "logs/d8.kali-access.log" common
</VirtualHost>
Edit:
I have this setup in my local system.
As per below comment, used IP. Even not working.
127.0.0.1 localhost
#.#.#.#(IP) d8.kali

Virtual host on Windows 10 with Apache 2.4

Can you tell me please what am I doing wrong in Virtual host settings?
I am editing two files:
Apache/conf/extra/httpd-vhosts.conf and Windows/System32/drivers/etc/hosts
httpd-vhosts.conf looks like
<VirtualHost 127.0.0.1>
ServerName scouttautomotive.com
ServerAlias www.scouttautomotive.com
DocumentRoot "C:/Apache24/htdocs/scouttautomotive/web"
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName bosp.sk
ServerAlias bosp.sk.localhost
DocumentRoot "C:/Apache24/htdocs/bosp/web"
</VirtualHost>
hosts file looks like
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 scouttautomotive.com
127.0.0.1 bosp.sk
What is wrong with it? I am realy confused cause bosp.sk virtual host works well.
After setting the domain ip to 127.0.0.1 to host file, You must restart your computer or flush dns cache to get that applied. Did you do?
So look at these config files and note that difference is only in the last letter of ServerName.
httpd-vhosts.conf
<VirtualHost 127.0.0.1>
ServerName scouttautomotive.com
ServerAlias scout.com.localhost
DocumentRoot "C:/Apache24/htdocs/scouttautomotive/web"
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName scouttautomotiv.com
ServerAlias drom.com.localhost
DocumentRoot "C:/Apache24/htdocs/scouttautomotive/web"
</VirtualHost>
hosts
127.0.0.1 scouttautomotive.com
127.0.0.1 scouttautomotiv.com
First version redirects me to one hosting which offers this domain to sell. Second version works well as virtual host. Both are created in the same time. So it looks command ipconfig /flushdns may not be enough.
Another possible solutions can be find here https://serverfault.com/questions/452268/hosts-file-ignored-how-to-troubleshoot Good luck!

Setting up virtual hosts on El Capitan

What I've done is:
Added this to httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents/site1"
ServerName site1.loc
ServerAlias www.site1.loc
ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents/site2"
ServerName site2.loc
ServerAlias www.site2.loc
ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>
And in hosts file, I added this:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 site1.localhost
127.0.0.1 site2.localhost
And finally in httpd.conf I uncommented this line:
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
I have restarted apache after this and after I have tried to run something like this:
http://site1/index.html
or http://site2 I get an error which saying:
This site can’t be reached
I am missing something very obvious? It was a long time I did this on Windows, so I guess I made some silly mistake. Also I get :
You don't have permission to access / on this server.
when I try to reach localhost.
Actually it worked after I have changed these:
127.0.0.1 site1.localhost
127.0.0.1 site2.localhost
to this:
127.0.0.1 site1.loc
127.0.0.1 site2.loc

Modifying httpd.conf to serve over the internet in EasyPHP

I'm running EasyPHP on Windows. The default install just opens port 80 on the loopback interface, 127.0.0.1. I want my sites to be accessible over the local network too. There are no simple EasyPHP settings for enabling my other interface, like the one that's connected to the internet (let's say 192.168.1.3). What do I add/modify in Apache httpd.conf?
Use this code in your httpd.conf
ServerName localdomain
# env
SetEnv TMP "/tmp"
ServerAdmin admin#devserver
DocumentRoot "/var/www"
#NameVirtualHost *:80
#Listen 80
##################################################################
# default
<VirtualHost *:80>
DocumentRoot "/var/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www"
ServerName www.localdomain.com
</VirtualHost>
** I just realize EasyPHP is for windows. You might use c:/path/to/www instead of /var/www
I just need to add this line
Listen <your machine IP>:<your port>
e.g.
Listen 192.168.1.3:8080
and restart Apache

Resources