Pin Me

A Guide to Linux Programming with PHP

written by: Berry van der Linden•edited by: Christian Cawley•updated: 1/29/2011

This is the first article in a series for programming with PHP in Linux. This article will provide you with a brief introduction to the open-source PHP language and show you how to set up your Linux, Apache, MySQL, PHP programming environment and code your first PHP application. Excited?

  • slide 1 of 5

    Introduction

    Example using Nano What is PHP? PHP is a recursive acronym stands for PHP Hypertext Preprocessor. In your hours spent trawling the Internet you have probably come across PHP numerous times. You may not know how powerful the language is, and what it can do and you may not have even seen any PHP code before now! PHP has the awesome position of being the only open-source server-side scripting language that's both powerful and satisfying to learn!

  • slide 2 of 5

    Why Use PHP?

    HTML is completely static. By using and HTML, we can create dynamic sites that will change depending on certain conditions. Not to mention that PHP is powerful, scalable and best of all, free. Data-driven applications can be mashed up quickly with the built-in database support in PHP, add an excellent manual, a friendly community and a price of zero - and you've got my favourite programming language!

  • slide 3 of 5

    Setting Up Your Environment

    As with all programming languages, before you begin to staring programming PHP, you need to have a development environment set up on your box. In the following PHP tutorial we will be using PHP with the Apache Web server running on Linux. However, you can just as easily use PHP with Apache on any operating system. Detailed instructions on how to set up a LAMP (Linux, Apache, MySQL, PHP) development environment on are here, in another of my articles.

  • slide 4 of 5

    Learning Some Syntax

    PHP code sits inside a page with the HTML, as with HTML it is made up of plain-text. Therefore, a page that shows "We are about to learn some awesome PHP skillz (yes, skills with a z)" would be inside an HTML page named filename.php like this:

    <html>

    <head>

    <title>Bright Hub Article</title>

    </head>

    <body> <p>That is some simple PHP code below:</p>

    <?php

    echo 'Hi, my name is Josef';

    ?>

    </body>

    </html>

    See? The HTML is rendered as HTML and the code between the <?php and ?> gets executed as PHP.

    You may notice some instances where the "php" after the question mark is missing. This is a lazy practice known as "PHP short tags" - full tags should always be used! Also, PHP statements end in a semi-colon, however, a semi-colon is not required to terminate the last line of a PHP block, as the PHP closing tag ?> contains a semi-colon.

  • slide 5 of 5

    Next Time

    I hope you enjoyed this brief introduction to PHP and that you come back for part two! In the next article we will take a look at more statements, how to comment and execute your beautiful PHP code!

A Guide to Linux Programming with PHP

In this series of articles I'll be teaching you the basics of using PHP, and showing you why I think it's the best language for web development. There are no pre-requisites for your level of knowledge, other than that you can understand basic HTML and are willing to learn.
  1. A Guide to Linux Programming with PHP
  2. A Guide to Linux Programming with PHP - Commenting and Executing Code
  3. A Guide to Linux Programming with PHP - Variables & Data Types
  4. A Guide to Linux Programming with PHP - HTML Forms and PHP
  5. A Guide to Linux Programming with PHP - Arrays
  6. A Guide to Linux Programming with PHP - Associative and Multidimensional Arrays