1. Using Software
2. How do I start/stop ...
3. Where do I place my ...
4. How do I view my fil...
5. Let’s do a Qui...
Computers don’t automatically come with code that runs PHP, as computers aren’t servers. Therefore, to test your PHP, you can:
- Use a free or paid hosting plan that has PHP installed, where you host your website on their servers. Almost all hosting has PHP pre-installed, so no need for you to worry about it.
- Turn your own computer into a small server-like environment. This can be done by downloading and installing a small piece of software, or by doing a manual installation yourself. Fortunately, PHP is completely free.
I myself, for example, use both. I host this website on a server so that you can all access it, but when I write and test new code I use software to host the website on my own computer. Not only is this kind of local testing quicker, it’s also cheaper and reduces the load on my website’s server.
If you’re just a novice at PHP, doing a manual installation is unnecessarily complicated, which is why I recommend using software. (On the other hand, if you’re already a PHP wizard, manual installation have some advantages for you. For information about that, visit the official PHP Install Manual
The most popular software, which is also available on all three platforms (Windows, Mac, Linux), is XAMPP
Once you’ve downloaded it, install it. There’s no harm in installing all components, but you only really need Apache, PHP and MySQL for this course. The default path (
C:\xampp) is fine.
How do I start/stop the Server?
Once installed, you can find the software like any other on your system, and fire it up. The interface might be intimidating, but to start the server, simply click Start on the Apache module. Similarly, to stop the server, click Stop.
Where do I place my files?
By default, the software will create the folder
C:\xampp\htdocs. This is where you should place all the files from your website, or at least all the files you want to test. You can simply remember it by the fact that htdocs stands for html documents.
How do I view my files?
Just like every other website, you can visit the website on your own server by typing a URL in the browser bar. Because it’s a local server that nobody else has access to, you can do so by typing
Visit it, and you should see a welcome message from XAMPP, which means it was successfully installed. If you see an error, installation was unsuccessful, or the service is not running.
Let’s do a Quick Test
So, fire up your favourite text editor, or the default editor on your operating system (which is probably Notepad for Windows, and Text Editor for Mac). Create a new file, and type
<?php echo "Hello World!"; ?>
What does this mean? It simply starts a PHP block, and prints the phrase Hello World! to the page. Save the file as
test.php, and to check if everything works as expected, access it by visiting
If it does, congratulations! You’ve written your first bit of PHP, and you even have a local test environment working perfectly.
If it doesn’t, there’s a good chance you accidentally unchecked PHP on installation. If you made any type error, XAMPP will automatically throw an error message to let you know what went wrong so you can fix it. Or, you might have forgotten to place the file in the right directory.