html as php on mac?
March 1, 2009 7:53 AM   Subscribe

I have a web application that is using php but the files end in html. I'm trying to set it up on a mac (10.5) for testing. Basically trying to run html as php. I've tried a few things including "AddHandler x-mapp-php5 .html .htm" with no luck. Thanks.
posted by mac-way to Computers & Internet (6 answers total)
also tried AddType application/x-httpd-php .html in the .htaccess file
posted by mac-way at 7:57 AM on March 1, 2009

In your follow up, you mentioned that you tried this in the .htaccess file. If so, you should check that your apache config for the server or virtual host allows this in the AllowOveride directive. If you're just testing on a machine that's not exposed to the world, go ahead and set it to all.

I don't recall if you can do this in a directory statement and the .htaccess since I've never tried to do so. I'd tend to put it in the config file for the entire server or the virtual host it's running under.

You could also change the filenames to their proper .php filenames and use mod_rewrite to send all requests for something.html to something.php .

I imagine this isn't an app you're writing, but I'd tend to agree with cjorgensen and discourage such behavior ;)
posted by advicepig at 8:29 AM on March 1, 2009

Yeah, you'll need to edit /private/etc/apache2/users/username.conf and change:

AllowOverride None


AllowOverride All

before changes like that will work in an .htaccess file in your /Users/username/Sites/ directory. If you're working out of /Library/Webserver/Documents/, you'll need to make that change in /private/etc/apache2/httpd.conf, around line 210.

Once you've made the change, have it take effect with the command:

sudo /usr/sbin/apachectl graceful
posted by hades at 9:12 AM on March 1, 2009

Why discourage such behaviour? I've often wondered why PHP doesn't run inside HTML files in general, is there some reason they made it that way?
posted by jeffmilner at 10:21 AM on March 1, 2009

jeffmilner, because even trying to parse a PHP file to see if it has executable code is much more computationally expensive than the webserver software telling the OS to blast the file out as fast as it can.
posted by Good Brain at 12:44 PM on March 1, 2009

Thanks! Yes, I am working out of /Library/Webserver/Documents/ and that worked great. Not sure why this app was written using this behavior.
posted by mac-way at 12:45 PM on March 1, 2009

« Older Help me get started with basic electrical...   |   Name-that-song filter: Trippy jungle drum /... Newer »
This thread is closed to new comments.