Xampp apache virtualhost - apache

I have two "htdocs" folder for two websites. I named the folders "website1" and "website2".
As you can see, both folders are inside C:/xampp.
When I type "website1.com" on my browser, I want xampp to serve the files on folder "website1" and its subfolders/subfiles as needed.
When I type "website2.com" on my browser, I want xampp to serve the files on folder "website2" and its subfolders/subfiles as needed.
For simplicity, let's say the landing page is index.php (think of sign-in page). This is the page called when I type "website1.com" or "website2.com".
Then after I hit submit button on index.php, it will call main.php.
I edited two files.
For hosts file, I add the host name that I wanted to be resolved into my localhost. Since I want to serve both website1 and website2 on my local computer via xampp, I added the following lines on hosts file located on C:/Windows/System32/drivers/etc
127.0.0.1 website1.com
127.0.0.1 website2.com
I also edited the apache config file which is httpd.conf
I added the following after the line: Listen localhost:80
<VirtualHost website1.com:80>
DocumentRoot "C:\xampp\website1"
ServerName website1.com
<Directory "C:\xampp\website1">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost website2.com:80>
DocumentRoot "C:\xampp\website2"
ServerName website2.com
<Directory "C:\xampp\website2">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
The current behavior with these configs is that:
Typing "website1.com" or "website2.com" directs me/loads the page properly. For simplicity, the index.php of website1 has just different text compared to website2.
The problem is, once I hit submit button and it tries to load main.php (DIFFERENT folder locations depending if website1 or website2 but SAME file name), I get the following error:
Any help would be appreciated. I am new to web development.
I am also new to this topic (virtual hosts). I happen to search for this because I am getting tired of renaming my htdocs folder. RIght now, when I want to test website1, I rename website1 folder to htdocs. I am thinking that if what I am trying is possible, it may save me time in the long run.

Related

Is there a way to redirect one directory as a root and its siblings as sub directories only via Apache2.4 mod_rewrite?

I must configure an HTTPD Server to serve main site from one of many sub directories, keeping all other to resolve as site sub catalogs. To make it more clear, lets say my root directory looks like this:
/var/www/
˫module_1
˫module_2
˫module_3
˫html
And the URL I want to have is:
example.com/module1 -> gets data from module_1 directory
example.com/module2 -> gets data from module_2 directory
example.com/module3 -> gets data from module_3 directory
example.com/ -> gets data from html directory
I tried some solution from the web, but it ends up wrong, like redirecting all to html or trying to find module data in html folder.
you can try below code your reference :
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/
<Directory "/var/www/">
Options +Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

What is the setting on httpd.conf that makes pages "unreachable"?

I am using wampserver and just created a folder to use as documentroot at c:/webroot. I know wampserver provides c:/wamp/www and c:/wamp/vhosts for serving web pages, I just want to know what settings on httpd.conf prevents apache webserver from serving pages located outside the wamp folder.
You need to think the other way around. It's not about preventing, it's about allowing the access by configuring your server.
You can change the path in your DocumentRoot (see httpd.conf).
Or create an alias. In httpd.conf add :
Alias /webroot "C:/webroot"
and
<Directory "C:/webroot">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
and then open http://127.0.0.1/webroot

Access Apache virtual hosts stored in /users directory

I just upgraded my Mac to Yosemite and managed to get my development environment almost back to normal. In my old set up (which I didn't create), I stored all of my virtual hosts in /etc/apache2/users as separate .conf files.
I'm now no longer able to access those sites and I need to set up my virtual hosts in the /etc/apache2/extra in the httpd-vhosts.conf file. While it does work, I'd rather not have to do this as it's easier for me to organize all of these extra sites when they're in separate files.
Is there anything I can do to get it back to my original set up? Using my old httpd.conf file doesn't work and I've left the new file that originally came with the Yosemite installation because at the very least it left my development environment functional.
The contents of the .conf files I set up in /etc/apache2/users look like this
<directory "/Users/dev/Sites/*/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
#Require all granted
</directory>
NameVirtualHost *:80
<virtualhost *:80>
DocumentRoot "/Users/dev/Sites/mysitename"
ServerName mysitename.dev
</virtualhost>
I was able to get my virtual hosts working by putting them all inside of the httpd-vhosts.conf file. I only had to add the virtualhost bock and left the directory block and the namevirtualhost *:80 line out as that was already inside of the httpd-vhosts.conf file.
Apache's Configuration file /etc/apache2/httpd.conf can include separate configuration files for processing through the Include and IncludeOptional directive (the difference being, if Include doesn't get a matching file it will fail with error but IncludeOptional will just ignore it)
What you can do now is, add this line at the very bottom of your httpd.conf
IncludeOptional users/*.conf
and place your separate configuration .conf files in /etc/apache2/users directory for including them in the main httpd.conf file

Apache Stopped Following Symlinks

Yesterday, I had a fistful of sites running locally with no problem. Today, nothing opens and I have a log full of this:
Symbolic link not allowed or link target not accessible: /var/www
I have no idea what I did (I didn't open/change my httpd.conf file in any way), but clearly it was something bad. I run virtual hosts and the root directories are located in ~/Developer/www. In order to share the config files across multiple Macs with different home directories, I've created a symlink, /var/www which points to ~/Developer/www.
All of the virtualhost config files point their DocumentRoot to /var/www/project_directory and its own root directory has the FollowSymLinks option:
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost.local localhost.dev
DocumentRoot /var/www/_localhost
<Directory /var/www/_localhost>
Options FollowSymLinks Indexes
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
My main httpd.conf file, similarly, has the FollowSymLinks option enabled for /:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
Any idea what I could have done to stop Apache from understanding symlinks or, better yet, what I can do to get it back on track?
Thanks.
UPDATE:
I should add that all of the directories in the "stack" are executable by all users and that this is the native Apache install on OS X Lion.
I guess I made an assumption that I shouldn't have. I had verified every relevant permission except the one that evidently mattered. Apache didn't have execute permissions on my top level home directory. I checked, re-checked and triple checked everything under that, but having never changed anything in that directory itself, I just didn't anticipate it being the issue.

Magento not accessible since tried to move to multi website setup. Apache issue?

I wish I had never seen this article:
http://www.magentocommerce.com/knowledge-base/entry/tutorial-multi-site-multi-domain-setup
I have Apache 2.2 installed on my XP machine and until a while ago I had a Magento site that I could test the development of a custom module on. I decided that I wanted to have multiple websites and multiple stores so that I could test that my modules configuration variables set at the different scopes (global, website, and store) were working as expected.
So I followed the instructions in the above Magento article. I created a website and gave it a name of “paulsplace.com”. I created a couple of Stores under that website. I then went to System/Configuration/General/Web and, with the scope set to paulsplace.com, I set the unsecured and secured URLs to http://paulsplace.com/ and https://paulsplace.com/ and hit Save Config - what a mistake!!
I got a 404 error. And now I can’t get to my magento front end or back end.
I tried a couple of things:
I added these lines to my hosts lookup file:
127.0.0.1 paulsplace.com
127.0.0.1 www.paulsplace.com
I then uncommented this line in my httpd,conf file:
Include conf/extra/httpd-hosts.conf
and added the following to the conf/extra/httpd-hosts.conf file:
<VirtualHost *:80>
ServerAdmin me#myemail.com
DocumentRoot "C:/Applications/Apache Software Foundation/Apache2.2/htdocs"
ServerName paulsplace.com
ErrorLog "logs/paulsplace.com-error.log"
CustomLog "logs/paulsplace.com-access.log" common
</VirtualHost>
and restarted Apache.
If I browse to “http://www.paulsplace.com” I now get a page that just says “It works!”. Same for “http://paulsplace.com” and “http://www.paulsplace.com/magento/index.php”.
I tried a few more things - I added this line to httpd.conf:
AccessFileName htaccess
(I did this because Windows Explorer didn’t let me create a file starting with a dot; I could do it from the command prompt, but I believe what I have done should be ok).
I changed AllowOverride to All from None:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
<Directory "C:/Applications/Apache Software Foundation/Apache2.2/htdocs">
AllowOverride All
</Directory>
and in C:\Applications\Apache Software Foundation\Apache2.2\htdocs\htaccess (a file that I created), I entered:
SetEnvIf Host www\.paulsplace\.com MAGE_RUN_CODE=pws1
SetEnvIf Host www\.paulsplace\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^paulsplace\.com MAGE_RUN_CODE=pws1
SetEnvIf Host ^paulsplace\.com MAGE_RUN_TYPE=website
(pws was the value I used for the “Code” when creating my store).
Please tell me how I can put this right. I feel like I’m taking one step forward and three backward at the moment.
Any help really would be greatly appreciated.
<VirtualHost *:80>
ServerAdmin me#myemail.com
DocumentRoot "Change this to point at your magento install"
ServerName paulsplace.com
ErrorLog "logs/paulsplace.com-error.log"
CustomLog "logs/paulsplace.com-access.log" common
SetEnv MAGE_RUN_TYPE website
SetEnv MAGE_RUN_CODE pws1
</VirtualHost>
If changing anything in System Configuration borks your system, you can always clear out the bad values in the database directly, and clear your Magento cache. Do a
select * from core_config_data where value LIKE '%paulsplace.com%'
This will give you the two rows that were added when you clicked save. Remove the rows. Next, clear out all the files in
var/cache/*
to clear your cache. Then restore your Apache config to what it was before you started monkeying around. This should restore your site back to its previous state, and you can continue to experiment with things.