Reading magento 1.9x htaccess file - magento-1.9

I've downloaded and installed Magento 1.9.x together with sample data on my Mac.
I've added an entry to my hosts file as follows:
127.0.0.1 local.magento.test
And in httpd-vhosts.conf I have the path to the web root set:
DocumentRoot "/Library/WebServer/Documents/vhosts/magento.test/httpdocs"
ServerName local.magento.test
I'm getting a 403 saying
Server unable to read htaccess file, denying access to be safe
If I look in the apache error log it seems that it is trying to read the .htaccess file from the magento.test directory, not httpdocs
Permission denied: ... /Library/WebServer/Documents/vhosts/magento.test/.htaccess
Any ideas or suggestions much appreciated

OK, problem solved. I needed to add the following to my virtual hosts entry:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>

Related

How to solve XAMPP PHPMyAdmin 403 Forbidden Error

I am using Apache/2.4.41 (Win64) OpenSSL/1.0.2s PHP/7.1.32 my phpmyadmin is suddenly not accessible its shows following error:
Access forbidden! You don't have permission to access the requested
directory. There is either no index document or the directory is
read-protected.
If you think this is a server error, please contact the webmaster.
I had tried everything but still not able to get it right
I had some error like this once, I just edit the httpd-xampp.conf from Require local to Require all granted in the LocationMatch tag. Or configure the http-vhosts.conf Directory tag to
<Directory>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride none
Require all granted
</Directory>
I hope it helps you!
Go to below file
C:\xampp\apache\conf\extra\httpd-xampp.conf
Then go to Directory tag as below:
<Directory "C:/xampp/phpMyAdmin">
and then in the Directory tag change as below:
From
Require local
To
Require all granted
Restart the Xampp
That's it!

Redirect HTML "/" to subfolder of WWW directory, the VirtualHost DocumentRoot

Sorry for asking this question again. Even though this has been asked and discussed quite a bit I cannot seem to find the right solution for a local dev environment using VirtualHost. I am using XAMPP Portable for Windows for dev work but assume this is the same for any other local server with regards to the .htaccess file.
DocumentRoot of VirtualHost is D:\dev\www\ for example.
ServerName is devwork.webdev for example.
HOSTS entry is 127.0.0.1 devwork.webdev.
VirtualHost file does have a default DocumentRoot being DocumentRoot "D:/xampp/htdocs". It works just fine.
The projects are each in a folder under D:\dev\www\ for example D:\dev\www\project01\ or D:\dev\www\project02\ and so on and show nicely in the browser when going to devwork.webdev with Options Indexes FollowSymLinks enabled. Apache is not showing any error and the access log file is also OK, things are working.
Now in my HTML when I use Project 01 a click on the link does link me to D:\dev\www\ showing all the projects I have in that folder.
Instead I would like to be linked to the root of the project, being D:\dev\www\project01\ or rather http://devwork.webdev/project01/.
How can I get that to work?
I am looking for a solution to this so that I can do dev work locally and without changing the HTML later FTP the data to the live host's root and it will work.
I have read and tried the following:
http://coolestguidesontheplanet.com/redirecting-a-web-folder-directory-to-another-in-htaccess/
https://perishablepress.com/redirect-subdirectory-to-root-via-htaccess/ .htaccess How to redirect root URL to subdirectory files, rewrite to clean URL AND not affect subdomains?
http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/
https://stackoverflow.com/a/990405/1010918
How to redirect /directory/index.html and /directory/index.php to /directory/
Redirecting /directory/index.html to /directory/
with
How to remove .html from URL
and
http://forums.modx.com/thread/77211/endless-friendly-url-redirect-from-subdomain-folder-location
being closest to what I think I need but I must be doing something wrong since I always arrive at the DocumentRoot instead of the folder where the project is kept under the DocumentRoot.
Thank you for any help.
This seems closest:
Add VirtualHost definition for each project you want to access. (I'm
not sure how to do it on XAMPP for Windows).
For example, project01.devwork.webdev...
Set DocumentRoot for this VirtualHost to D:\dev\www\project01...
Add the hostname to your /etc/hosts/ file.
Open http://project01.devwork.webdev/ in your browser.
You should see the application in D:\dev\www\project01, while all URLs
will be based on "/".
What happens in the background:
When you open the URL http://project01.devwork.webdev/ in your browser, it will (as usual) translate it to IP address, but along with the request, it will also send Host header with the entered hostname:
GET / HTTP/1.1
Host: project01.devwork.webdev
Based on the Host field, Apache will decide which VirtualHost it needs to "pretend" to be, and serve files from the respective direcory.
However, if you need to have index of the projects, you will have to create it manually with full URLs.
An alternative with the given logic would be to simply add a VirtualHost for each project in D:dev\www\projectname by giving it its own domain instead of a subdomain on the host.
There is little difference there now when already editing httpd-vhosts.conf (using XAMP this file is in InstallDir and then in apache\conf\extra )but ideally it makes copying the local HTML to the live server without changing the HTML possible.
So this is something devs doing local work should keep in mind. I certainly will!! Thank you for your help and information.
<VirtualHost *:80>
DocumentRoot "D:/dev/www/newprojectname"
ServerName newdomainname.webdev
ServerAlias www.newdomainname.webdev
ErrorLog "D:/dev/www/log/dev-apache.error.log"
CustomLog "D:/dev/www/log/dev-apache.access.log" common
<Directory "D:/dev/www/newprojectname">
AllowOverride All
Options Indexes FollowSymLinks
Require local
# more detailed local
# Require ip 192.168.188
# or the IP from your local network
</Directory>
</VirtualHost>

phpMyAdmin issue file not found

Getting this error "The requested URL /phpMyAdmin/db_structure.php was not found on this server." when clicks on the any of the database from the left bar.
I am using phpMyAdmin from MAMP pro. I tried reinstalling whole MAMP pro but still facing the same problem.
Any Help would be appreciated.
Check that your Apache config (httpd.conf) looks like something like that :
Alias /phpMyAdmin "[Your path to phpmyadmin]"
<Directory "[Your path to phpmyadmin]">
AllowOverride All
Options FollowSymlinks
Order allow,deny
Allow from all
</Directory>
Note that you may want to be more restrictive about the allow/deny config.
I solved this problem by reinstalling MAMP pro.

Apache hangs with Django Application and Matplotlib

Very stuck here and I don't have a whole lot to go on. I had a django application up and running and I started playing around with graphing using NetworkX and Matplotlib to visualize some of the data for a poster. I then tried to use the site again and got the error:
'/var/www' is not a writable dir; you must set /var/www/.matplotlib to be a writable dir. You can also set environment variable MPLCONFIGDIR to any writable directory where you want matplotlib data stored
Which I resolved by chmod'ding the directory. The site's homepage then loads fine but when I try to load any other page that django renders apache just hangs. I set the log level to debug and tail'ed it but it's not showing any new requests or errors or anything, it just sorta hangs until the browser gives up. I then thought it must just be an error with something that I just did so I reverted back to a working version in my repo and am having the same problem. Django's test server is still running the site fine which is leading me to believe that it's a problem with apache (of the whole thing apache is the part I have the least experience with).
my httpd.conf looks like:
ServerName >> my server <<
TraceEnable off
AcceptFilter http none
AcceptFilter https none
EnableMMAP off
EnableSendfile off
<VirtualHost *:80>
ServerAdmin >> my email <<
ServerName >> my server <<
DocumentRoot /Web/public/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
WSGIScriptAlias / /home/$USER/$APP/$APP/wsgi.py
<Directory /Web/public/static>
Options -Indexes
</Directory>
Alias /static /Web/public/static
Alias /media /Web/public/media
ErrorLog /var/log/apache2/error.log
LogLevel debug
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Please let me know if you have any thoughts, or need any more info.
Thanks!
I had the same problem; Apache/Django would not work but manage.py runserver would work fine. I tried making the default directory readable, and I tried changing MPLCONFIGDIR with export MPLCONFIGDIR=/stuff/, but the only thing that worked was placing
import os
os.environ[ 'MPLCONFIGDIR' ] = '/tmp/'
BEFORE importing matplotlib. Only one page uses MPL in my case, so placing this 'everywhere' was acceptable to me.
Taken from original solution by steko.

Apache giving 403 forbidden errors

Ok, so i've previously set up two virtual hosts and they are working cool. they both house simple web projects and work fine with http://project1 and http://project2 in the browser.
Anyway, I've come to add another vhost. I edited the /etc/hosts file with 127.0.0.1 project3 and also updated the httpd-vhosts.conf file by copy and pasting the previous entries for project2 and editing the file path.
I've checked all the file and folder permissions (in fact I copied and pasted from project2) and simply put a "hello world" message in the index.php file.
I get a 403 forbidden permission denied message when accessing http://project3
Why is this, I just can figure out what step I've missed as everything seems to be set up correct.
Check that :
Apache can physically access the file (the user that run apache, probably www-data or apache, can access the file in the filesystem)
Apache can list the content of the folder (read permission)
Apache has a "Allow" directive for that folder. There should be one for /var/www/, you can check default vhost for example.
Additionally, you can look at the error.log file (usually located at /var/log/apache2/error.log) which will describe why you get the 403 error exactly.
Finally, you may want to restart apache, just to be sure all that configuration is applied.
This can be generally done with /etc/init.d/apache2 restart. On some system, the script will be called httpd. Just figure out.
I just fixed this issue after struggling for a few days. Here's what worked for me:
First, check your Apache error_log file and look at the most recent error message.
If it says something like:
access to /mySite denied (filesystem path
'/Users/myusername/Sites/mySite') because search permissions
are missing on a component of the path
then there is a problem with your file permissions. You can fix them by running these commands from the terminal:
$ cd /Users/myusername/Sites/mySite
$ find . -type f -exec chmod 644 {} \;
$ find . -type d -exec chmod 755 {} \;
Then, refresh the URL where your website should be (such as http://localhost/mySite).
If you're still getting a 403 error, and if your Apache error_log still says the same thing, then progressively move up your directory tree, adjusting the directory permissions as you go. You can do this from the terminal by:
$ cd ..
$ chmod 755 mySite
If necessary, continue with:
$ cd ..
$ chmod Sites
and, if necessary,
$ cd ..
$ chmod myusername
DO NOT go up farther than that. You could royally mess up your system.
If you still get the error that says search permissions are missing on a component of the path, I don't know what you should do. However, I encountered a different error (the one below) which I fixed as follows:
If your error_log says something like:
client denied by server configuration:
/Users/myusername/Sites/mySite
then your problem is not with your file permissions, but instead with your Apache configuration.
Notice that in your httpd.conf file, you will see a default configuration like this (Apache 2.4+):
<Directory />
AllowOverride none
Require all denied
</Directory>
or like this (Apache 2.2):
<Directory />
Order deny,allow
Deny from all
</Directory>
DO NOT change this! We will not override these permissions globally, but instead in your httpd-vhosts.conf file.
First, however, make sure that your vhost Include line in httpd.conf is uncommented. It should look like this. (Your exact path may be different.)
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
Now, open the httpd-vhosts.conf file that you just Included. Add an entry for your webpage if you don't already have one. It should look something like this. The DocumentRoot and Directory paths should be identical, and should point to wherever your index.html or index.php file is located. For me, that's within the public subdirectory.
For Apache 2.2:
<VirtualHost *:80>
# ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "/Users/myusername/Sites/mySite/public"
ServerName mysite
# ErrorLog "logs/dummy-host2.example.com-error_log"
# CustomLog "logs/dummy-host2.example.com-access_log" common
<Directory "/Users/myusername/Sites/mySite/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
The lines saying
AllowOverride All
Require all granted
are critical for Apache 2.4+. Without these, you will not be overriding the default Apache settings specified in httpd.conf. Note that if you are using Apache 2.2, these lines should instead say
Order allow,deny
Allow from all
This change has been a major source of confusion for googlers of this problem, such as I, because copy-pasting these Apache 2.2 lines will not work in Apache 2.4+, and the Apache 2.2 lines are still commonly found on older help threads.
Once you have saved your changes, restart Apache. The command for this will depend on your OS and installation, so google that separately if you need help with it.
I hope this helps someone else!
PS: If you are having trouble finding these .conf files, try running the find command, such as:
$ find / -name httpd.conf
restorecon command works as below :
restorecon -v -R /var/www/html/
Notice that another issue that might be causing this is that, the "FollowSymLinks" option of a parent directory might have been mistakenly overwritten by the options of your project's directory. This was the case for me and made me pull my hair until I found out the cause!
Here's an example of such a mistake:
<Directory />
Options FollowSymLinks
AllowOverride all
Require all denied
</Directory>
<Directory /var/www/>
Options Indexes # <--- NOT OK! It's overwriting the above option of the "/" directory.
AllowOverride all
Require all granted
</Directory>
So now if you check the Apache's log message(tail -n 50 -f /var/www/html/{the_error_log_file_of_your_site}) you'll see such an error:
Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive
is also forbidden due to its similar ability to circumvent directory restrictions
That's because Indexes in the above rules for /var/www directory is overwriting the FolowSymLinks of the / directory. So now that you know the cause, in order to fix it, you can do many things depending on your need. For instance:
<Directory />
Options FollowSymLinks
AllowOverride all
Require all denied
</Directory>
<Directory /var/www/>
Options FollowSymLinks Indexes # <--- OK.
AllowOverride all
Require all granted
</Directory>
Or even this:
<Directory />
Options FollowSymLinks
AllowOverride all
Require all denied
</Directory>
<Directory /var/www/>
Options -Indexes # <--- OK as well! It will NOT cause an overwrite.
AllowOverride all
Require all granted
</Directory>
The example above will not cause the overwrite issue, because in Apache, if an option is "+" it will overwrite the "+"s only, and if it's a "-", it will overwrite the "-"s... (Don't ask me for a reference on that though, it's just my interpretation of an Apache's error message(checked through journalctl -xe) which says: Either all Options must start with + or -, or no Option may. when an option has a sign, but another one doesn't(E.g., FollowSymLinks -Indexes). So it's my personal conclusion -thus should be taken with a grain of salt- that if I've used -Indexes as the option, that will be considered as a whole distinct set of options by the Apache from the other option in the "/" which doesn't have any signs on it, and so no annoying rewrites will occur in the end, which I could successfully confirm by the above rules in a project directory of my own).
Hope that this will help you pull much less of your hair! :)
it doesn't, however, solve the problem, because on e.g. open SUSE Tumbleweed, custom source build is triggering the same 401 error on default web page, which is configured accordingly with Indexes and
Require all granted
The server may need read permission for your home directory and .htaccess therein
You can try disabling selinux and try once again using the following command
setenforce 0
In my case it was failing as the IP of my source server was not whitelisted in the target server.
For e.g. I was trying to access https://prodcat.ref.test.co.uk from application running on my source server.
On source server find IP by ifconfig
This IP should be whitelisted in the target Server's apache config file. If its not then get it whitelist.
Steps to add a IP for whitelisting (if you control the target server as well)
ssh to the apache server
sudo su -
cd /usr/local/apache/conf/extra (actual directories can be different based on your config)
Find the config file for the target application for e.g. prodcat-443.conf
RewriteCond %{REMOTE_ADDR} <YOUR Server's IP>
for e.g.
RewriteCond %{REMOTE_ADDR} !^192\.68\.2\.98
Hope this helps someone
Add
<Directory "/path/to/webroot">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow, deny
Allow from all
Require all granted
</Directory>
What this does is tell Apache2 to override any previous configs, and allow (200) from all before denying. (403) It also requires all requests to be granted. This code will have to go in every vhost file, but it does work. I have been using this for over a year.
to your config file (e.g. /etc/apache2/sites-enabled/000-default.conf)
Tested LAMP stack Debian 11