LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-21-2003, 02:29 PM   #1
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Rep: Reputation: 30
PHP newbie question


When I run my script off of my server at school, all the "echo" line work just fine. But when I try to run it off my apache here at home, I get weird lines like:

Title: $title "; echo "

when I'm actually trying to just print out the value of the $title variable.

Anybody see the issue here?
 
Old 11-21-2003, 02:41 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Is php installed and apache php enabled?

Fast way to check:

Create a file called phpinfo.php in your document root.

Put this inside that file:

</HEAD>
<BODY>
<?php /* Print PHP info */ phpinfo(); ?>
</BODY>
</HTML>

Open your browser and load this file.

If php is installed correctly and apache is php aware, then you should get a bunch of information about php, apache etc.

If not.........

PS: Don't leave this file in your document root (or any other dir in that tree). Just remove it after you have it all sorted out.
 
Old 11-21-2003, 02:52 PM   #3
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
Ok, I did it and I got tables and tables of info. So I'm assuming it is perhaps not configured properly??

Here is some of the info:

System Linux stripples.devel.redhat.com 2.4.21-1.1931.2.274.entsmp #1 SMP Tue Jun 24 11:18:10 EDT 2003 i686 i686 i386 GNU/Linux
Build Date Jun 29 2003 16:34:10
Configure Command './configure' '--host=i386-redhat-linux' '--build=i386-redhat-linux' '--target=i386-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--enable-force-cgi-redirect' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-db3' '--with-curl' '--with-dom=/usr' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-gd' '--enable-gd-native-ttf' '--with-ttf' '--with-gdbm' '--with-gettext' '--with-ncurses' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-regex=system' '--with-xml' '--with-expat-dir=/usr' '--with-zlib' '--with-layout=GNU' '--enable-bcmath' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-discard-path' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--without-oci8' '--with-pear=/usr/share/pear' '--with-imap=shared' '--with-imap-ssl' '--with-kerberos=/usr/kerberos' '--with-ldap=shared' '--with-mysql=shared,/usr' '--with-pgsql=shared' '--with-snmp=shared,/usr' '--with-snmp=shared' '--enable-ucd-snmp-hack' '--with-unixODBC=shared' '--enable-memory-limit' '--enable-bcmath' '--enable-shmop' '--enable-versioning' '--enable-calendar' '--enable-dbx' '--enable-dio' '--enable-mcal' '--with-apxs2=/usr/sbin/apxs'
Server API Apache 2.0 Filter
Virtual Directory Support disabled
Configuration File (php.ini) Path /etc/php.ini
Scan this dir for additional .ini files /etc/php.d
additional .ini files parsed /etc/php.d/imap.ini,
/etc/php.d/ldap.ini
Debug Build no
Thread Safety disabled


Thanks for any help!
 
Old 11-21-2003, 03:08 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Could be an option in your php.ini file (/etc/php.ini). I can't tell you which one.
Try to get hold of a copy of the php.ini your school uses and compare it with the one you have.

Are you certain that the code you wrote/copied is correct?

Do you start with <? or with <?php. If you start with the first one try the second one. If this solves your problem, look for the following line in your php.ini:

short_open_tag = Off

If you change this to On you can use <? to indicate that this is a php file. Personally I always use the <?php tag and leave the above option like it is (Off).
 
Old 11-21-2003, 03:18 PM   #5
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
No, that wasn't the problem. Thanks for trying though.

Out of curiosity - (I'm new to all of this remember), in my httpd.conf I add this line:

AddHandler php-script php

Is this correct? I just added it under my line which reads:

AddHandler cgi-script pl cgi


What do you think??
 
Old 11-21-2003, 03:34 PM   #6
hadding
Member
 
Registered: Oct 2003
Distribution: Redhat 9
Posts: 40

Rep: Reputation: 15
httpd.conf for php & Apache 2 :


Add "LoadModule php4_module modules/libphp4.so" to the bottom of the LoadModule list

Edit "DirectoryIndex index.html index.html.var" & add index.php to the end

Add "AddType application/x-httpd-php .php" to the bottom part of httpd.conf

Add "AddType application/x-httpd-php-source .phps" to the bottom part of httpd.conf

Create test.php, containing the following code :

<?php phpinfo(); ?>

Add test.php to your document root directory.

Access URL http://localhost/test.php
 
Old 11-21-2003, 03:50 PM   #7
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
Ok, I did all of that. I put the test.php file in my /var/www/cgi-bin and it seems to work fine.

But I'm still having the same problem with my other page. Also, when I run apache it says that the php4 module is already loaded - so I removed that LoadModule line from the httpd.conf.

Please don't give up on me!
 
Old 11-21-2003, 04:01 PM   #8
hadding
Member
 
Registered: Oct 2003
Distribution: Redhat 9
Posts: 40

Rep: Reputation: 15
Try this link http://www.devside.net/ . It's about the best step by step guide I know of for installing Apache/php/MySQL. Also contains instructions for OpenSSL & Perl if you want to play with that. They have a ready made httpd.conf that you might want to try out ( back up your existing one first )

Off the top of my head it sounds like you have something misconfigured in either/both your php.ini & httpd.conf.
 
Old 11-21-2003, 04:08 PM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
These are the entries that could be there. But it assumes that apache has DSO support and php is a module. If you are not certain about that check if the following file is present on your system:

/<path>/<to>/<apache>/modules/libphp4.so

There is a second way to install php, but I'm not certain what it should look like. So you could be correct with the 'AddHandler cgi-script pl cgi' entry. If libphp4.so is not on your system, you probably have installed php the 'other' way and the 'LoadModule php4_module modules/libphp4.so' will probably not work. It can't hurt trying.

Make a copy of your original httpd.conf before you start changing it. If the new config doesn't work you need to restore a working version (don't create a bigger problem).

Ok, here we go.

These belong in your httpd.conf. The # <some text> gives you an indication where the line should go in the httpd.conf.

# LoadModule foo_module modules/mod_foo.so
LoadModule php4_module modules/libphp4.so

#DirectoryIndex index.html index.html.var
DirectoryIndex index.php index.html index.htm index.html.var

# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
AddType application/x-httpd-php .php

Explanation:
=> LoadModule php4_module modules/libphp4.so
Make apache php aware.

DirectoryIndex index.php index.html index.htm index.html.var
=> the name and order of the files that apache will load automatically when only the url/directory structure is enter in a browser.

I.e: If you enter this in your browser:
http://some.site.com/
and one of these files is present:
index.php index.html index.htm index.html.var
it will be loaded and shown.

AddType application/x-httpd-php .php
=> recognize the .php extension. Could be that there are more in your config. Leave them, just make sure that .php is there too.

You do need to restart apache after you changed the httpd.conf file:

/<path>/<to>/<apache>/bin/bin/apachectl restart

Check logfile to see if anything went wrong. These logfiles are probably located here:

/<path>/<to>/<apache>/logs/

Check if your pages are still available.
Check if the php page that didn't work is recognized.

If your problem still excists, restore your original httpd.conf and restart apache.

Hope this helps.
 
Old 11-21-2003, 04:53 PM   #10
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
I think I've done everything you guys are saying. I thought I would show you my php code:

<html>
<head><title>Submition Results</title></head>

<body>
<p>
<h2>Submition Results:</h2>
<br/>
</p>
<p>
<?php
$output = fopen("files/bookdata.dat", "a+") or
die ("Error with output stream");
flock($output,2);
fwrite($output,"$title\t$issue\t$publisher\t$date\t$price\n");
flock($output,3);
echo "<h3>Title: $title </h3>";
echo "<h3>Issue# $issue </h3>";
echo "<h3>Publisher: $publisher </h3>";
echo "<h3>Date Published: $date </h3>";
echo "<h3>Price: $$price </h3>";
?>
</p>
<p><br/><br/>

This isn't the entire code obviously. But here is the output:


Submition Results:

Title: $title "; echo "
Issue# $issue
"; echo "
Publisher: $publisher
"; echo "
Date Published: $date
"; echo "
Price: $$price
"; ?>


This is baffling me. I think I do have my files somewhat properly configured because I can view the test.php file no problem. What do you think??
 
Old 11-21-2003, 04:56 PM   #11
froZenX
Member
 
Registered: Sep 2003
Distribution: Fedora, Mandrake 9.2, dare I say a little of M$ Longhorn? Ha.
Posts: 52

Rep: Reputation: 15
thats definitely messed. something VERY internally set up wrong. not the scripts.
 
Old 11-21-2003, 05:46 PM   #12
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
I'm really having no luck here! I followed all the instructions on devside like you said. I even put the test.php file in my root directory, but when I try to run it I just get "Object not found".

The only line I skipped in the instructions was the apxs stuff - but I'm thinking it really doesn't matter.

I really have no idea here.
 
Old 11-21-2003, 07:29 PM   #13
hadding
Member
 
Registered: Oct 2003
Distribution: Redhat 9
Posts: 40

Rep: Reputation: 15
Could try uninstalling Apache & Php. Then reinstall.
This is strange I've never had any problems like that.
I always compile from source with Apache & Php.

Are you doing source or binary installs ?

_h
 
Old 11-21-2003, 08:03 PM   #14
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
php-4.3.4.tar.bz2 is the package I downloaded from the link you gave me.

Does that help at all?

Also, does my php file need to have something like: #!/usr/local/php at the top?

Also, do I need a line like AddHandler php-script php in my httpd.conf???

Thanks for all your help

Last edited by jacksmash; 11-21-2003 at 08:09 PM.
 
Old 11-22-2003, 09:39 AM   #15
mrevilskier
LQ Newbie
 
Registered: Nov 2003
Posts: 10

Rep: Reputation: 0
by the way, put your scripts in /var/www/html and also, in a terminal you could run "php yourscript.php" and see what returns
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP question (newbie) matthewchin Programming 2 12-05-2005 09:46 PM
Newbie PHP question sleepisforwimps Programming 2 08-28-2005 04:06 AM
Kind of a newbie question On PHP compiling. Junior41180 Linux - Software 2 02-10-2005 09:01 PM
Newbie and PHP david63 Linux - Newbie 3 05-08-2003 03:18 AM
Apache newbie question.. (very newbie question) tarballed Linux - Newbie 1 02-07-2003 08:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration