3811 Introduction To PHP

From Coder Merlin
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Prerequisites[edit]

In order to get started with PHP on the CoderMerlin server, you'll first need to make sure you have your www folder set up properly. This should be in your home directory; if it does not exist, then you can create the folder by using the mkdir command:

mkdir ~/www

Once you have created the folder (or if it already exists), you'll need to set up the permissions for the folder. This isn't as hard as it sounds; simply run the following command:

chmod a+rx ~/www

If you ever encounter any "Access denied." error messages, then run the following command, replacing file.php with the full path and filename (e.g. ~/www/index.php):

chmod a+rx file.php

Hello World[edit]

For the first example, we'll simply print "Hello, World!" in your browser. This will help test if everything is set up properly, and is quite simple. Simply create a file called index.php in your www folder with the following contents:

<?php
echo 'Hello, World!';

Once you save the file, you can visit it using your own CoderMerlin URL which takes the form of https://www.codermerlin.com/users/your-user-name/filename

In this case, the filename is simply index.php because we placed the file directly in your www folder as opposed to in a subfolder.

Troubleshooting[edit]

  • Access denied: make sure you have set the permissions properly (see the previous section)
  • Not found: be sure to double check your URL
  • 500 or server error: be sure to verify that you have copied the entire contents of the index.php file; even a single missing semicolon or opening PHP tag can cause this error

If the issue persists, please follow the instructions in W1003_Help_Me!

Background[edit]

PHP (w3 Schools)

Introduction[edit]

Topic Headers[edit]

Key Concepts[edit]

Exercises[edit]

ExercisesExercisesIcon.png
  • Using, HTML and php, demonstrate your ability to:
    • Create a Hello, World! program which displays a php-generated message on a page served from your www directory.
    • Create a page with the numbers 1 ... 1000 each displayed on a new line

References[edit]