Trying to get subdomains working locally with codeigniter and mamp - apache

I'm trying to follow this tut http://net.tutsplus.com/tutorials/php/basecamp-style-subdomains-with-codeigniter/ to get subdomains working locally.
I've added this to the /etc/hosts file
127.0.0.1 snapgiftapp.com
127.0.0.1 test1.snapgiftapp.com
127.0.0.1 test2.snapgiftapp.com
and i've added this to the end of the /Applications/MAMP/conf/apache/httpd.config file
<VirtualHost *:80>
DocumentRoot "/Users/tomcaflisch/Sites/snapGiftAppFront"
ServerName snapgiftapp.com
ServerAlias snapgiftapp.com
<Directory "/Users/tomcaflisch/Sites/snapGiftAppFront">
Options -Indexes
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/tomcaflisch/Sites/snapGiftApp"
ServerName snapgiftapp.com
ServerAlias *.snapgiftapp.com
<Directory "/Users/tomcaflisch/Sites/snapGiftApp">
Options -Indexes
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
When I point my browser to snapgiftapp.com or test1.snapgiftapp.com, I get the same site located in the snapGiftAppFront folder

I had to go into the mamp configurations and change the port to 80 instead of 8888.

Related

XAMPP virtualhost site with all configs not working

I am trying to run site my.com locally on XAMPP's apache server. Here my configurations in httpd-vhosts.conf file in the path ...\XAMPP\apache\conf\extra:
<VirtualHost *:80>
DocumentRoot "D:/IDEs/XAMPP/htdocs"
ServerName localhost
<Directory "D:/IDEs/XAMPP/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/IDEs/Websites/my.com"
ServerName my.com
<Directory "D:/IDEs/Websites/my.com">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Also, I remembered to add two lines in the hosts file, with is located in C:\Windows\System32\drivers\etc:
127.0.0.1 localhost
127.0.0.1 my.com
However, when I enter via link 'my.com' with enabled apache server, I've got only page with folder directories, which are in htdocs XAMPP's folder.
I have checked a lot of videos and stackoverflow questions, but nothing helped.
I would be pleased if you could help me with solving this issue.
first you should arrange directories on httpd.conf
example:
<Directory "C:/SERVER~1/web/site1">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "C:/SERVER~1/web/site2">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
and then arrange vhosts.conf like this
example :
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.site1.com
DocumentRoot "C:/SERVER~1/web/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName site1.com
DocumentRoot "C:/SERVER~1/web/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName www.site2.com
DocumentRoot "C:/SERVER~1/web/site2"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.com
DocumentRoot "C:/SERVER~1/web/site2"
</VirtualHost>
After five days-night of reading, searching, trying, I finnally fould the solution and done it in some steps:
First of all, forget about every file, and concentrate on the httpd-ssl.conf which is located in D:\IDEs\XAMPP\apache\conf\extra.
Second:
find the line "SSL Virtual Host Context" which has been commented. And below, find the line <VirtualHost _default_:443>.or simmilar. Then change it to <VirtualHost *:443>.
Third, change document root to the path of xampp's htdocs, for example, "D:/XAMPP/htdocs". Also, change ServerName from www.example.com:443 or similar, to localhost.
Here we done.
And Finally, after line </VirtualHost>, insert code
<VirtualHost *:443>
DocumentRoot "D:/IDEs/Websites/my.com"
ServerName my.com
<Directory "D:/IDEs/Websites/my.com">
Require all granted
</Directory>
</VirtualHost>
Change Document Root and Directory paths to your website location. And Servername to your server name.
RESTART APACHE
it works for me.
I also understood than some website uses SSL on localhost while the others not.
SO if you have exception like Apache/2.4.37 (Win32) OpenSSL/1.0.2p PHP/7.0.33 Server at my.com Port 443 you shold add your virtualhost configs into httpd-ssl.conf file.
If you got like ... Port 80 add yourl virtualhost configs into httpd-vhosts.conf

Virtual Hosts on WAMP causing 403 forbidden on 192.168.1.6… other aliases still work

recently modified httpd.conf and httpd-vhosts.conf to add vhosts...
#IncludeOptional "E:/wamp/vhosts/*"
Include "E:/wamp/alias/*"
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "e:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "e:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
Require ip 192.168.1
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot E:/activeWork/projects
ServerName projects.local
<Directory "E:/activeWork/projects">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot E:/activeWork/projects
ServerName www.projects.local
<Directory "E:/activeWork/projects">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot E:/activeWork/projects
ServerName api.projects.local
<Directory "E:/activeWork/projects">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
after that when i try to load 192.168.1.6 or 127.0.0.1 , gives me :
Forbidden
You don't have permission to access / on this server.
i've tried to solve it whit this answer but not works for me
and by recommandation in answers i check my access.log and this is the result:
192.168.1.6 - - [03/Oct/2016:11:03:00 +0330] "GET / HTTP/1.1" 403 288
127.0.0.1 - - [03/Oct/2016:11:00:55 +0330] "GET / HTTP/1.1" 403 286
if you are sure that your wamp Installation path is inside E:
then I suggest you to check your access log and error log to collect more information.
I assume you are using Apache 2.4 or later on your Wampserver? If so, then replace the require rules with "Require all granted" in your vhosts, like this:
<VirtualHost *:80>
DocumentRoot "e:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "e:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
If it still doesn't work, check if your firewall is blocking your access.
my problem is to define 3 vhost point to same directory and this confused apache...finally tnx to riggsfolly i fixed that...beside of this i make changes from this guide to define VHost to have setup things in a right way

Apache2 subdomain redirects to main domain

I have an EC2 instance setup running Ubuntu 14.04 and Apache. I have a single elastic IP serving multiple domains and subdomains all of which point to individual folders on the server. The problem I am having is unless the subdomain is explicitly set in my .conf it will redirect to the main domain. I can't seem to find a definitive answer here or in google.
I have a single .conf file residing in /etc/apache2/sites-enabled/ serving all of the domains and subdomains like so:
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/html/mydomain.com
<Directory /var/www/html/mydomain.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName sub1.mydomian.com
ServerAlias www.sub1.mydomain.com
DocumentRoot /var/www/html/sub1.com
<Directory /var/www/html/sub1.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName sub2.mydomian.com
ServerAlias www.sub2.mydomain.com
DocumentRoot /var/www/html/sub2.com
<Directory /var/www/html/sub2.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName mydomain2.com
ServerAlias www.mydomain2.com
DocumentRoot /var/www/html/mydomain2.com
<Directory /var/www/html/mydomain2.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
So if I go to sub1.mydomain.com or sub2.mydomain.com it gets properly routed. But if I type sub3.mydomain.com which does not exist in my .conf file it gets redirected to mydomain.com. I do not want this behavior. How do I resolve this?
You need to enable name based virtualhosts. Add below line before your first virtual host and restart apache.
NameVirtualHost :80

Apache vhost not working for subdomains

I have this configuration but both url app.test.com & stage.test.com
redirect to same code/deployment
<VirtualHost *:80>
ServerName app.test.com
DocumentRoot /var/www/html/Test-Prod/web
<Directory "/var/www/html/Test-Prod/web">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog logs/test-prod__error_log
CustomLog logs/test-prod_access_log common
</VirtualHost>
<VirtualHost *:80>
ServerName stage.test.com
DocumentRoot /var/www/html/Test/web
<Directory "/var/www/html/Test/web">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog logs/test-website_error_log
CustomLog logs/test-website_access_log common
</VirtualHost>
The usual error for this is leaving out the NameVirtualHost directive if you're still using httpd 2.2
Add the following in your config file and it'll probably work
NameVirtualHost *.80
You might want to read the documentation for Named-based Virtual Host Support with httpd 2.2.
NameVirtualHost *.80
<VirtualHost localhost:80>
ServerName color
ServerAlias localhost
ServerPath "C:/wamp/www/subwww/color"
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www/subwww/color">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
in above code, subdomain name is color
and the url is http://color.localhost/
if the operating system is windows then add "127.0.0.1 color.localhost" in "C:/windows/system32/dirvers/etc/hosts" with notepad run as administration

XAMPP Windows Apache VirtualHost 403 Forbidden

I had XAMPP running fine with virtual hosts on my winodws 8 machine until I was forced to restart my computer (windows update). After restarting I've noticed my virtual hosts weren't working any more. Instead of trouble shooting too much I decided to reinstall XAMPP (currently have XAMPP 3.1.0 running. Which is runnign Apache v 2.4.3)
I have my windows host file edited to redirect sitename.localhost to 127.0.0.1 and this is what I have in my httpd-vhost.conf:
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\Users\USER\Documents\sitename"
ServerName sitename.localhost
<Directory "C:\Users\USER\Documents\sitename">
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Every time I try to access http://sitename.localhost I get a 403 Access Forbidden error. Any idea what I'm doing wrong?
Try adding Require all granted to the Directory configuration:
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\Users\USER\Documents\sitename"
ServerName sitename.localhost
<Directory "C:\Users\USER\Documents\sitename">
Order deny,allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
Also, try to set reading permissions to the web site folder for Authenticated users.
This will list out as index.
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\USER\Documents\sitename"
ServerName projectname.dev
ServerAlias projectname.dev
<Directory "C:\Users\USER\Documents\sitename">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
could you test this code pls instead of yours?
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\USER\Documents\sitename"
ServerName sitename.localhost
<Directory "C:\Users\USER\Documents\sitename">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
btw, do you have index.html/php file in folder "C:\Users\USER\Documents\sitename", don't you?