Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
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?
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.
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 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.
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.
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.
--------------------------
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
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:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.