Apache doesn't seem to be detecting my .htaccess file - php

I'm running an Apache server on my computer through MAMP, and I can't seem to get it to read my .htaccess file. All of the solutions I've looked at have said to make sure that my AllowOverride is set to All in httpd.conf, which it is, but this doesn't seem to resolve my issue. I know that .htaccess isn't being read since I've written some nonsense at the start of the file and no error is being produced. I have also restarted the Apache servers after changing httpd.conf. Maybe the problem is that I'm not completely sure where I'm supposed to place the .htaccess file.
My MAMP document root was formerly MAMP > htdocs, but I changed it to Library > WebServer > Documents, which is where all of my PHP files are located. The current project I'm working on is a subdirectory of this, say Library > WebServer > Documents > project. This is the folder that contains my .htaccess file. My httpd.conf file is in MAMP > conf > apache, and the relevant section of it is as follows:
# First, we configure the "default" to be a very restrictive set of
# features.
#
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
Do I need to change the directory from / to something else to get this working? Any help is really appreciated.
Edit: I added the following <VirtualHost> block to my httpd.conf following the comments below, but again, nothing seems to change:
<VirtualHost *:80>
ServerAdmin email#site.com
ServerName localhost:8890
DocumentRoot /
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Update (Solved): I was able to resolve the issue by reverting MAMP's DocumentRoot to its original MAMP > htdocs as opposed to my Library > WebServer > Documents. Apache is now reading the .htaccess file located in my MAMP > htdocs > project. Thanks everyone for the help.

First I would try to fix my VirtualHost to use the correct paths. I'm not super familiar with Mac, but if Library > WebServer > Documents > project corresponds to /Library/WebServer/Documents/project in your file system, then I would use that. Might be /home/your_username/Library/WebServer/Documents/project but as I said, I'm not a Mac guy. Next, I don't understand why you have directives for the same directory with opposite permissions, so I would try to remove the first Directory block or change the targetted directory to something else on one of the blocks. Note that you should never grant access to / with apache as it would be a very big security breach.
<VirtualHost *:80>
ServerAdmin email#site.com
ServerName localhost:8890
DocumentRoot /Library/WebServer/Documents/project
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory /Library/WebServer/Documents/project>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
If it still doesn't work, you might want to make sure that the filename Apache is looking for hasn't been changed to something else using the AccessFileName directive.
Also, you are not giving details on where you put the VirtualHost block, but if it is in a separate file. Make sure you are including that file somehow.
You don't specify your Apache version but since version 2.4, you should Require instead of Allow directives since this is deprecated. See https://httpd.apache.org/docs/2.4/en/howto/access.html

Try adding Listen 80 and Listen 443 to the top of the main config.

Check your httpd.conf. Via the AllowOverride (http://httpd.apache.org/docs/current/mod/core.html#allowoverride) and AllowOverrideList (http://httpd.apache.org/docs/current/mod/core.html#allowoverridelist) directives it can control whether or not .htaccess files are considered.
When this directive (i.e. AllowOverride) is set to None and AllowOverrideList is set to None, .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem.
Please note that the default value is None for both, which cause exactly this behavior of not considering .htaccess files.

Related

Laravel: no joy after MAMP upgrade from 3.4 to 4.1

As I am suffering a weird redirect problem and I read MAMP could be the cause I decided to upgrade it.
I have my virtual hosts set and they are enabled in the conf.
I set correct ports and set PHP version to 5.6.31 (it was 5.6.10).
What happens when I start the servers is I can open the welcome screen of the laravel project (project.dev) but then the routes don't work with error 404. Example project.dev/home or project.dev/login etc.
Any clue?
--- edit
I added this to my vhost and now it's working. Not sure if all the stuff there is needed as I just copied from the web. Strangely I didn't have anything of this in the past and it worked. Could it be apache was configured to allow mod_rewrite or something?
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
In your httpd.conf file set AllowOverride directive from None to All, for example:
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
The default in Apache 2.3.9 and later is None, previous versions is was All. From the online docs:
When this directive is set to None and AllowOverrideList is set to
None, .htaccess files are completely ignored. In this case, the server
will not even attempt to read .htaccess files in the filesystem.
When this directive is set to All, then any directive which has the
.htaccess Context is allowed in .htaccess files.

.Htaccess file not working, does this have anything to do with AllowOverride?

I have a local installation of XAMPP, whatever directives I put inside .htaccess it does not affect anything, then in Apache Server Config file I found AllowOverride none. Do you think AllowOverride none is the reason that changes made in .htaccess are not taking any effect? Also same .htaccess file works fine on a web hosting I am using.
Yes. AllowOverride controls what can be done in an .htaccess file. See the documentation for the AllowOverride directive.
In a default XAMPP out of the box installation the httpd.conf file here: /xampp/apache/conf/httpd.conf has this code in it, which I have never changed and everything works fine, but I am using a vhost configuration. vhost is a much better way to handle multiple XAMPP development sites since you can change your configuration per site instead of affecting all XAMPP dev sites. The vhost conf file is here: /xampp/apache/conf/extra/httpd-vhosts.conf. I posted a simple example below. the httpd-vhosts.conf file also has examples in it. It seems like a difficult thing to setup/configure, but it is not. Like I said this is the best way to setup multiple dev sites. This looks like a decent vhost setup tutorial: http://austin.passy.co/2012/setting-up-virtual-hosts-wordpress-multisite-with-xampp-on-windows-7/
# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition. These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
AllowOverride none
Require all denied
</Directory>
Vhost config example:
## AITpro Main site
<VirtualHost aitpro-main.local:80>
ServerAdmin postmaster#localhost
DocumentRoot "C:/xampp/htdocs1/aitpro-main"
ServerName aitpro-main.local
ServerAlias aitpro-main.local
<Directory "C:/xampp/htdocs1/aitpro-main">
#Options Indexes FollowSymLinks Includes ExecCGI
Options All
AllowOverride All
Require all granted
#Order allow,deny
#Allow from all
</Directory>
</VirtualHost>

apache url rewrite connection reset on root directory

in my apache sites-available/default file i had change the config to folowing:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All //originally was AllowOverride None
FallbackResource rewrite.php //i added this line, too
Order allow,deny
allow from all
</Directory>
i wanted to handle all url calls in my own rewrite.php file. this works, when i visit my site at http://192.168.1.104:4567/web/knxzkcha but doesnt work when i go for http://192.168.1.104:4567/web/. i got this problem in firefox : The connection to the server was reset while the page was loading.
the index site http://192.168.1.104:4567/web/index.php works flawlessly and shows me my index.php file. all i want is to let me show the index file when visiting the root directory, too. /var/www points to the /web directory. i have some ubuntu 12.04 server 64 LTS edition
when i rewert the config lines, the root gives me the index file by default.
You do not need to add AllowOverride All, telling apache to avoid IO by checking existence of .htaccess files in current directory and all parents directories with AllowOverride None is a good recipe for speed. Avoid .htaccess files if you can edit Apache configuration.
Now FallbackResource is a quite new feature and may have some bugs. Did you check the ErrorLog for details? Could you try that with LogLevel debug?
It seems you problems is with directories, maybe you could fix it by enforcing usage of your fallback when a Directory is requested, try to add:
DirectoryIndex rewrite.php

Edit httpd.conf - Require/include no longer works

Running latest Zend Server on Windows 7x64, I was playing around with different ways to sync htdocs into dropbox and edited two lines of httpd.conf.
DocumentRoot "C:\Program Files (x86)\Zend\Apache2/htdocs"
<Directory "C:\Program Files (x86)\Zend\Apache2/htdocs">
with various symlinks, dropbox locations, etc.
Put it back to the way it was and php includes and require no longer work. I know the scripts are fine as the exact same scripts work on my desktop with the exact same development environment.
I put all my usernames/passwords/database names/etc in a php file that is generally stored outside the htdocs directory.
require_once('constants.php');
(In the same dir for purposes of troubleshooting, have tried everything from $_SERVER to dir.
Throws this error:
Warning: require_once(1): failed to open stream: No such file or directory in C:\Program Files (x86)\Zend\Apache2\htdocs\index.php on line 17
Fatal error: require_once(): Failed opening required '1' (include_path='.;C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library') in C:\Program Files (x86)\Zend\Apache2\htdocs\index.php on line 17
Scripts are working fine on another machine with exact same software.
For the purposes of testing scripts, even require_once in same dir doesn't work.
Made a backup of httpd.conf before changing, put it back with no effect.
Copied httpd.conf off healthy machine, no change.
Completely re-installed the entire zend package twice, no change.
At a loss as to what could be causing this. Any ideas?
This is out of the box from the healthy machine, # removed:
DocumentRoot "C:\Program Files (x86)\Zend\Apache2/htdocs"
Each directory to which Apache has access can be configured with respect
to which services and features are allowed and/or disabled in that
directory (and its subdirectories).
First, we configure the "default" to be a very restrictive set of
features.
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
Note that from this point forward you must specifically allow
particular features to be enabled - so if something's not working as
you might expect, make sure that you have specifically enabled it
below.
This should be changed to whatever you set DocumentRoot to.
<Directory "C:\Program Files (x86)\Zend\Apache2/htdocs">
Possible values for the Options directive are "None", "All",
or any combination of:
Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
Note that "MultiViews" must be named *explicitly* --- "Options All"
doesn't give it to you.
The Options directive is both complicated and important. Please see
http://httpd.apache.org/docs/2.2/mod/core.html#options
for more information.
Options Indexes FollowSymLinks
AllowOverride controls what directives may be placed in .htaccess files.
It can be "All", "None", or any combination of the keywords:
Options FileInfo AuthConfig Limit
AllowOverride None
Controls who can get stuff from this server.
Order allow,deny
Allow from all
</Directory>
No quotes are used in Apache config IE:
ServerName yoursite.com
DocumentRoot C:\www\your_site
<Directory C:\www\your_site>
Options FollowSymLinks MultiViews
... rest of stuff
</Directory>
In addition your include may need the absolute path depending on you Apache settings .. IE
require_once('C:\www\your_site\outside_http_docs\constants.php');
Fixed it. Windows permissions requiring file outside the scope of htdocs.

In which directory i should keep my workspace or project

I have installed XAMPP in my machine(Windows XP OS). And I have Eclipse as IDE.
Now my question is, In which directory i should keep my workspace (or project).
Whether I should keep under the path "C:\xampp\php\www" OR under "C:\xampp\htdocs".
You need to change the DocumentRoot value in c:\xampp\apache\conf\httpd.conf from
DocumentRoot "C:\xampp\htdocs"
to
DocumentRoot "E:/MyProject/Source/Admin"
and configure permissions also.
<Directory "E:/MyProject/Source/Admin">
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
and then restart the apache server(in xampp control panel). so from there onwards whenever you access http://localhost/ it will execute the files under E:/MyProject/Source/Admin
see for more info.
http://httpd.apache.org/docs/2.0/mod/core.html#documentroot
http://www.apachefriends.org/en/xampp-windows.html#529
Looking at the Where I change the start page? section of XAMP's FAQ (quoting) :
The DocumentRoot folder is
"\xampp\htdocs". There is the
index site (index.php) the real
start page which is loaded after
executing of "http://localhost/".
So, I'd say, in your case, you'll have to work in C:\xampp\htdocs.
Still, of course, you can change that by modifying Apache's configuration and/or creating new VirtualHosts.

Categories