New to PHP

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
Carlo Gambino
Forum Newbie
Posts: 9
Joined: Mon Jul 21, 2008 10:40 am

New to PHP

Post 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?
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: New to PHP

Post 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");?>
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: New to PHP

Post 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.
Carlo Gambino
Forum Newbie
Posts: 9
Joined: Mon Jul 21, 2008 10:40 am

Re: New to PHP

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: New to PHP

Post 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"
Carlo Gambino
Forum Newbie
Posts: 9
Joined: Mon Jul 21, 2008 10:40 am

Re: New to PHP

Post by Carlo Gambino »

I was looking for httpd.conf to find it blank. Are there guidelines for setting this file up?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: New to PHP

Post 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?
Carlo Gambino
Forum Newbie
Posts: 9
Joined: Mon Jul 21, 2008 10:40 am

Re: New to PHP

Post by Carlo Gambino »

I installed them individually.

Also, I'm using a LAMP setup, windows makes me uncomfortable.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: New to PHP

Post 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.
Doug G
Forum Contributor
Posts: 282
Joined: Sun Sep 09, 2007 6:27 pm

Re: New to PHP

Post 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.
Carlo Gambino
Forum Newbie
Posts: 9
Joined: Mon Jul 21, 2008 10:40 am

Re: New to PHP

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: New to PHP

Post 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 :)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply