Diving into PHP
Part 1: Getting Started with PHP
Welcome to the 1st installment of Diving into PHP. This is a free online ebook or workshop written by Joshua Drake in an effort to teach those who are willing how to be a multifaceted web developer. As this is an individual project, it will take me a long time to reach completion, but I hope everyone will follow along and learn something. In this series, I will be jumping back and forth between languages (have no fear, I will remain highly organized with this) in an effort to demonstrate the best tools for the job in my opinion. Throughout this project, I will be supplying sample code to copy / paste, downloadable snippets, as well as demonstrations.
These articles will all be accessible to The Admin Zone community, my personal tutorial / resource site Drake Technologies, as well as Good-Tutorials.com and possibly others. If anyone has any questions, feel free to leave a comment. This is considered a 'workshop', so I'm expecting comments, concerns, questions, everything.
This particular article will serve as a crash course, teaching you how to install the software you will need to start with. With all of these articles, it is assumed that you have a basic knowledge of HTML, as these concepts will be very lightly demonstrated throughout. Within the course of this series of articles, expect to learn the following items right off the bat:
- Installing PHP / MySQL for testing purposes
- Inserting PHP snippets into HTML code
- Displaying text using PHP
- Basic Predefined functions
- and more...
This will be the easiest tutorial of the PHP part of the series. Just remember, if you have any questions, feel free to contact me. If anyone has any corrections or disputes with the information, feel free to comment as well. Now let’s get started!
Setting Up Your Environment
Apache / MySQL / PHP Setup
Some PHP books or guides will go over setting up a complete LAMP/WAMP (Linux/Apache/MySQL/PHP or Windows/Apache/MySQL/PHP) setup, but I feel if you want a complete test environment this approach is not only unnecessary, but a waste of time when you are trying to learn. Not that it isn't something you shouldn't be concerned with once you are up to speed and creating advanced programs and need to fully test system functionality and resource usage, but for now, and for the scope of this guide, it is unwarranted. For this guide, I will recommend you setup XAMPP.
To setup an installation of XAMPP, you should head to their website and download the latest copy. Then, as an administrator, run the installer as shown in figure 1.1.
Figure 1.1 - Running the installer
As the installer loads, the very first thing it will ask you is where you would like to install it. For the purpose of this tutorial, we have selected the root of your hard drive, or for Windows users (this tutorial is being written using my server, with Windows Server 2003 Enterprise as the operating system) the root would equate as C:\. Refer to figure 1.2 for details.
Figure 1.2 - Setting the installation directory
Now that that's taken care of, go ahead and click install. After the installer has installed all of the necessary files, it will bring up a DOS style prompt asking a few questions. I recommend selecting 'y' to allow desktop shortcuts (for ease of access to the XAMPP Control Panel), 'y' to locate the XAMPP paths correctly, and 'n' to not make portable drives. The last option is entirely up to you, but for the scope of this guide it's not necessary. Refer to figure 1.3 to see what I'm talking about.
Figure 1.3 - Configuring XAMPP post-install
Once this is taken care of, the DOS style screen should change to a more advanced menu. Simply select '1' to start the XAMPP Control Panel, then 'x' to exit. An example is in figure 1.4.
Figure 1.4 - Starting the xCP
Now that the control panel is up, click on the check boxes located next to 'Svc' alongside Apache and MySQL to run both of these as background services and click 'OK' to confirm. Next, start both of these services by clicking the 'Start' button. Refer to figures 1.5 and 1.6 to see what you're looking for.
Figure 1.5 - Creating Services
Figure 1.6 - Starting services
As long as everything went as planned, you should be able to load up your favorite browser and load http://localhost or http://127.0.0.1 and get XAMPP's default start page as referenced in figure 1.7. Now, it's a good idea to go to C:\xampp and create a shortcut of the 'htdocs' folder to your desktop for reference. This folder is the root to your private webserver and any folder you create will create a folder on your server. For example, if you create htdocs/test, and you load up http://localhost/test, it will direct you to any content in that folder.
Figure 1.7 - The finished product
PHP can be written in any text editor, but it is imperative that the editor uses raw text (meaning no MSWord, etcetera). The editor I use on a day-to-day basis is Dreamweaver, but as many of you know it's an Adobe product and it isn't free, or cheap. For those simply learning, it's much easier if you don't already have it lying around (I was discounted through a student program many moons ago), use something open source (or free) such as Notepad++. It's contextual, much like Dreamweaver, and does the trick. Just as a quick note, while Notepad++ is contextual, it isn't considered a WYSIWYG editor, considering you still have to format your own code by hand.
Setting up this program is so easy in fact, that I only have one image (not that XAMPP was that much more difficult). Simply download the file from the website, and run the installer. After using the default settings, run your new application. The only thing you have to setup that isn't in the defaults is go to Language, highlight P, then select PHP as shown in the image.
Figure 1.8 - Setting up Notepad++
While this lesson hasn't really given you any information on how to code...well...anything, it is designed simply to get the software for the rest of the series into your skill set. After you have everything installed, go ahead and play around with it and get acquainted. Make a few sample pages or your own website using these programs using HTML.
As mentioned, feel free to leave comments with any questions, and I'll get back to them as soon as possible. I'm going to begin preparing for the first real PHP lesson, "Creating Your First Page", an introduction to the PHP tags, comments, and echo / print statements.
Until next time.