First of all, this is my very first post on Sitepoint's forums, and i am thrilled to include myself in such a vast ocean of helpful design resources, so just wanted to get that out of the way..... Ok, onward then; I am reading Build Your Own Database Driven Web Site Using PHP & MySQL by Kevin Yank. So I am past installing all of MySQL, PHP, and Apache, and then uploaded the a php file (called today.php - which is intended to display the current date) to my (apache) server's root directory. All fine, except the issue arises when i then look up the directory via my browser (http://localhost:8080/today.php). The browser simply displays the exact code that I typed, without actually processing the code (html and php) itself, and then outputting the functions.... anyone able to enlighten me to why this is? Any help greatly appreciated, just trying to get on my feet and learning so I can get some things actually done. thanks everyone!
Are you using Windows with it set to hide common file extensions? If so then most likely the real filename is today.php.txt and so since it is a .txt file it would just have its content displayed.
That's about the only reason I can think of for the code appearing exactly as typed. If it was recognising HTML then it wouldn't display all of the content as text.
Right, I'll check that one again.... I typed up the code using Mac Dreamweaver 8 - saving as a .php file ext., so it really shouldn't be the issue at all.... very perplexing, and a really small thing to be tripping me up (so early)! oh well, im sure i will get around it, even if i gotta reinstall everything. I spose i don't NEED it right immediately, however, this is an awesome and valuable developing tool; to be able to TEST a site on a server before it is published, therefore I really want to get this working. Thank You for a response!
Also ensure that you're using <?php and not just <? as php doesn't always have short tags turned on.
You may also want to consider downloading an all in one preconfigured Apache, PHP and MySQL setup such as XAMPP or the UniformServer. With these you literally extract them from the archive, save the directory to your c: drive and run - it's all setup with no testing , config problems etc. The best thing is you can even put them on a usb drive and run it on any computer. I personally use the uniformserver as xampp takes a lot of diskspace but both are very good.
Yes, it's probably something wrong with the PHP/Apache/MySQL setup. As said above, it's easier to install and all-in-one solution, which would be MAMP for you on a Mac. As the book says, it's better to understand how to set up all those programs individually, though.
Locate your Apache config file which should be called httpd.conf and in that file look for a line that reads something like:
LoadModule php5_module "c:/wamp/bin/php/php5.3.0/php5apache2_2.dll"
The file location will obviously be different. Once you've found that line, does it have a # at the start of it - if so remove the # from the start of that line, save the file then reboot the server.?
If that line exists and doesn't have a # at the start of it (is the file location for yourself correct?), have a look for a section in the same file which will look something like:
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
# AddType allows you to add to or override the MIME configuration
# file specified in TypesConfig for specific file types.
#AddType application/x-gzip .tgz
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .php5
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#AddHandler cgi-script .cgi
# For type maps (negotiated resources):
#AddHandler type-map var
# Filters allow you to process content before it is sent to the client.
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml
There should be a line in that section.
AddType application/x-httpd-php .php
If it's missing then add it with the rest of the AddType application lines, save the file then reboot the server.