Apache VirtualHost Loading the Wrong Page - apache

Problems
An Apache VirtualHost keeps loading the wrong directory when I'm telling it to load a completely different part. Here is what I have for the VirtualHost:
<VirtualHost *:80>
DocumentRoot "/Workspace/Font"
ServerName fonts.wrks.tk
# ErrorLog "/Logs/Workarea/Fonts/Error.log"
# CustomLog "/Logs/Workarea/Fonts/Access.log" common
<Directory "/Workspace/Font">
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
So, the problem, I'm telling it to load /Workspace/Font But it's not, it's loading /Workspace instead. I'm not sure how this came to be.
Attempt at Solution
There's not much I could do considering that the search on Google gave me no relevant results on what I was trying to fix. But regardless, here is some things I did myself to try and fix it.
Restarted Apache Multiple times
Changed permissions around:
sudo chown -R daemon:daemon /Workspace/Fonts (I run XAMPP, and the user and group is daemon)
Checked Error Logs (Nothing Relevant to the problem was printed)
Created a index folder and/or tried to access folder and files within the domain.

It turns out I didn't have the VirtualHosts line uncommented, thanks for anyone that helped in the past. But everything works now.

Related

XAMPP Virtual Host wildcard subdomains on Mac

I want to set up my virtual hosts in a way so that I don't have my projects in the htdocs folder and I would like to use subdomains to get to them. So for example instead of going to "http://localhost/myproject" which would be located inside "/xampp/htdocs/myproject", I'd rather like to go to "http://myproject.sites.local" which would be located inside "/Users/myname/Projects/myproject".
I know I have to go to httpd.conf inside the "etc" folder in xampp and uncomment the line that includes virtual hosts, done that. Then I went to "/etc/hosts" file to add "127.0.0.1 sites.local" and after that I have this chunk of code inside my httpd-vhosts.conf file:
<Directory "/Users/marioplantosar/Projects">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/marioplantosar/Projects"
UseCanonicalName Off
</Virtualhost>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/marioplantosar/Projects/%1"
ServerName sites.local
ServerAlias *.sites.local
UseCanonicalName Off
</Virtualhost>
The first part works I guess because if I visit "http://sites.local" it opens the Projects folder root (it just lists the subfolders because there is no index file inside of the "Projects" folder. But the other part is not working and it just throws the "ERR_NAME_NOT_RESOLVED" error. So I have the wildcard "*" in the ServerAlias so that it catches every subdomain of sites.local, and I use the "%1" to open the corresponding folder inside "Projects" folder, however it's just not working. The weirdest part is that it worked for months up until yesterday and I have no idea what happened that it just suddenly stopped working.
I figured out the problem. Everything I wrote in the question was configured correctly, but since I was doing all of that little over a year ago I totally forgot about the dnsmasq part which somehow got messed up. "hosts" file doesn't support wildcards so you have to use a tool like dnsmasq that does the dns masking automatically for every folder inside my "Projects" folder.
For anyone that gets into a similar situation like me, you configured everything in httpd-vhosts.conf, httpd.conf and hosts files correctly but it's not working you should follow this tutorial to set up the dnsmasq: https://passingcuriosity.com/2013/dnsmasq-dev-osx/

Local website not working

I'm having a lot of trouble setting up a local website that I need to do some work on.
I have 2 local sites: "first_training" and "resus_skills"
The former, first_training, works. I have it set up that first_training.loc/ takes me to the local site. resus_skills is set up in the exact same way, but when I try to access resus_skills.loc/ all I get is:
Here are the details of my setup, as well as some screenshots of it:
/etc/apache2/sites-available/resus_skills.conf :
<VirtualHost *:80>
ServerName resus_skills.loc
ServerAlias www.resus_skills.loc
DocumentRoot "/var/www/resus_skills"
<Directory "/var/www/resus_skills">
Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I made sure to enable it with sudo a2ensite resus_skills.conf and have confirmed that it's symlink is present in ``/etc/apache2/sites-enabled`
I've made sure my apache server is running:
and I've run apachectl -S to get this result:
I am able to reach first_training.loc/ with no issues, but cannot reach resus_skills.loc/.
I'm unsure how to troubleshoot this - the apache error.log isn't showing me anything.
Before anyone points out what an idiot I've been - I never updated the /etc/hosts file, which was the only missing step.

Xampp keeps redirecting to dashboard

I am trying to set up local dev environment with virtual host, using XAMPP, on my new work laptop - running Windows 10.
I have exactly the same set up as on my Surface Pro where it works, but each time I try to access local, I get redirected to the dashboard.
In the hosts file I have added:
127.0.0.1 local.testing.co.uk
In httpd-vhosts.conf I have added:
<VirtualHost *:80>
DocumentRoot "C:/www/testing-co-uk/web"
ServerName local.testing.co.uk
<Directory />
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
In httpd.conf, I have amended the DocumentRoot and Directory as follows:
DocumentRoot "C:/www"
<Directory "C:/www">
My testing-co-uk folder is in C:/www
If I go to local.testing.co.uk, I get redirected to local.testing.co.uk/dashboard.
If I go to localhost, I also get redirected to local.testing.co.uk/dashboard.
If I go to localhost/index.php, I do get to the front page of site I want, however clicking on a link will take me to local.testing.co.uk/linkname (and a 404 error).
Can anyone kindly suggest what could be going wrong? I have been going slowly insane for about 10 hours now. I have checked various other posts within Stack Overflow and tried various solutions, and of course, restarted Xampp every time.
Any help would be really appreciated.
Kind regards
James

How do I access the parent directory of public_html in Apache?

I remember reading a while ago how it's possible for someone to access your computers filesystem from the website. I want to know how to do it, so I can test and prevent it from happening.
Running Apache 2.4 on Windows via XAMPP
My virtualhost is set up like so:
<VirtualHost *:80>
ServerName local.scrap
DocumentRoot "D:/Dropbox/www/scrap/public_html/"
<Directory "D:/Dropbox/www/scrap/">
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog "D:/Dropbox/www/scrap/logs/error.log"
</VirtualHost>
There is an index2.html in scrap/ and index.html in scrap/public_html/
hosts is set up to be 127.0.0.1 local.scrap
If I type the URL http://local.scrap/ I get index.html.
If I type the URL http://local.scrap/../index2.html it gets redirected to http://local.scrap/index2.html
Why is the ../ URL getting redirected to the DocumentRoot path?
Often times a non-malicious user-agent will resolve ../ in the URL before it ever contacts the server. But even without that, webservers are designe to not allow that kind of directory traversal outside of context roots.
You'd need to test with telnet/netcat/s_client to be sure.
If there's a directory traversal or LFI vulnerability in the website application code then this might indeed be possible.
Also, some webservers have directory traversal vulnerabilities. However, the current version of Apache has no known weaknesses in this respect.

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.