38

I getting started with zend framework 2 and they have a prerequisite of an installation and configuration of mod_rewrite for apache. Apache 2.2.22 came pre-installed on Mac OS X 10.8.2. Is there an easy way to install and configure mod_rewrite for apache?

The only help I have come across suggests to recompile apache. Is this the only way?

brad.roush
  • 597
  • 1
  • 4
  • 9
  • Does this not work for you? http://serverfault.com/questions/113853/getting-mod-rewrite-working-on-os-x-snow-leopard (first answer, Keith Norman) – Joe T Sep 25 '12 at 22:57
  • 1
    This question is not a programming question and belongs to ServerFault. – Daniel M Sep 26 '12 at 07:14
  • 2
    @DanielM I agree it's not a programming question, but it doesn't belong on ServerFault. In fact, it's hard to say _where_ questions like this belong now. Any time I ask a question on ServerFault like this it either gets ignored or closed...or _both_. Maybe it belongs on "Ask Different?" Who knows.. – Yes Barry Oct 12 '12 at 01:35

8 Answers8

156

To check that mod_rewrite and PHP are enabled, look at /etc/apache2/httpd.conf and ensure that these lines:

LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module        libexec/apache2/libphp5.so

are uncommented.

Also ensure that AllowOverride is set to All within the <Directory "/Library/WebServer/Documents"> section.

After making these changes, restart Apache with: sudo apachectl restart

If you then put your project within the /Library/WebServer/Documents folder, then it should work.

Aleksi Sjöberg
  • 1,454
  • 1
  • 12
  • 34
Rob Allen
  • 12,643
  • 1
  • 40
  • 49
13

If you are serving your site from ~/Sites, the trick for me was modifying my /private/etc/apache2/users/USERNAME.conf file. Initially, the content was:

<Directory "/Users/USERNAME/Sites/">
    Options Indexes MultiViews FollowSymLinks ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Changing AllowOverride to all and then restarting the server with a quick sudo apachectl restart enabled me to start using mod_rewrite in .htaccess files living beneath ~/Sites.

sffc
  • 6,186
  • 3
  • 44
  • 68
  • After changing this setting, I'm getting 403 forbidden and the error is : `Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /Users/xliang/Sites/flight/event` Any ideas? BTW I'm running my site from ~/Sites – Xiao Jul 16 '14 at 20:22
3

In addition to Rob Allen's response, both line numbers are located around 168 and 169 (to save you some time from scrolling the 500+ lines of text). Also, to explain what each line does exactly:

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

This overrides the default settings for any .htaccess files used at the document root

LoadModule php5_module        libexec/apache2/libphp5.so

This allows URL rewrites for permalinks

Source: link

SM23
  • 419
  • 6
  • 12
1

Add this to http-vhosts.conf file

<Directory "/Library/WebServer/Documents">
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

Don't forget to reload your apache using this commande

sudo apachectl restart

Good luck

gounane
  • 381
  • 2
  • 6
1

yosemite os x should be like this:

<VirtualHost *:80>
    ServerAdmin enzo@enzolutions.com
    DocumentRoot "/Users/enzo/www/drupal8"

    ServerName drupal8

    #ServerAlias www.dummy-host.example.com
    <Directory /Users/enzo/www/drupal8>
        Require all granted
        Options Includes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog "/private/var/log/apache2/drupal8-error.log"
    CustomLog "/private/var/log/apache2/drupal8-access.log" common
</VirtualHost>

gotten from this blog post

Potherca
  • 13,207
  • 5
  • 76
  • 94
1nstinct
  • 1,745
  • 1
  • 26
  • 30
0

My chose

<VirtualHost *:80>
    <Directory />
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
    ServerAdmin user@domain.ru
    DocumentRoot "/Users/r00we/sites/buytocoins.ru"
    ServerName site.ru
    ServerAlias www.site.ru
    ErrorLog "/private/var/log/apache2/myfaketestsite.com-error_log"
    CustomLog "/private/var/log/apache2/myfaketestsite.com-access_log" common
</VirtualHost>
R00We
  • 1,931
  • 18
  • 21
0

I know this is an old thread, but this also might raise this issue:

Make sure DocumentRoot and Directory links to the same folder in /etc/apache2/extra/httpd-vhosts.conf as following:

enter image description here

This is an innocent mistake if you copy the virtual host block from existing sites.

Cheers!

Maroun Melhem
  • 3,100
  • 1
  • 20
  • 22
-1

Rob Allen's answer sounds right, but I've never used the default installation of Apache on my Mac so I can't verify. I would recommend either MAMP or Zend Server CE.

It took me a little while to get Zend Server CE configured and running correctly on my Mac, but that was version 4 and it was buggy and either way it was well worth it. Conversely, version 5.6 of ZSCE seems to be much better!

Some notes on Zend Server CE for Mac OS X

If you go with MAMP, it should be a very quick install, aside from configuring virtual hosts.

Note that both of these come with mod_rewrite already installed.

Yes Barry
  • 9,514
  • 5
  • 50
  • 69
  • i havent' had much luck with zend server ce and mac os x lion – b_dubb Oct 18 '12 at 15:23
  • @b_dubb sorry to hear that. what kind of problems have you been had? – Yes Barry Oct 18 '12 at 20:01
  • problems with controller / action uri's not being found. i've set up my vhost and htaccess. i add an Admin controller with the zf.sh tool and get zf error message when i go to my project uri. zf thinks my /~username ... is a controller. blarg – b_dubb Oct 19 '12 at 18:07
  • hmm well I still use snow leopard so I'm not certain, but either way I never used the zf tool stuff, I always did it manually. – Yes Barry Oct 19 '12 at 20:10