By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,817 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

Enabling PHP in Leopard

P: n/a
I want to use my new Macbook Pro as a development platform for work,
so I went looking for info on installing Apache, PHP, Postgres, etc on
Leopard. I discovered in my search that Apache and PHP are already
installed by default, but disabled, so I'd just have to enable the
already-installed versions.

Getting Apache up and running was no problem. You just check "enable
web sharing" in the Sharing control panel and away you go. getting
PHP working is proving not to be so simple.

I made sure Apache was not running, started a terminal and followed
the instructions I had found online. Namely I CD'd to /etc/apache2,
then sudo pico httpd.conf and uncommented the line that loads
php5_module.so. I saved my changes and restarted the server. No
joy. The server was serving HTML no trouble, but PHP files were not
executing and just echoing their source code back.

I'm obviously missing something, but what? Do I need to add the PHP
MIME type to httpd.conf? None of the websites with instructions for
enabling PHP mentioned needing to do so. Or is there some other step
that I'm missing?
Dec 11 '07 #1
Share this Question
Share on Google+
13 Replies


P: n/a
On Tue, 11 Dec 2007 14:43:05 +0100, Gordon <go**********@ntlworld.com>
wrote:
I want to use my new Macbook Pro as a development platform for work,
so I went looking for info on installing Apache, PHP, Postgres, etc on
Leopard. I discovered in my search that Apache and PHP are already
installed by default, but disabled, so I'd just have to enable the
already-installed versions.

Getting Apache up and running was no problem. You just check "enable
web sharing" in the Sharing control panel and away you go. getting
PHP working is proving not to be so simple.

I made sure Apache was not running, started a terminal and followed
the instructions I had found online. Namely I CD'd to /etc/apache2,
then sudo pico httpd.conf and uncommented the line that loads
php5_module.so. I saved my changes and restarted the server. No
joy. The server was serving HTML no trouble, but PHP files were not
executing and just echoing their source code back.

I'm obviously missing something, but what? Do I need to add the PHP
MIME type to httpd.conf? None of the websites with instructions for
enabling PHP mentioned needing to do so. Or is there some other step
that I'm missing?
<http://nl2.php.net/manual/en/install.macosx.bundled.php>
(this still mentions php4, but you get the drift)

Add these lines to httpd.conf, and then restart the server:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

And possibly add 'index.php' to the DirectoryIndex directive.
--
Rik Wasmus
Dec 11 '07 #2

P: n/a
Rik Wasmus <lu************@hotmail.comwrote:
On Tue, 11 Dec 2007 14:43:05 +0100, Gordon <go**********@ntlworld.com>
wrote:
I want to use my new Macbook Pro as a development platform for work,
so I went looking for info on installing Apache, PHP, Postgres, etc on
Leopard. I discovered in my search that Apache and PHP are already
installed by default, but disabled, so I'd just have to enable the
already-installed versions.

Getting Apache up and running was no problem. You just check "enable
web sharing" in the Sharing control panel and away you go. getting
PHP working is proving not to be so simple.

I made sure Apache was not running, started a terminal and followed
the instructions I had found online. Namely I CD'd to /etc/apache2,
then sudo pico httpd.conf and uncommented the line that loads
php5_module.so. I saved my changes and restarted the server. No
joy. The server was serving HTML no trouble, but PHP files were not
executing and just echoing their source code back.
That's exactly what I did.

I had the same problem the first time I tried to execute some PHP but it
seemed to correct itself subsequently (no idea why). It is working fine
at the moment.

I initially thought there was a problem recognising the "<?" prefix but
it was OK with "<?php", or it didn't like jumping straight into PHP
without an HTML header, as it worked after I made those changes. On
further investigation these turned out to be red herrings. I have a test
file called info.php which works fine and it contains the following
single line:

<? phpinfo(); ?>

Mac OS X 10.5.1, Apache 2.2.6 (standard) and PHP 5.2.4 (standard).

I've kept a copy of the original httpd.conf and comparing it to my
version, the only relevant change I made was uncommenting the
"LoadModule php5_module ..." line.

I can't see anything strange in /var/log/apache2/error_log around the
time I enabled PHP. It shows Apache starting up with PHP loaded, which
it didn't the previous time.
I'm obviously missing something, but what? Do I need to add the PHP
MIME type to httpd.conf? None of the websites with instructions for
enabling PHP mentioned needing to do so. Or is there some other step
that I'm missing?

<http://nl2.php.net/manual/en/install.macosx.bundled.php>
(this still mentions php4, but you get the drift)

Add these lines to httpd.conf, and then restart the server:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

And possibly add 'index.php' to the DirectoryIndex directive.
None of that is necessary. There is a file /etc/apache2/other/php5.conf
which contains all of those instructions, conditional on the PHP5 module
being loaded. All files in 'other' are included by httpd.conf.

--
David Empson
de*****@actrix.gen.nz
Dec 11 '07 #3

P: n/a
On 11 Dec, 14:24, demp...@actrix.gen.nz (David Empson) wrote:
I initially thought there was a problem recognising the "<?" prefix but
it was OK with "<?php"
You may have to spcifically set short tags on. Or better, don't use
'em at all.
Dec 11 '07 #4

P: n/a
On Tue, 11 Dec 2007 15:24:27 +0100, David Empson <de*****@actrix.gen.nz>
wrote:
Rik Wasmus <lu************@hotmail.comwrote:
>On Tue, 11 Dec 2007 14:43:05 +0100, Gordon <go**********@ntlworld.com>
wrote:
I want to use my new Macbook Pro as a development platform for work,
so I went looking for info on installing Apache, PHP, Postgres, etc on
Leopard. I discovered in my search that Apache and PHP are already
installed by default, but disabled, so I'd just have to enable the
already-installed versions.

Getting Apache up and running was no problem. You just check "enable
web sharing" in the Sharing control panel and away you go. getting
PHP working is proving not to be so simple.

I made sure Apache was not running, started a terminal and followed
the instructions I had found online. Namely I CD'd to /etc/apache2,
then sudo pico httpd.conf and uncommented the line that loads
php5_module.so. I saved my changes and restarted the server. No
joy. The server was serving HTML no trouble, but PHP files were not
executing and just echoing their source code back.

That's exactly what I did.

I had the same problem the first time I tried to execute some PHP but it
seemed to correct itself subsequently (no idea why). It is working fine
at the moment.

I initially thought there was a problem recognising the "<?" prefix but
it was OK with "<?php", or it didn't like jumping straight into PHP
without an HTML header, as it worked after I made those changes.
It's called short_open_tags, and it's been turned OFF by default in PHP 5,
ON in PHP 4. You can set it in php.ini, but I'd advice you never to rely
on short tags, it will ensure portability, and it's easier to output an
XML header.
--
Rik Wasmus
Dec 11 '07 #5

P: n/a
Rik Wasmus <lu************@hotmail.comwrote:
On Tue, 11 Dec 2007 15:24:27 +0100, David Empson <de*****@actrix.gen.nz>
wrote:
Rik Wasmus <lu************@hotmail.comwrote:
I made sure Apache was not running, started a terminal and followed
the instructions I had found online. Namely I CD'd to /etc/apache2,
then sudo pico httpd.conf and uncommented the line that loads
php5_module.so. I saved my changes and restarted the server. No
joy. The server was serving HTML no trouble, but PHP files were not
executing and just echoing their source code back.
That's exactly what I did.

I had the same problem the first time I tried to execute some PHP but it
seemed to correct itself subsequently (no idea why). It is working fine
at the moment.

I initially thought there was a problem recognising the "<?" prefix but
it was OK with "<?php", or it didn't like jumping straight into PHP
without an HTML header, as it worked after I made those changes.

It's called short_open_tags, and it's been turned OFF by default in PHP 5,
ON in PHP 4. You can set it in php.ini, but I'd advice you never to rely
on short tags, it will ensure portability, and it's easier to output an
XML header.
Ok, thanks for the heads-up.

As far as I can tell, Apple's PHP 5 build is pointing at /etc to locate
its configuration file:

--with-config-file-path=/etc

There is no php.ini in that directory, so this suggests that PHP 5 is
running with default configuration, but perhaps Apple has modified the
defaults.

There is a /etc/php.ini.default. This file contains the line:

short_open_tag = On

I also see that my phpinfo() output says short_open_tags is On.

It looks like the same file is present in a fresh install of Mac OS X
10.5, so all evidence says that Apple's default configuration for PHP 5
is to have short_open_tag On.

This may be a side issue to Gordon's problem.

--
David Empson
de*****@actrix.gen.nz
Dec 11 '07 #6

P: n/a
On Dec 11, 3:44 pm, demp...@actrix.gen.nz (David Empson) wrote:
Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
On Tue, 11 Dec 2007 15:24:27 +0100, David Empson <demp...@actrix.gen.nz>
wrote:
Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
I made sure Apache was not running, started a terminal and followed
the instructions I had found online. Namely I CD'd to /etc/apache2,
then sudo pico httpd.conf and uncommented the line that loads
php5_module.so. I saved my changes and restarted the server. No
joy. The server was serving HTML no trouble, but PHP files were not
executing and just echoing their source code back.
That's exactly what I did.
I had the same problem the first time I tried to execute some PHP but it
seemed to correct itself subsequently (no idea why). It is working fine
at the moment.
I initially thought there was a problem recognising the "<?" prefix but
it was OK with "<?php", or it didn't like jumping straight into PHP
without an HTML header, as it worked after I made those changes.
It's called short_open_tags, and it's been turned OFF by default in PHP 5,
ON in PHP 4. You can set it in php.ini, but I'd advice you never to rely
on short tags, it will ensure portability, and it's easier to output an
XML header.

Ok, thanks for the heads-up.

As far as I can tell, Apple's PHP 5 build is pointing at /etc to locate
its configuration file:

--with-config-file-path=/etc

There is no php.ini in that directory, so this suggests that PHP 5 is
running with default configuration, but perhaps Apple has modified the
defaults.

There is a /etc/php.ini.default. This file contains the line:

short_open_tag = On

I also see that my phpinfo() output says short_open_tags is On.

It looks like the same file is present in a fresh install of Mac OS X
10.5, so all evidence says that Apple's default configuration for PHP 5
is to have short_open_tag On.

This may be a side issue to Gordon's problem.

--
David Empson
demp...@actrix.gen.nz
I don't think short tags are causing the problem, as both <?php
phpinfo (); ?and <? phpinfo (); ?are failing to execute.
Dec 11 '07 #7

P: n/a
On 2007-12-11 13:51:15 +0000, "Rik Wasmus" <lu************@hotmail.comsaid:
On Tue, 11 Dec 2007 14:43:05 +0100, Gordon <go**********@ntlworld.com wrote:
>I want to use my new Macbook Pro as a development platform for work,
so I went looking for info on installing Apache, PHP, Postgres, etc on
Leopard. I discovered in my search that Apache and PHP are already
installed by default, but disabled, so I'd just have to enable the
already-installed versions.
I know it does not exactly answer your post, but I use MAMP to test my
PHP webpages and it works extremely well. It might tie you over until
you can sort this mess out!
--
Replace vetsco with a well known supermarket chain

Dec 11 '07 #8

P: n/a
On 2007-12-11 17:25:43 +0000, tricky <rs**@vetsco.netsaid:
On 2007-12-11 13:51:15 +0000, "Rik Wasmus" <lu************@hotmail.comsaid:
>On Tue, 11 Dec 2007 14:43:05 +0100, Gordon <go**********@ntlworld.com wrote:
>>I want to use my new Macbook Pro as a development platform for work,
so I went looking for info on installing Apache, PHP, Postgres, etc on
Leopard. I discovered in my search that Apache and PHP are already
installed by default, but disabled, so I'd just have to enable the
already-installed versions.

I know it does not exactly answer your post, but I use MAMP to test my
PHP webpages and it works extremely well. It might tie you over until
you can sort this mess out!
It should be fairly straightforward to see what Apache's *really* doing
with a spot of playing with Instruments.app.

Cheers,

Chris

Dec 11 '07 #9

P: n/a
Gordon <go**********@ntlworld.comwrote:
On Dec 11, 3:44 pm, demp...@actrix.gen.nz (David Empson) wrote:
Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
On Tue, 11 Dec 2007 15:24:27 +0100, David Empson <demp...@actrix.gen.nz>
wrote:
Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
I made sure Apache was not running, started a terminal and followed
the instructions I had found online. Namely I CD'd to /etc/apache2,
then sudo pico httpd.conf and uncommented the line that loads
php5_module.so. I saved my changes and restarted the server. No
joy. The server was serving HTML no trouble, but PHP files were not
executing and just echoing their source code back.
[snip]
I don't think short tags are causing the problem, as both <?php
phpinfo (); ?and <? phpinfo (); ?are failing to execute.
Have a look at the files I mentioned in earlier posts.

In particular: what do you see in "/var/log/apache2/error_log" ?

Look for lines resembling this:

[Wed Nov 07 04:21:39 2007] [notice] Apache/2.2.6 (Unix) mod_ssl/2.2.6
OpenSSL/0.9.7l DAV/2 configured -- resuming normal operations

The above line is what I got when I first started Apache2 _without_ PHP.

[Wed Nov 28 23:33:58 2007] [notice] Apache/2.2.6 (Unix) mod_ssl/2.2.6
OpenSSL/0.9.7l DAV/2 PHP/5.2.4 configured -- resuming normal operations

The above line is what I got when I started Apache2 after enabling PHP.
Note that "PHP/5.2.4" appeared in the log entry.

This will show whether Apache thinks it is loading the PHP module. Also
look for any other error messages around recent Apache startups.

Next, have a look in /etc for any files relating to PHP. I have a
"php.ini.default" but no "php.ini". If you have a php.ini, it might have
been retained from an earlier system (after an upgrade or migration) and
it might not be compatible with PHP 5. If so, I'd expect to see an error
message appearing somewhere in a log.

If there is nothing in the Apache error log, check the Console and
system.log around the time of Apache's last startup (as given by the
timestamp in the Apache error log).

--
David Empson
de*****@actrix.gen.nz
Dec 11 '07 #10

P: n/a
tricky wrote:
I know it does not exactly answer your post, but I use MAMP to test my
PHP webpages and it works extremely well.
Yeah, I tend to use MAMP too. I've got the built-in Apache running too.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 4 days, 9:11.]

Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/1...tunes-sharing/
Dec 11 '07 #11

P: n/a
In article
<f3**********************************@e10g2000prf. googlegroups.com>,
Gordon <go**********@ntlworld.comwrote:
I want to use my new Macbook Pro as a development platform for work,
so I went looking for info on installing Apache, PHP, Postgres, etc on
Leopard. I discovered in my search that Apache and PHP are already
installed by default, but disabled, so I'd just have to enable the
already-installed versions.

Getting Apache up and running was no problem. You just check "enable
web sharing" in the Sharing control panel and away you go. getting
PHP working is proving not to be so simple.

I made sure Apache was not running, started a terminal and followed
the instructions I had found online. Namely I CD'd to /etc/apache2,
then sudo pico httpd.conf and uncommented the line that loads
php5_module.so. I saved my changes and restarted the server. No
joy. The server was serving HTML no trouble, but PHP files were not
executing and just echoing their source code back.

I'm obviously missing something, but what? Do I need to add the PHP
MIME type to httpd.conf? None of the websites with instructions for
enabling PHP mentioned needing to do so. Or is there some other step
that I'm missing?
You have to serve your files from ~/Sites, and then do

http://[your.ip.address]/test.php

Once you've uncommented that line like you did, and restarted the
server, that's all you need to do. Put a test.php file in ~/Sites that
has

<?php
phpinfo();
?>

in it, and all should be well. The pages have to be _served_, you can't
just drag a php file into the browser window. Note that if you add

Listen: 127.0.0.1:80

to httpd.conf (almost at the very beginning), you can do

http://localhost/test.php

and view your pages.
--
W. Oates
Dec 12 '07 #12

P: n/a
Gordon wrote:
On Dec 11, 3:44 pm, demp...@actrix.gen.nz (David Empson) wrote:
>Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
>>On Tue, 11 Dec 2007 15:24:27 +0100, David Empson <demp...@actrix.gen.nz>
wrote:
Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
>I made sure Apache was not running, started a terminal and followed
>the instructions I had found online. Namely I CD'd to /etc/apache2,
>then sudo pico httpd.conf and uncommented the line that loads
>php5_module.so. I saved my changes and restarted the server. No
>joy. The server was serving HTML no trouble, but PHP files were not
>executing and just echoing their source code back.
That's exactly what I did.
I had the same problem the first time I tried to execute some PHP but it
seemed to correct itself subsequently (no idea why). It is working fine
at the moment.
I initially thought there was a problem recognising the "<?" prefix but
it was OK with "<?php", or it didn't like jumping straight into PHP
without an HTML header, as it worked after I made those changes.
It's called short_open_tags, and it's been turned OFF by default in PHP 5,
ON in PHP 4. You can set it in php.ini, but I'd advice you never to rely
on short tags, it will ensure portability, and it's easier to output an
XML header.
Ok, thanks for the heads-up.

As far as I can tell, Apple's PHP 5 build is pointing at /etc to locate
its configuration file:

--with-config-file-path=/etc

There is no php.ini in that directory, so this suggests that PHP 5 is
running with default configuration, but perhaps Apple has modified the
defaults.

There is a /etc/php.ini.default. This file contains the line:

short_open_tag = On

I also see that my phpinfo() output says short_open_tags is On.

It looks like the same file is present in a fresh install of Mac OS X
10.5, so all evidence says that Apple's default configuration for PHP 5
is to have short_open_tag On.

This may be a side issue to Gordon's problem.

--
David Empson
demp...@actrix.gen.nz

I don't think short tags are causing the problem, as both <?php
phpinfo (); ?and <? phpinfo (); ?are failing to execute.
After making the changes did you fully stop and restart Apache?
Reloading isn't good enough - all that does is reload the configuration.
It won't load new modules.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Dec 12 '07 #13

P: n/a
On Dec 12, 3:52 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Gordon wrote:
On Dec 11, 3:44 pm, demp...@actrix.gen.nz (David Empson) wrote:
Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
On Tue, 11 Dec 2007 15:24:27 +0100, David Empson <demp...@actrix.gen.nz>
wrote:
Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
I made sure Apache was not running, started a terminal and followed
the instructions I had found online. Namely I CD'd to /etc/apache2,
then sudo pico httpd.conf and uncommented the line that loads
php5_module.so. I saved my changes and restarted the server. No
joy. The server was serving HTML no trouble, but PHP files were not
executing and just echoing their source code back.
That's exactly what I did.
I had the same problem the first time I tried to execute some PHP but it
seemed to correct itself subsequently (no idea why). It is working fine
at the moment.
I initially thought there was a problem recognising the "<?" prefix but
it was OK with "<?php", or it didn't like jumping straight into PHP
without an HTML header, as it worked after I made those changes.
It's called short_open_tags, and it's been turned OFF by default in PHP 5,
ON in PHP 4. You can set it in php.ini, but I'd advice you never to rely
on short tags, it will ensure portability, and it's easier to output an
XML header.
Ok, thanks for the heads-up.
As far as I can tell, Apple's PHP 5 build is pointing at /etc to locate
its configuration file:
--with-config-file-path=/etc
There is no php.ini in that directory, so this suggests that PHP 5 is
running with default configuration, but perhaps Apple has modified the
defaults.
There is a /etc/php.ini.default. This file contains the line:
short_open_tag = On
I also see that my phpinfo() output says short_open_tags is On.
It looks like the same file is present in a fresh install of Mac OS X
10.5, so all evidence says that Apple's default configuration for PHP 5
is to have short_open_tag On.
This may be a side issue to Gordon's problem.
--
David Empson
demp...@actrix.gen.nz
I don't think short tags are causing the problem, as both <?php
phpinfo (); ?and <? phpinfo (); ?are failing to execute.

After making the changes did you fully stop and restart Apache?
Reloading isn't good enough - all that does is reload the configuration.
It won't load new modules.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
I restarted the whole computer.
Dec 12 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.