Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: Enable the built-in PHP module UNIX
If you did a fresh install of 10.3 you do not need to install PHP - it is installed by default! To enable it you just need to uncomment the following lines in the /etc -> httpd -> httpd.conf file:
LoadModule php4_module        libexec/httpd/libphp4.so
...
...
AddModule mod_php4.c
Now stop and restart Apache (Personal Web Sharing). To test it, create the following test.php file in your sites directory:

<?php>
 phpinfo();
?>
Now load test.php in your browser:
http://localhost/~username/test.php
And you should see the PHP configuration. Enjoy!

[robg adds: This is even easier than it was in 10.2, and make sure you see the related hint on editing the php.ini file.]
    •    
  • Currently 1.75 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[23,350 views]  

10.3: Enable the built-in PHP module | 27 comments | Create New Account
Click here to return to the '10.3: Enable the built-in PHP module' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Enable the built-in PHP module
Authored by: j0nathan on Nov 13, '03 12:14:01PM

There's a useful tip elsewhere on the site (that I can't find now) about changing apache configuration by using /private/etc/httpd/users/<username>.conf as opposed to changing the main httpd.conf. This protects your custom apache configurations when future installations are made. I'm presuming this holds in 10.3



[ Reply to This | # ]
10.3: Enable the built-in PHP module
Authored by: mozart11 on Nov 13, '03 12:50:29PM

What is the PHP module? Should this be activated by everyone?



[ Reply to This | # ]
10.3: Enable the built-in PHP module
Authored by: MtnBiker on Nov 13, '03 01:30:37PM

No. It is one of those, if you don't know what it is, you don't need to turn it on.

PHP is a server side language for serving web pages. In other works, scripts are run on the server to customize the output to the client. There are many client languages, but this one is free, well-supported and fairly common.
I use it on our club webpage. The cutest thing is to display a different selection from our photo gallery each time you use the page (and you can click through to the full size picture). I use it for more practical things like serving up the correct newsletter. The newsletter only has to be on the server and correctly named to appear when it should.
www.php.net for more info. Our club page sbmbc.com.

---
Hermosa Beach, CA USA



[ Reply to This | # ]
10.3: Enable the built-in PHP module
Authored by: avanham on Nov 13, '03 12:55:34PM
Great hint! The test file needs brackets after the 'phpinfo' line though. Here is the correct version
<?php>
phpinfo();
?>


[ Reply to This | # ]
10.3: Enable the built-in PHP module
Authored by: warrens on Nov 14, '03 09:26:27PM
No, PHP doesn't need the ?> at the end of a script for it to parse correctly. May be nice for appearances (and necessary for brain-dead editors like Dreamweaver), but on the other hand, any empty lines you may have in your PHP after the closing tag, will be sent out to the client, which is unnecessary.
<? phpinfo();
works fine.

[ Reply to This | # ]
10.3: Enable the built-in PHP module
Authored by: babbage on Nov 17, '03 12:14:58AM

Just because it can be done doesn't mean it's correct.

The whole point of "smart" markup languages like PHP, SSI, ASP, or JSP is to contain the advanced logic inside of HTML/XML/SGML tags so that the document remains otherwise syntactically valid. If Dreamweaver complains about a dangling marker like PHP's "?>", it's doing the right thing.

Come on, its only another two characters (three if you count a line break) -- it's not hard to include, and doing so is one way to avoid a mentality of sloppiness that can come back to haunt you when debugging other code later.

---
--
DO NOT LEAVE IT IS NOT REAL

[ Reply to This | # ]

10.3: Enable the built-in PHP module
Authored by: avanham on Nov 17, '03 08:46:53AM

Actually, I was talking about the () brackets. The original post had only :

[code]phpinfo[/code]

which didn't work on my system until I added the brackets:

[code]phpinfo()[/code]



[ Reply to This | # ]
10.3: Enable the built-in PHP module
Authored by: babbage on Nov 17, '03 09:51:56AM

What? That doesn't work -- the 'greater than' character at the end of the first line breaks everything. Didn't you test this before commenting?

The version that actually works looks like this:

    <?php
        phpinfo();
    ?>

The version given earlier, which starts <?php>, just returns a blank web page for me. Drop the '>' from that line and it works. (The hint text is now using the broken version -- it probably should be amended.)

Also, I've tried two variations that give much different results:

    <!-- variation ONE:
         gives a roughly plain text page back -->
    <?php
     phpinfo;
    ?>

    <!-- variation TWO:
         gives a colorful, formatted page with tables, etc -->
    <?php phpinfo() ?>

I don't know enough PHP to speculate about what the difference is here, or why the result is so different. Is it because there are no line breaks in the second version? Is it because there is no 'end of line' character in that one? I can't figure out what the important difference is between the two tags, but they give very dissimilar output after being served.

---
--
DO NOT LEAVE IT IS NOT REAL

[ Reply to This | # ]

10.3: Enable the built-in PHP module
Authored by: MtnBiker on Nov 13, '03 01:51:24PM

Is there any differences between the Panther version and th version available through Mark Livanage? The description on his site is ambiguous. http://www.entropy.ch/software/macosx/php/ Of course his version is slightly newer, but are there feature differences. OK I now need to write him.

To amplify another comment. To keep your customization the hint was to add
Include /private/etc/httpd/users
to the httpd.conf file and puts a file named
username.conf in the users folder. I put my Rendezvous "shortcuts" in that file too.

I think it's Livanage's version that adds:
Include /usr/local/php/httpd.conf.php
to the httpd.conf file.
and then puts the lines referred to in the original article in the httpd.conf.php file.

Confusing for we amateurs.

---
Hermosa Beach, CA USA



[ Reply to This | # ]
10.3: Enable the built-in PHP module
Authored by: fds on Nov 13, '03 03:11:07PM

He provides a whole lot more of the PHP extensions pre-compiled than Apple does.

If you don't know about these extensions and aren't missing them alreaedy, you probably don't need them though.



[ Reply to This | # ]
10.3: Enable the built-in PHP module
Authored by: bluehz on Nov 13, '03 07:33:25PM
You can find the same info as creating the phpinfo page in the terminal - enter php -i

Taking a quick look at the default Panther install of PHP 4.3.2 I see it is compiled with:

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/lib \
--with-apxs \
--with-iconv=/usr/local/php \
--with-openssl=/usr \
--with-zlib=/usr \
--with-mysql \
--with-pgsql=/Users/marc/entropy-cvs/php-module/build/postgresql-build \
--with-gd \
--with-png-dir=/usr/local/php \
--with-freetype-dir=/usr/local/php \
--with-t1lib=/usr/local/php \
--with-jpeg-dir=/usr/local/php \
--with-tiff-dir=/usr/local/php \
--with-curl=/usr/local/php \
--with-mcal=/usr/local/php \
--with-mcrypt=/usr/local/php \
--with-mhash=/usr/local/php \
--with-mcve=/usr/local/php \
--with-pdflib=/usr/local/php \
--with-imap=../imap-2002d \
--with-imap-ssl=/usr \
--with-expat-dir=/usr/local/php \
--with-gettext=/usr/local/php \
--with-dom=/usr/local/php \
--with-dom-xslt=/usr/local/php \
--with-dom-exslt=/usr/local/php \
--with-ldap \
--with-xmlrpc \
--with-xml \
--with-iodbc \
--with-xslt-sablot=/usr/local/php \
--enable-xslt \
--enable-sockets \
--enable-dbx \
--enable-dbase \
--enable-trans-sid \
--enable-exif \
--enable-wddx \
--enable-ftp \
--enable-mbstring
Thats a pretty extensive list - pretty much what I use when I compile it myself on my linux box.

[ Reply to This | # ]
10.3: Enable the built-in PHP module
Authored by: cilly on Nov 15, '03 08:40:53AM

Hm, are you using Mac OS X Panther Server?

---
cilly



[ Reply to This | # ]
10.3: Enable the built-in PHP module (And then update PHP)
Authored by: skribble on Nov 13, '03 02:55:31PM

Even cooler thing about Panther and PHP is that you can download the latest version off of php.net (4.3.4) and compile and install it perfectly over the version that ships with Panther.

This is necessary if you want to use pear BTW since certain files are missing from Panther's default install.

ie:
$ tar zxf php-4.3.4
$ cd php-4.3.4
$ ./configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-apxs --with-ldap=/usr --with-kerberos=/usr --enable-cli --with-zlib-dir=/usr --enable-trans-sid --with-xml --enable-exif --enable-ftp --enable-mbstring --enable-dbx --enable-sockets --with-iodbc=/usr --with-curl=/usr --with-config-file-path=/etc
$ make
$ sudo rm -rf /usr/lib/php/* // $ sudo make install

voilla!

[ Reply to This | # ]
10.3: Enable the built-in PHP module (And then update PHP)
Authored by: osxfan57 on Nov 14, '03 01:39:23AM

This is what I get when I run the command as instructed to update PHP:

$ make
$ sudo rm -rf /usr/lib/php/* // $ sudo make install

loading cache ./config.cache
checking host system type... powerpc-apple-darwin7.0.0
checking for gcc... no
checking for cc... no
configure: error: no acceptable cc found in $PATH
<MyUserName>-Computer:~/php-4.3.4 <MyUserName>$ $ make
-bash: $: command not found
<MyUserName>-Computer:~/php-4.3.4 <MyUserName>$ $ sudo rm -rf /usr/lib/php/* // $ sudo make install
-bash: $: command not found
<MyUserName>-Computer:~/php-4.3.4 <MyUserName>$

Is the problem I don't have the developer tools installed? If so, where on the Panther 10.3 CD's do I find it and how to install? Thanks.

---
iMac 17, OS 10.3



[ Reply to This | # ]
10.3: Enable the built-in PHP module (And then update PHP)
Authored by: celeborn on Nov 14, '03 04:28:45AM

The Developer Tools are called XCode on Panther, and a CD labelled 'XCode Tools' should have been in the Panther retail box.



[ Reply to This | # ]
10.3: Enable the built-in PHP module (And then update PHP)
Authored by: skribble on Nov 14, '03 08:11:44AM
Yes, you need the developers tools they are on the XCode CD that came with Panther. Also, the last line in my sample came across wrong... that should actually be two lines:

$ sudo rm -rf /usr/lib/php/*.*
$ sudo make install
(Also dont type the '$' that's the prompt) -S.

[ Reply to This | # ]
10.3: Enable the built-in PHP module (And then update PHP)
Authored by: osxfan57 on Nov 14, '03 10:36:32AM

Thanks! I installed DT off the Panther CD and it all worked perfectly as to installing. Only question now: when I run the php test script, I still get PHP Version 4.3.2, not 4.3.4. What am I doing wrong?

---
iMac 17, OS 10.3



[ Reply to This | # ]
10.3: Enable the built-in PHP module (And then update PHP)
Authored by: skribble on Nov 14, '03 12:32:01PM
did you restart apache?
 sudo apachectl restart
also reload you browser to make sure you are not just loading a cached version of the info page.

[ Reply to This | # ]
10.3: Enable the built-in PHP module (And then update PHP)
Authored by: osxfan57 on Nov 15, '03 12:50:16AM

I did, and I've actually both emptied the Safari cache and rebooted. No dice. Yet the install went fine, no errors!

---
iMac 17, OS 10.3



[ Reply to This | # ]
10.3: Enable the built-in PHP module (And then update PHP)
Authored by: osxfan57 on Nov 15, '03 12:51:59AM

Sorry, I hadn't restarted Remote Login. Now that I have, it shows up fine as 4.3.4. Thanks!

---
iMac 17, OS 10.3



[ Reply to This | # ]
10.3: Enable the built-in PHP module (And then update PHP)
Authored by: cansas on Nov 14, '03 10:57:32AM

I get the following error on make... any ideas?

ld: can't specify both -twolevel_namespace and -flatname_space
make: *** [libs/libphp4.bundle] Error 1



[ Reply to This | # ]
10.3: Enable the built-in PHP module (And then update PHP)
Authored by: cilly on Nov 15, '03 08:34:23AM
Great hint! You can gather the configure options with the test.php file mentioned above.

But I recommend backing up the original php installation before running this command:

sudo rm -rf /usr/lib/php/*
You never know, may be some OS X installer will fail...

---
cilly

[ Reply to This | # ]

Newbie question
Authored by: pairof9s on Nov 14, '03 10:11:26AM
Sorry for the elementary question but I'm new to this and want to explore the options.

That said, I'm having no luck getting the above hint to run properly in Terminal. It gives me "command not found" when getting to the LoadModule lines.

Am I missing something very fundamental here that the original post did not feel needed to be shown?

[ Reply to This | # ]
Newbie question
Authored by: MtnBiker on Nov 14, '03 01:59:29PM

Yes, very fundamental. Those are lines in the httpd.conf file to be edited. And the /etc/httpd/ is the folder. I'll try to put down a GUI way to do it.

In the finder, type Cmd-shift-G and then put in /etc/httpd/ which will open up that folder (since these are hidden, it is difficult to get there otherwise). Or, even better and more direct, In TextEdit, Cmd-O, and in the open dialog box, Cmd-Shift-G which brings up another little window where you type the same /etc/httpd/, hit enter and you're looking at the folder and then you can open the httpd.conf file and make the changes. That is remove the # from the beginning of the two lines shown in the original hint. You'll probably be asked for system admin password.
I usually put in a line beginning with a # (comment) and I write a note to myself about the change I made. To be safe, you can save a copy of the original file somewhere, either in the same folder with a name such as httpd.conf.originalAsOf14Nov03 or wherever else you want.

Thanks to recent hint for the Cmd-shift-g in the open dialog method.
Also note the corrections on the test file: add paratheses to phpinfo
You can restart Apache by going to System Preferences>Sharing, select Personal Web Sharing, click on stop, wait, then click on start. Not as geeky, but safer.
Also the geek would modify the file using a command line editor, but I'm a GUI type person.

PS. Thanks to the whomever answered my question about the differences between Panther PHP and Livanage PHP.

---
Hermosa Beach, CA USA



[ Reply to This | # ]
RE:Newbie question
Authored by: pairof9s on Nov 14, '03 02:34:37PM

Thanks! That did the trick.



[ Reply to This | # ]
Fix for PHP Source showing
Authored by: aramis on Dec 23, '03 03:15:48PM

I found I needed to do two additional things to get PHP alive. (This is on a virgin Panther install).

1) sudo cp /etc/php.ini.default /etc/php.ini
2) Add the following line to /etc/httpd/httpd.conf:
AddType application/x-httpd-php .php

Without the AddType bit, all I got was the source of the PHP page I was trying to hit.

Best regards,
Zac Bedell



[ Reply to This | # ]
Fix for PHP Source showing
Authored by: Anonymous on Aug 30, '04 09:06:13PM
In 10.3.5 you don't need to put in the AddType command because the config file already has code to turn on recognition of .php files if the mod_php4.c is also turned on. Here's the stock code from the .conf file:

<IfModule mod_php4.c>
    # If php is turned on, we repsect .php and .phps files.
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    # Since most users will want index.php to work we
    # also automatically enable index.php
    <IfModule mod_dir.c>
        DirectoryIndex index.html index.php
    </IfModule>
</IfModule>


[ Reply to This | # ]