A tutorial on…creating, uploading and running a PHP script

To begin, open an appropriate text editor. Likewise with HTML documents, PHP files are made up of plain text, thus sufficient for use in editors such as Notepad and BBEdit on Mac OS.

Type in the example found below:

1: <?php
2: phpinfo ();
3: ?>

Save it as phpinfo.php in your web server’s root document directory. If you are using a web hosting server, upload it to the server to where you would place HTML files.
The coding above basically allows information about the PHP installation to be outputted to the browser. I discovered that the phpinfo() part is useful for debugging scripts due to the context information provided.

The extension to the PHP document is important because it tells the server to treat the file as PHP code. The default PHP extension for a PHP document is .php.

After the document is saved, you should be able to access it via your browser. If everything has gone accordingly, you will see the scripts output on screen. Open up your web browser and go to either; http://localhost/phpinfo.php, or http://your-web-hosting-server.com/phpinfo.php if you are using a web hosting server.

(Note: You will need to make sure MySQL is enabled, as you will need this previously installed in-order to complete the test. This can be installed as part of a multi-package available from here: http://www.apachefriends.org/en/xampp-macosx.html)

Background Research

I discovered some information on how different operating systems use different character combinations to denote the end of a line of text. It is essential to save your PHP documents with the correct line breaks for the operating system that runs your server. A document with the wrong line breaks for the operating system might be read as a very long line of text by the PHP engine. This won’t cause any specific problems, however bugs may evolve.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: