By not even trolling I don't mean that I won't troll PHP, but that this is a legitimate help resource.

Installation

The great news is that with PHP 5.4+ it can run a self-contained web-server that can behave just like Python, Ruby, or other programming languages.

Depending on the OS, it may be a little more hassle to install:

For OS X head on over to http://php-osx.liip.ch/.

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.4
echo 'export PATH=/usr/local/php5/bin:$PATH' >> ~/.profile
echo 'export PATH=/usr/local/php5/bin:$PATH' >> ~/.zshrc

Note: You'll need to exit Terminal and reopen it.

php -v

For Ubuntu Linux see http://www.zimbio.com/Ubuntu+Linux/articles/D_AsJR2qAL6/How+Upgrade+PHP+5+4+Ubuntu

sudo add-apt-repository ppa:ondrej/php5
suda apt-get update
sudo apt-get install php5

For Windows try the PHP for Windows and see the notes

Your first PHP app

mkdir phpapp
pushd phpapp
echo '<?php echo("Hello World!"); ?>' >> index.php
php -S localhost:3000

And open your browser to http://localhost:3000 to see your lovely PHP.

Your first encounter with errors

The great great thing about running PHP from the console is that you can see errors easily.

<?php
  echo("Hello World!");
  $x = 1;
  foreach($x as $foo) {
    echo("LIES! " . $foo);
  }
  echo("shouldn't get here, but I do");
?>

Writing maintainable code, and you

Those examples are really crappy ways to write code.

more to come...

Further reading

PHP: A fractal of bad design is an article that honestly does an amazing job of outlining the quirks and bad parts of PHP so that you know what you're up against.


By AJ ONeal

If you loved this and want more like it, sign up!


Did I make your day?
Buy me a coffeeBuy me a coffee  

(you can learn about the bigger picture I'm working towards on my patreon page )