brad.roush
brad.roush

Reputation: 607

Install and configure mod_rewrite for Apache 2 on Mac OS X for Zend Framework 2

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?

Upvotes: 39

Views: 88180

Answers (8)

Maroun Melhem
Maroun Melhem

Reputation: 4290

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!

Upvotes: 0

Rob Allen
Rob Allen

Reputation: 12778

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.

Upvotes: 159

SM23
SM23

Reputation: 409

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

Upvotes: 3

1nstinct
1nstinct

Reputation: 1775

yosemite os x should be like this:

<VirtualHost *:80>
    ServerAdmin [email protected]
    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

Upvotes: 1

R00We
R00We

Reputation: 1981

My chose

<VirtualHost *:80>
    <Directory />
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
    ServerAdmin [email protected]
    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>

Upvotes: 0

gounane
gounane

Reputation: 381

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

Upvotes: 1

sffc
sffc

Reputation: 6424

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.

Upvotes: 13

Yes Barry
Yes Barry

Reputation: 9876

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.

Upvotes: -1

Related Questions