Page 1 of 1

New to PHP

Posted: Mon Jul 21, 2008 10:46 am
by Carlo Gambino
Hello,

I have recently decided to experiment with my own LAMP server and consider creating and hosting my own web dynamic web pages. I have configured everything correctly to this point (I think). I haven't made the server accessible from the outside yet, but can access it on my network and can see my index.htm page.

I created a small php file to see if I've done it right:

Code: Select all

<HTML>
<HEAD>
<TITLE>PHP Testing</TITLE>
</HEAD>
<BODY>
<?php
echo "if this works, we <i>really</i> did it!";
?>
</BODY>
</HTML>
when I call the file in a browser, I see the code, not the echo'd text. The code Looks correct to me, but I am super new at this. Is it the code or the configuration?

Re: New to PHP

Posted: Mon Jul 21, 2008 2:26 pm
by JAB Creations
Hi Carlo and welcome to DevNetwork!

It's advisable to post the code in question, otherwise we can't help you out on the specifics (or many times at all).

This includes example should work just fine...

Code: Select all

<?php include("menu.php");?>

Re: New to PHP

Posted: Mon Jul 21, 2008 3:35 pm
by califdon
Carlo Gambino wrote:Hello,

I have recently decided to experiment with my own LAMP server and consider creating and hosting my own web dynamic web pages. I have configured everything correctly to this point (I think). I haven't made the server accessible from the outside yet, but can access it on my network and can see my index.htm page.

I created a small php file to see if I've done it right:

Code: Select all

<HTML>
<HEAD>
<TITLE>PHP Testing</TITLE>
</HEAD>
<BODY>
<?php
echo "if this works, we <i>really</i> did it!";
?>
</BODY>
</HTML>
when I call the file in a browser, I see the code, not the echo'd text. The code Looks correct to me, but I am super new at this. Is it the code or the configuration?
How are you opening the file, just by using File Open or whatever your browser calls it? That won't be going through your server, so it won't be interpreting any PHP. (For example, you can open HTML files on your hard drive in your browser even if you don't have a server installed!) What you have to do is something like: localhost/helloworld.php. You have to have the helloworld.php file in the "document root" that is defined for your Apache server.

Re: New to PHP

Posted: Mon Jul 21, 2008 4:39 pm
by Carlo Gambino
Thanks for the welcome and feedback.
It's advisable to post the code in question, otherwise we can't help you out on the specifics (or many times at all).
I listed the code that created my test file in the original post. I believe the code is correct, I will be looking into my configuration to figure out the problem.
How are you opening the file, just by using File Open or whatever your browser calls it? That won't be going through your server, so it won't be interpreting any PHP. (For example, you can open HTML files on your hard drive in your browser even if you don't have a server installed!) What you have to do is something like: localhost/helloworld.php. You have to have the helloworld.php file in the "document root" that is defined for your Apache server.
I called the document from the browser of another machine. I am able to see HTML files, but whenever I put php code in (and change the extension to .php), the output is the code, not the expected echo'd text.

Re: New to PHP

Posted: Mon Jul 21, 2008 4:58 pm
by califdon
That does sound like Apache isn't configured properly. Review your httpd.conf file. Be sure the paths are correct in the lines that look like this (your paths will probably be different):

Code: Select all

PHPIniDir "C:/Program Files/PHP/"
LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll"

Re: New to PHP

Posted: Tue Jul 22, 2008 3:18 pm
by Carlo Gambino
I was looking for httpd.conf to find it blank. Are there guidelines for setting this file up?

Re: New to PHP

Posted: Tue Jul 22, 2008 5:51 pm
by califdon
Carlo Gambino wrote:I was looking for httpd.conf to find it blank. Are there guidelines for setting this file up?
Oh, wow! Something bad happened when you installed your Apache web server! That should be a very large file! You should reinstall Apache, then PHP. Did you install each of them separately or use one of the WAMP server packages that installs everything at once?

Re: New to PHP

Posted: Wed Jul 23, 2008 12:16 pm
by Carlo Gambino
I installed them individually.

Also, I'm using a LAMP setup, windows makes me uncomfortable.

Re: New to PHP

Posted: Wed Jul 23, 2008 2:03 pm
by califdon
Carlo Gambino wrote:I installed them individually.

Also, I'm using a LAMP setup, windows makes me uncomfortable.
Sorry for jumping to conclusions. I fully understand your discomfort. Usually Apache installations come with a default config file and often with several special config files for particular setups, such as virtual hosting. The file will probably be over 400 lines in length. Currently I don't have Apache installed on my Linux machine, so I can't directly give you the filenames, etc., but if you will Google linux apache config, you will find many good references. Probably all you will need to do is copy one of the existing config files to httpd.conf. Then if PHP still doesn't work, you will only have to uncomment or add a couple of lines to the file.

Re: New to PHP

Posted: Wed Jul 23, 2008 5:43 pm
by Doug G
In case you're not, you need to open php pages through your webserver by pointing the browser to something like http://localhost/myphppage.php

If you try to directly open a php page from the filesystem, you'll just see the php code since the page is not going through a web server to interpret the php.

Re: New to PHP

Posted: Wed Jul 23, 2008 7:51 pm
by Carlo Gambino
Thanks again for the input!

I overlooked one part of the configuration. I was considering using ISPConfig, which suggested disabling php globally to be enabled on a per site basis:

Code: Select all

vi /etc/mime.types
and comment out the following:

Code: Select all

[...]
#application/x-httpd-php                         phtml pht php
#application/x-httpd-php-source               phps
#application/x-httpd-php3                        php3
#application/x-httpd-php3-preprocessed     php3p
#application/x-httpd-php4                        php4
[...]
So I removed the "#" and now php seems to be working. Upon reviewing httpd.conf, the file is still blank, but my phptest.php page displays the php info.

Re: New to PHP

Posted: Thu Jul 24, 2008 1:16 am
by VladSun
califdon wrote:
Carlo Gambino wrote:I was looking for httpd.conf to find it blank. Are there guidelines for setting this file up?
Oh, wow! Something bad happened when you installed your Apache web server! That should be a very large file! You should reinstall Apache, then PHP. Did you install each of them separately or use one of the WAMP server packages that installs everything at once?
Debian and derivatives ;)

Code: Select all

/etc/apache2# ls -l
-rw-r--r-- 1 root root 24198 2008-01-24 23:01 apache2.conf
-rw------- 1 root root  2189 2008-01-31 17:14 apache.pem
drwxr-xr-x 2 root root  4096 2008-01-22 12:01 conf.d
-rw-r--r-- 1 root root   895 2007-09-19 22:45 envvars
[b]-rw-r--r-- 1 root root     0 2008-01-22 12:01 httpd.conf[/b]
drwxr-xr-x 2 root root  4096 2008-01-22 13:42 mods-available
drwxr-xr-x 2 root root  4096 2008-01-23 13:33 mods-enabled
-rw-r--r-- 1 root root    21 2008-01-23 13:41 ports.conf
drwxr-xr-x 2 root root  4096 2008-01-23 13:42 sites-available
drwxr-xr-x 2 root root  4096 2008-01-23 13:43 sites-enabled
 
I suppose you use Slackware, califdon :)