1

OK, so I'v installed php5 and apache2 on my OS X using macports. php is running fine from the terminal, as is apache. I've edited my httpd.conf file to add the following:

LoadModule php5_module        modules/libphp5.so
AddType    application/x-httpd-php .php [I have also tried AddHandler here to no avail]
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

Apache will redirect to an index.html file in the local root, but will not redirect to index.php. it just shows the list of files in the directory, and clicking on index.php will just output the contents of the file in plaintext. It's as if my httpd.conf changes aren't even being read. But I've searched and there are no other versions of httpd.conf stored anywhere on my system, bar one file named 'httpd.conf.bak', in my /opt/local/apache2/conf/ folder. Can anyone help?

Leon Aves
  • 171
  • 7
  • Seek serverfault for help. –  Aug 04 '11 at 13:46
  • Restart Apache? If that doesn't work, check your error logs. – Berry Langerak Aug 04 '11 at 13:49
  • In case anyone missed the discussion below, the problem was that I was using virtualhost.sh to set up virtual hosts, which was editing the httpd.conf file for the default version of apache then starting that up. –  Aug 04 '11 at 14:40

2 Answers2

1

Have you restarted apache? Try running sudo /usr/sbin/apachectl graceful? You can also run it as sudo /usr/sbin/apachectl -t to check for errors.

EDIT: Added restart for MacPorts apache installation.

sudo /opt/local/apache2/bin/apachectl

  • Ah it might not be `/usr/sbin/apachectl` for you as I'm using the native apache and php on OS X. –  Aug 04 '11 at 13:51
  • I used restart, not graceful, but yes I've restarted many times. –  Aug 04 '11 at 13:55
  • -t reports no errors. just "syntax OK" –  Aug 04 '11 at 13:56
  • I was aware that OS X had Apache built in but it was my understanding it wasn't installed by default. Could it be that version is running over the macports version I installed? And if so, how do I overwrite it? –  Aug 04 '11 at 13:58
  • Have you turned off Personal Web Sharing under the Sharing System Preferences pane? This could be in conflict with the apache server you just installed. –  Aug 04 '11 at 14:01
  • It's off. I found OS X's built in apache, and it's output: SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf" –  Aug 04 '11 at 14:03
  • Ah, edited my answer. We might be restarting the apachectl for the native apache, added the apachectl for MacPorts installation. –  Aug 04 '11 at 14:04
  • Apache is installed by default and so is PHP (since SnowLeopard it was 5.3 as well). You can enable/disable that by enabling "web sharing" on your sharing preferences. Try disabling that and using your macports version or use the ones from the OS - installed by default. If you want a packages solution [MAMP](http://www.mamp.info/en/index.html) is a good choice too. –  Aug 04 '11 at 14:05
  • Nah I was restarting that version. had added an alias: alias apache2ctl='sudo /opt/local/apache2/bin/apachectl' –  Aug 04 '11 at 14:06
  • Hmmm, have you tried forcing it to read from the config file you edited, adding this `-f /opt/local/apache2/conf/httpd.conf` –  Aug 04 '11 at 14:11
  • I want to use the version of Apache and PHP I got from macports, apparently the libraries in the OS X version aren't as extensive. Web Sharing is off. I'm pretty sure it is using the default version because when i go to /usr/sbin and run apachectl stop, then refresh, it uses the other version. I can tell because i had virtualhosts set up, and obviously it was doing that for the running version of apache. –  Aug 04 '11 at 14:15
  • OK, any idea how I can get [virtualhost.sh](http://code.google.com/p/virtualhost-sh/) to work with a custom install of apache? –  Aug 04 '11 at 14:19
  • Ah, can you run `sudo /usr/sbin/apachectl stop` then run `sudo /opt/local/apache2/bin/apachectl graceful`? Your other option is to set the port for the default apache to any number that is not used by other clients to make it sure it's not the apache handling your browser requests. –  Aug 04 '11 at 14:19
  • 1
    You just need to open virtualhost.sh and change the following constants `APACHE_CONFIG="/private/etc/apache2" APACHECTL="/usr/sbin/apachectl"` to the new paths for your MacPorts apache. I think `/private/etc/apache2` to `/opt/local/apache2/conf/` and `/usr/sbin/apachectl` to `/opt/local/apache2/bin/apachectl`. –  Aug 04 '11 at 14:24
  • Thank you! Didn't even consider editing the shell file, thought it would have an option somewhere. Thank you thank you thank you! –  Aug 04 '11 at 14:30
0

It looks like the php is not being read. I had a problem with this a while ago and added the following to my httpd.conf file.

<IfModule sapi_apache2.c>
    php_admin_flag engine on
    php_admin_flag safe_mode off
</IfModule>
<IfModule mod_php5.c>
    php_admin_flag engine on
    php_admin_flag safe_mode off
</IfModule>

Not sure if the modules are the same as yours as this was on a production server and not a Mac.

I hope this helps though.

Cheers

Adam

Adam Stacey
  • 101
  • 1