LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2005, 07:01 PM   #1
rhb327
Member
 
Registered: May 2004
Distribution: Slackware Current
Posts: 161

Rep: Reputation: 30
Apache PHP help


Hi! I'm trying to setup up a web page that will eventually be hosted but I want to develop it locally. It will use PHP to hit a MySQL database. So I have a local database created. I installed PHP and Apache. Next I thought I would do some basic PHP tests as I don't know anything about PHP or Apache. So here is where my snag is.

1) I can execute at the command line:
who@where:/var/www/htdocs$ php -r 'echo "hiya\n";'
hiya

so this seems to work and makes me think PHP is a ok.

2) If I have /var/www/htdocs/my_web/test.php as following:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
what
<?php echo('hiya\n'); ?>
</body>
</html>

an open test.php in firefox I get nothing at all

3) If I have /var/www/htdocs/my_web/test.php as following:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
what
<?php echo('<p>hiya\n</p>'); ?>
</body>
</html>

an open test.php in firefox I get:

hiya\n

'); ?>

So forget logging into my database just yet! What am I doing wrong? It seems PHP is not being processed correctly via Apache but based on the PHP command line I think the problem is in Apache? Perhaps a missed configuration? I've been trying to use the tutorial here:

http://us3.php.net/manual/en/tutorial.firstpage.php

to get a grasp but I'm in a holding pattern until I can get these simple examples to work! In addition, I'm currently running my MySQL database from /var/lib/mysql/my_db...when I go to host this will it be stored in my main web directory? If so, can I make this db run from /var/www/htdocs/my_web to simulate this in my local development?

Thanks!
 
Old 03-14-2005, 10:07 AM   #2
rhb327
Member
 
Registered: May 2004
Distribution: Slackware Current
Posts: 161

Original Poster
Rep: Reputation: 30
I got a hit on comp.lang.php regarding this. I won't be able to test until later though. I was opening the file in firefox using File->Open File...the suggestion is to use http://localhost/my_web/test.php.

I'll post back regarding this. I think this is right though because when I used File->Open and then did a view source the php tags were still there so it's as if firefox in interpretting the raw html in test.php as best it can.
 
Old 03-14-2005, 11:50 AM   #3
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
The problem isn't with your PHP, but rather with your HTML

Quote:
<?php echo('hiya\n'); ?>
This gets ignored because there are no HTML tags to handle it, so Firefox does the right thing and doesn't display it.

Quote:
<?php echo('<p>hiya\n</p>'); ?>
Again, by displaying hiya\n Firefox is doing the right thing because \n has absolutely no meaning in HTML and Firefox is treating it like the rest of the text you are asking to be echoed. What you need to do to display it properly is

<?php echo(''<p>hiya</p><br>'); ?>

Last edited by Hangdog42; 03-14-2005 at 11:51 AM.
 
Old 03-14-2005, 12:34 PM   #4
rhb327
Member
 
Registered: May 2004
Distribution: Slackware Current
Posts: 161

Original Poster
Rep: Reputation: 30
Hmmm, your suggestion still failed when using File->Open mehtod but I will certainly remove the '\n' from the command line test for the php file.

Thanks
 
Old 03-14-2005, 01:56 PM   #5
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
PHP is a server side scripting language meaning that, any php pages should be processed on the web server and then the output sent to your browser. The right way to view them is to use the http://localhost/path/to/script.php and not opening them using the file dialogue. Also, if you want to use escape characters like the newline, use double quotes instead of single quotes, so from your example, the right code would be.
Code:
<?php 
echo "<p>Hiya</p>\n";
?>
The newline doesn't do anything for html, but when you look at the source via your web browser, any code after the php code will be on a new line.
 
Old 03-14-2005, 06:23 PM   #6
rhb327
Member
 
Registered: May 2004
Distribution: Slackware Current
Posts: 161

Original Poster
Rep: Reputation: 30
I have http://localhost/my_web/test.php in the URL textbox and for the code you gave reddazz:

<?php
echo "<p>Hiya</p>\n";
?>

I see this in firefox:

Hiya

\n"; ?>

Here's the entire contents of test.php:

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
echo "<p>Hiya</p>\n";
?>
</body>
</html>

I also tried:

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
echo ("<p>Hiya</p>\n");
?>
</body>
</html>

I also cleared the cache to ensure it would reload. I believe the server is working to some extent becaue when I stop it and try to the load the page I get a connection refused.

Any other ideas?

Thanks,
Rich
 
Old 03-14-2005, 06:42 PM   #7
pave
Member
 
Registered: Oct 2004
Posts: 42

Rep: Reputation: 16
Investigate your php.ini file. I think that the problem is related with parsing magic quotes. What happens if you abort omit \n ?
 
Old 03-14-2005, 07:53 PM   #8
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
Both your srcipts works fine on my system using php 4.3.10 and php 5.0.3, so I guess there is a problem somewhere on your version of php or its configuration file.
 
Old 03-14-2005, 09:27 PM   #9
rhb327
Member
 
Registered: May 2004
Distribution: Slackware Current
Posts: 161

Original Poster
Rep: Reputation: 30
Ok, some additional information:

--------------------------
php --version
PHP 4.3.7 (cli) (built: Jun 5 2004 00:11:51)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

-------------------------
pave:
Without the \n so test.php is:
Code:
<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
  <?php 
  echo ("<p>Hiya</p>");
  ?>
 </body>
</html>
firefox directed to http://localhost/my_web/test.php shows:
Code:
 Hiya

"); ?>
--------------------------
I'll start digging into php.ini but here are some quick points:

1) This is a Slackware 10.0 install.
2) /etc/apache# diff php.ini php.ini-recommended outputs nothing at all
3) /etc/apache# diff php.ini php.ini-dist outputs alot
4) php.ini is 1100+ lines long so here's the output of cat php.ini | grep magic:
Code:
 cat php.ini | grep magic
; - magic_quotes_gpc = Off         [Performance]
magic_quotes_gpc = Off
magic_quotes_runtime = Off
; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off
;extension=php_mime_magic.dll
Any insight is much appreciated...thanks!
 
Old 03-15-2005, 07:09 PM   #10
rhb327
Member
 
Registered: May 2004
Distribution: Slackware Current
Posts: 161

Original Poster
Rep: Reputation: 30
Well, I tried both:

cp php.ini-recommended php.ini

AND

cp php.ini-dist

restarting the http server in between with no difference. So I'm still not successful with even the most basic PHP commands. I scanned the php.ini files trying to familiarize myself with the options and the magic quotes certainly seems suspect. When using the php.ini-recommended (magic quotes off) I tried to escape manually like:

echo \'<p>Hiya</p>\';

and using

http://localhost/my_web/test.php

in the URL input box with similar results as before:

Hiya

\'; ?>

Any other suggestions?
 
Old 03-15-2005, 07:34 PM   #11
rhb327
Member
 
Registered: May 2004
Distribution: Slackware Current
Posts: 161

Original Poster
Rep: Reputation: 30
Hey, it works!

# ==> mod_php configuration settings <==
#
# PACKAGES REQUIRED: openssl-solibs (A series) and/or openssl (N series),
# mysql (AP series), gmp (L series), and apache (N series)
#
Include /etc/apache/mod_php.conf

I had to uncomment this enabled in /etc/apache/httpd.conf. I'm trying a basic
connect to my mysql database now.

Thanks for all the help.
 
  


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
Apache 2, PHP 5, SuSE 9.2 - cannot run php files dickohead Linux - Networking 6 06-28-2006 10:25 AM
php apache or php cgi - php learner rblampain Linux - Security 3 12-17-2004 11:10 PM
slackware, apache and PHP from .tgz - problems with PHP szymon Slackware 2 09-06-2004 04:57 PM
reinstalled apache, php, still no php support SuSE 8.2 hindenbergbaby Linux - Software 1 10-14-2003 01:42 PM
php-nuke with apache php mysql c0c0deuz Linux - Software 0 03-30-2003 06:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:08 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