Introduction to PHP
We’ve talked a bit about PHP in class with Carolina lately, and a lot of people are having problems getting anything to work.
Introduction
PHP is a server-side scripting language, and as such the server (Your computer, or your remote server) MUST have PHP installed in order for any PHP to be rendered. If PHP is not installed, your PHP will be displayed in your browser as plain text, and no code will execute.
Getting PHP Up and Running
You already have IIS (Windows web server) installed, so you can install PHP on it, or you can do it the easy way by downloading XAMPP and letting it install/ configure everything for you: Apache (Web Server), MySQL, PHP, PHPMyAdmin (Web-based administration tool for MySQL).
So, start by downloading XAMPP here: Windows Installer
Run the installer and follow the instructions; it should be pretty self-explanatory. When the setup is complete, make sure to turn off IIS by clicking on Start > Settings > Control Panel > Administrative Tools > Services
Rightclick on the “IIS Admin Service” service, and click “Stop” from the menu. If you don’t turn IIS off, Apache will conflict with it and you’ll run in to problems. Note that this doesn’t permanently disable IIS or change anything, it just shuts it off temporarily.
Once IIS is shut down, go into your web browser, and in the address bar, type in “localhost”. You should be presented with an XAMPP welcome screen; congratulations, you now have Apache, PHP, and the whole shibang running.
Apache has a specific directory that it reads from as the place where your local web files are; the default when XAMPP installs it is “C:\Program Files\xampp\htdocs\” . This is the directory you are taken to when you go to localhost in your browser. If you make a sub-directory called “Mydir”, the address would be http://localhost/Mydir . You MUST place your html, php files and anything else you want to access in your browser within the “C:\Program Files\xampp\htdocs\” directory.
Once you’ve got that down, open up your favourite editing software (Apatana, Notepad++, or god forbid Notepad), and write the following:
<?php
phpinfo()
?>
Save that file to the “C:\Program Files\xampp\htdocs\” directory as “test.php”. Now go into your browser and in the address bar, type in: http://localhost/test.php If you see a page entitled, “PHP Version 5.2.1″ with all the information on your computer, web server, and php information, congratulations, you just wrote your first PHP file. phpinfo() is a built-in PHP function that displays the information mentioned above.
You can now write your own PHP and experiment. Don’t forget to use gotAPI.com when you’re playing with PHP, it’ll help you out with functions, methods, syntax, and generally getting your scripts to work. I’ll also post some PHP tutorials and links soon.
If you have any questions, post a comment!
Filed under: Data Structures for the WWW, Databases, Tools, Web Programming
