Hi! I’m trying to pick up PHP from the book"PHP and MySQL Web Development Fourth Edition Developers Library". I have experience with Java/C/C++/XHTML/CSS/etc… but PHP is new to me and I having trouble getting output from my hello world tinkering experiment. Here is my code:
[i]
Hello World!
<?php
echo '
Hello World!
';
?>
[/i]
AND…here is my output:
[i]Hello World!
'; ?> [/i]
My issue is the ';?> at the end of my code (which is SUPPOSED to be the closing quote for the echo parameters and the php tag close as well as the end line ;
I’m not really sure what the issue is here. I’ve tried " as well as ’ and I just can’t get it to stop!!! It is very frustrating. I’m editing using Notepad and using Firefox (one of the latest versions) to view the result. The file extension is HTML not PHP. I have tried PHP as well to no avail. Internet Explorer doesnt even try! It just views the code!!! Please help
I renamed the file to a .php extension, and I am still getting the same output. I am using a Windows box as instructed by the book, so I don’t think Apache is the issue. I need help with this output issue. Have the standards of PHP changed recently that would cause such an issue? This book is a year old.
Okay! Problem solved! In case anyone else attempts to debug/test PHP on their windows machine, here is an overview of what you need to do to get this working! It isn’t just as easy as using JS or HTML/CSS, you actually have to configure windows IIS in order to use PHP! The problem is that since PHP is a server side script, it needs a server application to adequately interpret the PHP code before displaying the resulting HTML on your web browser! Follow these steps and you should be good to go!
First of all, you need PHP (obviously). Go to the PHP download page and grab the latest non-thread-safe ZIP archive for Windows. As of writing this, the package is called “PHP 5.2.8 Non-thread-safe zip package”. Unzip the archive to a folder on your hard disk (I use C:\php5) and create a copy of php.ini-recommended (or php.ini-production in recent PHP versions) called php.ini. There, add the following configuration setting:
cgi.force_redirect = 0
This is the minimum setting you need to change to make PHP work with IIS.
2 )Then it’s time to install IIS. You need at least the “Business” version of Windows 7, but the currently available beta 1 is Windows 7 Ultimate anyway. Go to Start/Control Panel/Programs/Turn Windows Features on or off and check on the Internet Information Services entry. Activate the World Wide Web Services/Application Development Features/CGI node and also Web Management Tools/IIS Management Console. Now, start the IIS Management Console; just open up the start menu, enter inetmgr and hit Enter. There, navigate to the Sites/Default Web Site/Handler Mappings node and double-click on the “Handler Mappings” entry.
As a result of this, the Actions panel on the right hand side changes. You now see an option called Add Module Mapping. Clicking on it opens up a dialog! If you do not see the FastCgiModule entry, you probably forgot to check the CGI node when installing IIS. Otherwise, close the Add Module Mapping dialog by clicking on OK. You need to confirm that you want to create a FastCGI application; click Yes. Finally, create a .php script and put it in the root folder of the IIS site (by default C:\Inetpub\wwwroot; note that you may need additional rights to write into that directory), e.g. phpinfo.php with a simple phpinfo() call in it. Call this script using http://localhost/phpinfo.php, and you are done!
So if you want to debug any PHP script, simply place it in the c:\inetpub\wwwroot folder and call it by using http://localhost/INSERTSCRIPTNAMEHERE.php. So most of your coding should be saved in this folder! You may also need more permissions in order for your scripts to write to your drive.
I use WAMP, which stands for Windows Apache MYSQL PHP. In other words, when you download WAMP, it automatically installed The Apache Server, Configured with PHP and MYSQL databse ready to use. It’s hassle free. All you need to remember is to place the php files inside the wamp/www folder that’s created in your c: drive, or whatever drive you chose at installation. There other web servers like XAMP, MAMP (for Macs), etc. that you can use with similar results.
Again, this is when you want to work and test from your local machine. Alternatively you can upload your files to a web host where everything should be set up beforehand. You might need to manage the database, if you are using one.
I find trying to configure IIS to be a hassle for those people like me who are not network administrators.