Tools for writing PHP programs

See more about:

Where are we?

You know what PHP programs do. Now let’s look at the tools you’ll need to write them.

This lesson’s goals

By the end of this lesson, you should:

  • Know about two approaches to development.
  • Know about two good tools for writing code.
  • Know about a good file transfer program.
  • Know how to install a development server on your computer.

Two development models

There are two general ways to end up with runnable PHP code on a server:

  • Edit your files directly on your hosting account’s server.
  • Get your PHP working on your own computer, then upload the files to your hosting account.

You can do the former, but I don’t recommend it. If you like the Unix command line, you can log in to your Web host and use pico or some other character-oriented editor. Or you can use an editor with FTP support.

There are two problems with this. First, other people might try to access your Web site as you’re working on it. They’ll see a broken site. Second, unless you’re careful with backups, it’s easy to damage a file, and not be able to get it back to a working state.

I recommend the second approach: Get your PHP working on your own computer, then upload the files to your hosting account. That means installing a Web server on your own computer. It’s easier than you think.

You’ll need at least three types of tools:

  • Tools for writing code
  • A file transfer program
  • A local Web server

Writing code

You’ll need software to write PHP code. The same tool should help you write HTML, CSS, and JavaScript as well.

There are two main types of tools you can use: text editors and integrated development environments. There of lots of different options. I’ll just recommend one of each type.

Notepad++ is a free Windows text editor. It has lots of nice features, including syntax highlighting and code completion. You can install it on a portable drive (like a USB stick), so you can carry it around and use it on any PC that is available.

TextMate is often recommended for the Mac, but it’s not free. Aptana and TextWrangler are free options.

An integrated development environment (IDE) is a more complete solution. The one I recommend at the moment is the PHP bundle of Netbeans. The editor is better than Notepad++, and it has things like an integrated debugger. It’s free. You can run Netbeans from a portable drive (like a USB stick), if you want.

You can start with Notepad++ if you like. But you should switch to Netbeans eventually. It will make you more productive. The best thing: it will find some typing mistakes for you! Yay!

File transfer

You can do file transfer from within both Notepad++ and Netbeans, but I prefer using a separate program. I generally get the PHP right, and then upload it as a separate step.

The program I use is WinSCP. It supports FTP, SFTP, and SCP. Easy to use, and free.

Development server

You can use your own computer as a development server. Just install Web server software, and off you go.

Let’s do that now. We’ll be looking at a Windows installation, but other platforms are similar.

Download XAMPP from ApacheFriends. There are Windows, Mac, and Linux versions. It’s easiest to grab the installer, since it does all the work for you.

Run the installer, and install XAMPP at c:\ (for Windows). It will install the Apache Web server, MySQL, and some other stuff.

XAMPP comes with a control panel you can use to start and stop Apache. Run it, and start Apache. It will look something like this:

XAMPP control panel

Figure 1. XAMPP control panel

Now you can use your browser to access Apache on your computer. But what is the URL?

Some IP addresses and domain names are reserved for special uses. The IP address 127.0.0.1 and the domain name localhost always map to the computer you are using. So start your browser, and type http://localhost into the address bar. You should see a welcome page from XAMPP.

W00f!

Now you have a development server. You can create pages, and upload them to your hosting account.

Add a page

You should be able to put files on your disk, and access them through your localhost. But you need to put them in the right place.

If you installed XAMPP at C:\xampp, the root of your Web – your DocumentRoot – will be C:\xampp\htdocs. To make a file available through your development server, all you have to do is copy it to somewhere under C:\xampp\htdocs.

Let’s try it. Create a directory under C:\xampp\htdocs. Called it testthing. Now create a text file with a joke in it, and save it in that directory, under the name joke.txt.

Here’s a screen shot:

Joke file

Figure 2. Joke file

Windows Explorer is in the background (you can see the path and file name). I just used Notepad to make the file. You can see the file’s contents.

Let’s see if it worked. Go to your browser, and enter the URL:

http://localhost/testthing/joke.txt

Joke in the browser

Figure 3. Joke in the browser

If you did everything right, then – wee hoo!

Summary

You can write PHP code directly on your Web hosting account’s server. But it’s better to install a development server on your own computer, and do your programming there.

Notepad++ is a good text editor for PHP work. Netbeans is a good IDE.

WinSCP is good for file transfer.

Download XAMPP from ApacheFriends. It’s an easy way to install a development server.

What now?

Time to dig into PHP. Let’s start with one of the most important uses of PHP, one that gives you a big productivity win: creating dynamic Web templates.


How to...

Lessons

User login

Log in problems? Try here


Dogs