- Learn about what PHP is and does for you
- Get online hosting and the means to use it for building your PHP site
What is PHP?
PHP stands for Pretext HyperProcessor or something, but whatever. More interesting is the definition of the official php.net site:
PHP is a popular general-purpose scripting language that is especially suited to web development.Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.
Ok, sorry, that’s still not useful.
Here’s some of the things PHP can be used for:
- Including one piece of HTML code ( (for example the <head> part of your site)) into another, so you don’t have to copy-paste big blocks of code across pages.
- Catching information that a user sends to you with a HTML form
- Making your site show different things depending on the time of day, the visitor’s IP address…
- Generally adding cool ‘programming logic’ to your site, with IF statements and loops and variables and things like that.
- And lots, LOTS more.
But, we can keep it at “it’s yet another language for building web sites” and try to get to the part where you see the use rather than read about it as fast as possible.
PHP requires a server to run
So far, all it took to work on your web site is save a couple of files and open them in your browser directly.
Those days are over.
PHP is a complex language, and requires a server running some magic PHP-interpreting software that turns your notepad musings into actual stuff showing in your browser.
By the way, the word ‘server’ is used, roughly, to indicate the following 2 things:
- A physical computer, just like the one you’re on now,, specialising in handling online traffic. That means it typically has no screen, a huge-ass hard drive, and resides together with thousands of identical buddies in some data center. Google and Facebook have lots (and lots and lots) of servers for example.
- A piece of software that can handle incoming ‘connections’ or ‘requests’ from ‘clients’ (a browser is a client for example), and do stuff with them, like execute PHP code and give those incoming requests something back. The piece of server software that’s most relevant to what we are talking about here is called Apache.
Feeling more geeky by the minute, eh?
Get an online web host that runs PHP
Sit down, we need to talk. By now I feel we have established a relationship, albeit a peculiar one stooped in a bizarre mix of condescension and fatherly advice. But it’s also one of trust. Did I ever lie to you? Of course I did, but not on purpose, I promise.
That is why I want to ask you to follow this advice, which is for the first time in the course of this site to pay for something, and trust me that it will be worth it:
Take your wallet, head over to HostGator, and purchase their (cheapest) web hosting plan. Now.
This will give you the power to have a PHP site online, where you’ll want to get it anyway, and get used to some actual ‘putting code online for the world to see’. But the main reason is that you don’t have to worry about setting up all the server stuff that goes into interpreting PHP code.
It takes about 2 minutes, and costs about 50 bucks for a year, and it’s more than worth it. Come back here when you’re done.
Download your FTP client and set it up
Great, you have your online web host account! Just a tad more work and we’re all set to crank out another ‘hello world’. It’s your last one, and it will taste the sweetest of all.
To put files online (on your server), we use ‘FTP’, and to transfer files with FTP we need an ‘FTP client’. (the clever among you recognise how this fits in with some of the terminology about servers we mentioned above)
Configure a new site on FileZilla, using the FTP data you can find in your HostGator backend.
Running PHP on your local computer
Ok, you can also do this. If you are on Windows, download and install WAMP, if you are on Mac, download and install MAMP (they will keep bugging you about MAMP Pro, but ignore that – the free MAMP has all you need). These programs allow you to run a PHP site locally, so you can keep building your website just by saving .php files and refreshing your browser.
The workflow of building a site with an online PHP host
It’s all the same as that for a HTML site, except that you now also upload the files to your online web space using FTP with FileZilla.
- So far we only made our sites show things. PHP allows you to make it do things.
- Your browser cannot simply open php code files. Instead, PHP requires a server, typically ‘Apache’ to interpret the code, and execute it.
- PHP is amazingly powerful, and Facebook and Wikipedia are among the sites built with it, as well as every WordPress site like the one you are reading now.
- PHP is hard. It’s actual programming instead of specifying how something should look. Prepare to be frustrated. And feel victorious you got something to work. And frustrated again.