<? PHP To The Rescue ?>

PHP Development

Servers: PHP has been enabled on both the edison and zephir servers for SCCC.  However, our MySQL databases will only be available via zephir.  Please use Zephir to do your class work. Zephir has been set up to REQUIRE secure FTP. For this class you will also need to setup PHP files on an entirely different server.  There are hosting companies that provide free PHP & MySQL web hosting, such as 000webhost Free PHP/MySQL Hosting.

However if you become interested in working with PHP professionally I highly recommend considering Dreamhost or Hostgator.  Using a free host is great for trying out PHP/MySQL, but it's essentially unsustainable (you can't get something good forever for free) and may reflect poorly upon you when you need it most!

File Upload (FTP/SFTP): Since our pages should be on a server to run properly, we need to be able to upload the files to the correct directory. For many Unix/Linux PHP servers, the directory is named public_html, referring to the fact that the files that go there are visible to the public, and are generally HTML files.  Sometimes you'll see an alternate directory named htdocs.  If you are using Dreamhost, the folder is the name of the domain, ie: example.com

Ports: A program designed to upload files frequently uses a file transfer standard called File Transfer Protocol (FTP) and commonly connects to the server via Port 21.  FTP is insecure, however, as the login and password information, and all your files are sent via clear text, and can be intercepted.  For clients we recommend Secure FTP (SFTP) which is not offered by all web hosting companies. SFTP connects to the server by the common port 22.  The port numbers indicate where particular types of data are expected on a computer.  Keeping too many ports open on a computer is considered a security risk.  When we browse the web, the common port number is 80.

Secure FTP: The server we are using for this class (Zephir) requires a Secure FTP application. Therefore, for Windows I recommend WinSCP (Secure Copy & FTP)   (select standalone application). For a Mac most people use the free and open source Cyberduck, which can do both secure and insecure FTP.  Here's a tutorial on how to setup a Secure SFTP connection via Cyberduck

SFTP with Zephir: When using WinSCP, the hostname is zephir.seattlecentral.edu.  For the User Name use your student name (first initial, first 6 chars of your last name, with a possible replacement of a couple of numbers at the end).  The password is the last 6 digits of your student ID.  "horsey01" will be how we refer to your username in this class (first initial, part of last name, etc.)

Physical vs Virtual Path: When we work with web servers we need to be concerned with two different "paths" to reach our files, one from the inside (while logged in via SFTP) and one from the outside (the web). 

The path from the inside we'll call the physical path, represents how the server sets up and stores our files:

/home/classes/horsey01/public_html/

In the above path, the folder named "horsey01" represents your home directory and the root of your server space.  

In the case of Zephir, your home directory (horsey01) is not accessible via the web.  This makes it perfect for storing private data, such as instructions or backups.  The root of your web space is the folder named public_html.

Since the "public_html" folder represents the root of your web space, placing files in the web space allows them to be seen via the web, but also indexed by search engines.  Never put anything private in your web space.  See Google Hacking

Once your web files are uploaded into your web root (public_html) you can view the files via the web at the following URL:

http://zephir.seattlecentral.edu/~horsey01/

The above is the virtual path, where web files can be viewed.  Note the tilde (~) that shows up only in the virtual (web) path.  Tilde means "root" to UNIX/LINUX, so tilde then your username says, "look in my web root".  Remember the web root is public_html, but only from the inside (FTP)!

We need the virtual path (web) for the following types of files & assets:

  • images
  • CSS files
  • JavaScript files
  • Audio/Video files
  • links

We'll be using the physical path for SFTP, file upload, include files and error logging, all of which occur on the inside of the web server.

Remember that the physical and virtual paths can both point to the same file, if the files are in the web space!

Command Line (Shell) Access: We'll need to speak directly to the web server to run commands and work with files and directories.  Later we'll use the command line to access MySQL, the open source database system for this class. We'll need to access the command line via a secure connection, and there is a simple program for Windows machines I recommend called puTTY. On a Mac, use the built in Secure Shell (SSH) in OSX.

Mac OSX comes with OpenSSH.  To put an alias to "Terminal" on the dock, open your Macintosh HD and go to the Applications folder, then Utilities. Terminal is in the Utilities folder. Drag it to an empty space in the Dock. Next, open a terminal window (from the Dock) and type:

ssh -l horsey01 zephir.seattlecentral.edu

Here's more about SSH on a Mac

Development Software: PHP pages can be built and edited with a simple text editor. Some editors are aware of PHP tags, which can color code your source code, once the file is saved with a .php extension. Dreamweaver provides autocomplete, which prompts the developer when typing in PHP functions.  A free windows editor that features autocomplete is Komodo Edit.  For a general purpose free editor, I like the fast, and code friendly Crimson.  Crimson also has a powerful column mode to edit dozens of lines in a vertical fashion at once.  I also use Notepad++ which can run from a thumb drive (good for traveling) and has a great file comparison feature.

Free PHP specific editors include PHP Designer and DevPHP.  Many people also like the Aptana development environment. The ultimate commercial PHP development environment is Zend Studio.

If you are using a Mac, I have heard people use TextEdit, which is built in and free but not perfect. Another alternative is TextWrangler. There are several alternatives: Mac Editor Discussion

File Comparison: The last major software task will allow us to compare files, to be sure of what we're editing.  Notepad++ has file compare built in under plugins.  For bigger jobs on Windows there's a great program named ExamDiff.  For Macs one such program is KDiff3 

Local Development: Some people like to develop on their local machine and upload files to a server later.  The easiest way to develop locally on your computer is to install XAMPP.  There are Windows and Mac versions available.

Programmer Habits: When we work with static HTML our page names may be self evident: for example index.htm, links.htm, etc. With server side code it is common to have numerous include files that are difficult to track.

With all the extra possible files, we should take steps to be certain our project is well documented, from the start.

Since PHP will not run unless the .php extension is used, always use the .php extension on your pages so you can easily add PHP code to a page at a later time without updating links or worry about removing pages that are indexed by search engines.

Server Directory Structure: Careful use of the directory structure is an advantage to a developer. Below is the suggested directory structure for your site, with some descriptions of the purpose and contents of the directories:

Directory Name Contents Note
/ (the web root, no sub folder) Your index.php page and all main linked php pages End all pages with .php extension, for possible later additional code.  Remember the folder for web files has an alias, for example "public_html".
/images/ All image files for the site, spacer GIFs, etc. Customary isolation of image files
/include/ All non-image included web files, CSS, JavaScript, etc. Supporting files that are pieces & parts - these will be only web files (stylesheets and JavaScript files) as later we'll create a special folder for PHP include files
/upload/ all read/write/executable files Isolate any files that are writable as the directory that is writable presents security issues
/demo/ All test pages and model pages we are using for reference Separate files that support your development from the necessary site files - these files would be removed when work on a site is complete
/sandbox/ all example & trivial test files we are working on ITC280 class examples go here - these files would be removed when a site is done


Daily Folders: On your development machine, to keep from overwriting work, and to store work on previous versions of dynamic pages, I suggest keeping daily directories from which to work. This means you create a different directory every day, on your main development machine, with today's date, for example:

/20110906/

The above example would be for the 6th of September, 2011. All of the dated directories should go under a single main folder, perhaps named "Development", and stored in a likely place for backup, perhaps "My Documents".

All work for the day would go into that folder, with work for the next day to be stored in a folder with the next date on it. In a daily folder could go sub-folders for each client or project for the day.

A time may come in which you need to research all versions of a particular page, and then you can search over all the folders in your development environment. Backing up the contents of all your daily folders and burning them to CDs at regular intervals is advised.

Developer Habits

Backup your files. Backing up files in a server side programming environment is so important that I will require this for the class. Backing up your files does not mean storing your only copy of a file on a floppy disk. By backup, you must have a second copy of all critical files in more than one physical location.

Document your code with extensive comments. At this stage, it is difficult to imagine including too much documentation in your code. Make sure there is a basic description of the page functionality, with dependent pages (if any) listed as well.

Always complete your curly braces before you fill in the applicable code. It is difficult to troubleshoot for this issue, if you don't start with this habit early.

Never work directly on a floppy disk/Network Drive/Thumb Drive. Work on a hard drive, and copy your data to a floppy/Thumb drive, and to the server, thereby fulfilling your "backup" requirement. Never work (in ANY language or even with a critical WORD document), directly on a volatile drive, as you may lose ALL your work!

Take a Notebook Everywhere (and write in it). As you develop you want to stay focused and not lose important things.  Keep a simple spiral bound notebook with you to write down things like:

  • Great Ideas
  • Goals
  • Shopping (and any) Lists
  • Time spent on projects
  • Diagrams of concepts

Having the notebook handy (and well used) frees you to focus on the other tasks at hand!  Try it!

Create your PHP Spellbook. Create a folder or book with printed copies of all important examples and pages you are working on. Having a printed copy allows you quick access to work you have already created, and allows you to highlight, or draw arrows or notation on a page in a manner not possible in electronic form. The Spellbook is not a requirement for the course, but is highly recommended.

Print this Page Back To Top

© 2000- 2012 newMANIC INC, All rights reserved