Web Hosting Talk







View Full Version : PHP as Binary and Module


BMM
01-17-2002, 09:37 PM
I need to have PHP installed as binary and a module. Currently, the Linux server has PHP 4.06 as an Apache module and I need to install PHP has binary as well. Does anyone have a detailed and comprehensive tutorial on how to do this? I want to run the .php pages via the PHP module and run only a help desk app via PHP as binary. I do not want to mess up the PHP module install when installing the PHP as binary. The more command line details the better.

Any help would be greatly appreciated!

Starhost
01-18-2002, 05:44 AM
Ok this is what I always do for compiling PHP as a binary:

first download the PHP to your server and do:

# tar -zxvf php-4.x.x.tar.gz

Then do a cd

# cd php-4.x.x

Lets configure:

# ./configure --prefix=/usr --with-mysql

# make
# make install
# cp php /usr/bin/ or /usr/sbin/


Now you can run PHP scripts as cgi. :-) Hope it helped.

BMM
01-18-2002, 07:36 AM
Thanks for the reply. I installed PHP as binary... I think. Problem is that I can't run anything through the PHP as binary, it all goes through the Apache module. For example, I saved the following code in a file called testcgi.php.

#!/usr/local/bin/php -q

<?php

print("Hello, world!\n");

?>


This is the output that I get on the page.

#!/usr/local/bin/php -q Hello, world!


It looks as though it is completely ignoring "#!/usr/local/bin/php -q".

Any ideas?

Thanks in advance.

priyadi
01-18-2002, 08:04 AM
You need to add "AddHandler cgi-script .php" in your httpd.conf, and chmod +x the php script.

Noldar
01-18-2002, 09:49 AM
Or you should be able to just rename your file testcgi.php to testcgi.cgi. That way if you want to use PHP as an apache module you use a .php extension and if you want to use PHP as a binary you use a .cgi extension.

Richard

BMM
01-18-2002, 03:12 PM
When I rename the file to .cgi I get the following error message:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@tradingcardoutlet.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


Then tried to run the script from the command line:

1) cd /path/to/where/your/script/is
2) chmod 755 hellocgi.php
(To make it "executable")
3) ./hellocgi.php

I get the following message:

[root@ns testing]# ./hellocgi.php
Error in argument 1, char 3: option not found
Error in argument 1, char 3: option not found
Usage: php [-q] [-h] [-s [-v] [-i] [-f <file>] | {<file> [args...]}
-q Quiet-mode. Suppress HTTP Header output.
-s Display colour syntax highlighted source.
-f <file> Parse <file>. Implies `-q'
-v Version number
-C Do not chdir to the script's directory
-c <path> Look for php.ini file in this directory
-a Run interactively
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-z <file> Load Zend extension <file>.
-l Syntax check only (lint)
-m Show compiled in modules
-i PHP information
-h This help



Any ideas?

Starhost
01-18-2002, 03:28 PM
I also had that fault, you prbably got a space in front of the

#!/usr/bin/php

or

<?

And PHP Doesn't know how to handle this correct.

Because what happens if you run it by hand?
/usr/bin/php /path/to/script.php


Then it will probably work.

BMM
01-18-2002, 04:09 PM
I also had that fault, you probably got a space in front of the #!/usr/bin/php

I checked and no spaces. What do you mean running by hand? I tried running the script by shell and no luck(see previous post for error message).

priyadi
01-18-2002, 05:06 PM
The script is probably in DOS text format. Try converting it to unix format using this command: perl -pi -e 's/\r//g' hellocgi.php

BMM
01-19-2002, 02:39 AM
priyadi,

I did the command as you suggested buy still having the same problem. As before this is the result of hellocgi.php

#!/usr/local/bin/php -q Hello, world!

Any other ideas? I am stumped :(

Starhost
01-19-2002, 07:11 AM
What happens if you now remove the addhandler section in your httpd.conf??

So remove: AddHandler cgi-script .php


Now run from the commandline: /usr/bin/php /path/to/script.php
Remove the line #!/usr/bin/php -q when you do this, if this is working you probably have a whitespace, I'm sure because I also had that.

Now type in your shell: pico hello.php
put in it (type it your self! Do not copy and paste it!!!)

#!/usr/bin/php -q
<?
print "Hello world";
?>

And save this.
Now chmod 755 hello.php and run it ./hello.php


Hope this helps.

priyadi
01-19-2002, 12:47 PM
Originally posted by BMM
priyadi,

I did the command as you suggested buy still having the same problem. As before this is the result of hellocgi.php

#!/usr/local/bin/php -q Hello, world!

Any other ideas? I am stumped :(

If that's what you got, that must be something with your httpd.conf, have you properly added AddHandler cgi-script .php to your httpd.conf?

Ahmad
01-19-2002, 01:10 PM
Do you want your .php files to be served by the binary installation or module installation of apache?

The problem is probably because you have the .php extension associated with both CGI handler and the PHP module handler, and Apache is choosing PHP module.

just look a line similar to this and comment it out:

AddType application/x-httpd-php .php

BMM
01-21-2002, 11:09 PM
Thanks for all the suggestions, unfortunately I am still having problems.


Do you want your .php files to be served by the binary installation or module installation of apache?

I want to be able to run PHP command line scripts from binary while using PHP apache module to run the .php pages for the site.


I tired adding .php to the AddHandler within httpd.conf (i.e. cgi-script .cgi .pl .php) and I also commented out the AddHandler cgi-script-script .cgi .pl .php. Neither of these worked. I set it back to the default (AddHandler cgi-script-script .cgi .pl) and started from square 1 as instructed below:

Now type in your shell: pico hello.php
put in it (type it your self! Do not copy and paste it!!!)

#!/usr/bin/php -q
<?
print "Hello world";
?>

And save this.
Now chmod 755 hello.php and run it ./hello.php


I received the following message after running the script.

permission denied

This is a little encouraging since this is a completely different error than what I have been getting. Although I am a not sure what it means or how to correct the situation. Does anyone know why I would be getting this error and am I getting any closer to running PHP from the command line?

Thanks in advance for you comments

BMM
01-21-2002, 11:33 PM
Update....

Here is something intersting that may shed some light on this problem. I just created the exact same script (hello.php) as described in the post immediately before this one. However, instead of using pico, I created the file on my Windows 2000 Professional desktop via PFE and then FTPed it to the Linux server and then did chmod 755 to make it executable. When I ran the script I got the error following error:

Error in argument 1, char 3: option not found
Error in argument 1, char 3: option not found
Usage: php [-q] [-h] [-s [-v] [-i] [-f <file>] | {<file> [args...]}
-q Quiet-mode. Suppress HTTP Header output.
-s Display colour syntax highlighted source.
-f <file> Parse <file>. Implies `-q'
-v Version number
-C Do not chdir to the script's directory
-c <path> Look for php.ini file in this directory
-a Run interactively
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-z <file> Load Zend extension <file>.
-l Syntax check only (lint)
-m Show compiled in modules
-i PHP information
-h This help

This is much different than the permission denied error that I received using this same script created with pico. I have a feeling that I have made this a much tougher problem by FTPing files from Windows to the Linux server. From now on I am staying within Linux. This still leaves the problem of the permission denied. Any ideas?

priyadi
01-22-2002, 12:26 AM
You seem to do everybody's suggestions here. It is better if you do it one at a time :). Alright then, here are what you need to do:

- on httpd.conf make sure there is 'AddHandler cgi-script cgi'
- using pico (or another unix text editor) create a file named test.cgi containing:


#!/usr/local/bin/php
<? phpinfo() ?>


(do not use FTP, pico is the safest way to ensure you have a proper unix text file)

- chmod +x test
- now run it by hand using ./test.cgi
- now try it from your web browser

BMM
01-22-2002, 04:32 AM
priyadi,

I did as you instructed. When running the script from the command line ./test.cgi it returned all of the html code for phpinfo().

Then when viewing it from the web browser it dispayed the page correctly for the PHP as a binary installation. Although #!/usr/local/bin/php was displayed in the upper left hand corner of the page. Why will it run .cgi files but not .php files from the command line?

Thanks

Starhost
01-22-2002, 06:34 AM
May I ask what it is that you exactly want? Do you want to run PHP script trough your shell or prase them to the www.

If it is running throw your shell do what I said but chmoddd the script 755. And then run it again, then it should work. (as it is also working on my own server).

Ahmad
01-22-2002, 07:18 AM
Originally posted by BMM


Then when viewing it from the web browser it dispayed the page correctly for the PHP as a binary installation. Although #!/usr/local/bin/php was displayed in the upper left hand corner of the page. Why will it run .cgi files but not .php files from the command line?

Thanks

One thing I'm sure about. This page was served by the PHP module and not binary installation. :)

priyadi
01-22-2002, 08:01 AM
Originally posted by BMM
priyadi,

I did as you instructed. When running the script from the command line ./test.cgi it returned all of the html code for phpinfo().

Then when viewing it from the web browser it dispayed the page correctly for the PHP as a binary installation. Although #!/usr/local/bin/php was displayed in the upper left hand corner of the page. Why will it run .cgi files but not .php files from the command line?

Thanks

Whoa... if the #! line get shown, it must be served from your Apache module version of PHP. Find a line from your httpd.conf that says AddType application/x-httpd-php cgi, and remove it. Even better, revert your httpd.conf to the default one, and do my previous instruction again.