0

I am using the standard Apple-provided installations of PHP 5.3 and Apache 2 to do web development on a Mac Pro that I just upgraded to Mac OS X 10.6 (Snow Leopard). The upgrade went well enough, if I ignore the fact that it destroyed my ability to get work done. ;)

After the update, the CakePHP application I was developing started giving me 403 Forbidden errors when accessed. Based on the errors in the log file, I've determined that Apache is choking on the mod_rewrite rules in Cake's .htaccess file. Here's the file, in its entirety:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

It's not that the rules themselves are wrong, but that Apache is forbidding the use of mod_rewrite altogether. All other pages on the machine work fine, and the 403 errors go away if I comment out the .htaccess file (but nothing works, of course).

In my httpd.conf file, I've tried changing this:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

To this:

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>

...which has no effect.

I don't know much about Apache configuration files, and I'm quite stuck on this. In fact, I know little enough that I'm not sure which information about my setup is needed to enable people to provide useful answers. I'm just using the vanilla OS X setup, nothing fancy.

Googling has yielded no fruits for me this time, so I'm turning to you. Any ideas?

6 Answers 6

4

How about the ownership/permissions of the files your pointing to? I'm more inclined to think Apache can't get to them rather than it being Apache at this point.

Edit with solution: Put Options +FollowSymLinks above RewriteEngine On

5
  • I probably should have mentioned this in the question, but that's the first thing I tried. The error logs point to mod_rewrite, and when mod_rewrite isn't used, the error goes away... Oct 1, 2009 at 5:00
  • How about selectively commenting rewrite rules? Does one or the other stop it?
    – Xorlev
    Oct 1, 2009 at 5:08
  • Commenting out both rules does not stop the error. Commenting out the "RewriteEngine On" line does. Oct 1, 2009 at 5:13
  • 3
    Try putting Options +FollowSymLinks Above RewriteEngine On. I know you have it in Directory, but it -may- help.
    – Xorlev
    Oct 1, 2009 at 6:19
  • It makes absolutely no sense, but it worked, so I'll take it. Thanks! Oct 1, 2009 at 6:47
3

Adding FollowSymlinks to the htaccess didn't work for me so I googled a bit a found another solution

It turns out there is another Directory block in /etc/apache2/users/.conf in which you need to add FollowSymlinks to Options and change AllowOverride to All

<Directory "/Users/<your user>/Sites/">
    Options Indexes MultiViews FollowSymlinks
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>

Restart apache and htaccess files and rewrite conditions should now work.

1

Ok, this is my solution distelled from the comments on this page:

Configuration:

  • Mac OS X 10.6.6
  • CakePHP 1.3.7

Solution: A combination of Matthieu Sadouni and Jason Strack, so:

Change /private/etc/apache2/users/{user}.conf to:

<Directory "/Users/{user}/Sites/">
    Options Indexes MultiViews FollowSymlinks
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>

And change the Cake root .htaccess file to:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /~{user}/cake_1_3/
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

(Where {user} is your username and cake_1_3 is your cake directory)

UPDATE: Yes, I am new to Cake, so I started with the 15 minutes blog tutorial. That's how I found out you have to edit 2 other .htaccess files as well:

  • cake_1_3/app/.htaccess
  • cake_1_3/app/webroot/.htaccess

After RewriteEngine on add the line RewriteBase /~{user}/cake_1_3/ here as well.

0

Just for the record and in response to @Matthie Sadouni

I’m using Snow Leopard (OS X 10.6) and the location of my {user}.conf file is somewhere else than he described.

“/private/etc/apache2/users/{user}.conf”

(Replace {user} with your Mac username)

0

I had QUITE a problem with this. If you are using Leopard or greater, you'll probably have issues w/ the mod_rewrite.

When your files are put into http://localhost/~username/cake, you don't see styling. Here is the way to fix that.

Firstly, open httpd.conf. (I use nano. Just make sure that whatever you use can save a system file.) Make sure that there is no hash in front of the mod_rewrite component. Then scroll down to the section. Set AllowOverride None to AllowOverride All. (On Snow Leopard Only) Navigate to apache2/users/.conf. Edit this file so that the lines read: Options Indexes MultiViews FollowSymLinks Allow Override All. Now, save and restart apache (sudo apachectl restart). Here comes the tricky part. If you navigate to your site, it should give you a warning about a directory not being found. Now, you have to edit your .htaccess files. Start in your main directory. right under RewriteEngine On, Add the following line "RewriteBase /~//" Do this for the root folder, the app folder and the webroot folder, making sure to include them in each .htaccess file. Of grave importance is that you make sure to add the ending forward slash. It's important. I hope that helps! Good Luck. G*d knows you'll need it.

0

I had to use "RewriteBase /~username//" if it was in my home sites directory and I had to use "RewriteBase /~username/cakePHP//" when I put it in a subfolder of my home web directory.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .