Walking through setting up PHP on your computer so you can write and test scripts locally before putting anything live.
Understanding PHP
PHP stands for Hypertext Preprocessor. It is a server-side scripting language, which means it runs on a web server and builds pages before they are sent to the browser. The HTML you write is static; PHP generates the dynamic parts on the server.
Setting up a local environment
A local environment lets you develop and test PHP on your own machine without needing a live web server. You can break things, fix them, and try again – all on your computer.
Step 1: Install a local server
You need a server on your machine. On Windows, XAMPP or WAMP are common choices. On macOS, MAMP is popular. This guide uses XAMPP because it works on all three platforms.
- Download XAMPP from Apache Friends.
- Install it following the instructions. Make sure Apache (the server) and PHP are selected.
Step 2: Testing the server
Once installed, start the Apache server from the XAMPP control panel.
Open your browser and go to http://localhost. If you see the XAMPP welcome page, your server is running.
Step 3: Writing your first PHP script
Find the htdocs folder inside your XAMPP installation directory. This is where your PHP files live.
Create a file called test.php. Open it in any text editor (Notepad, Notepad++, or an IDE) and add this:
<?php
echo "Hello, PHP world!";
?>
Save the file and visit http://localhost/test.php in your browser. You should see “Hello, PHP world!” on screen.
Understanding php.ini
The php.ini file controls PHP settings – upload limits, memory limits, and so on. You will not need to touch it at first, but it is worth knowing it exists.
Using a PHP IDE
You can write PHP in any text editor, but an IDE makes life easier with syntax highlighting, code completion, and error detection. PhpStorm, NetBeans, and Visual Studio Code are all solid choices. Use whatever you find comfortable.
Exploring PHP syntax
With your environment ready, here is a quick taste of PHP syntax. Scripts sit inside <?php ?> tags. This example prints today’s date:
<?php
echo "Today's date is " . Date('Y-m-d');
?>
The echo statement outputs text. The date() function returns the current date.
That is your local PHP environment set up. Next we will go deeper into PHP syntax and start building more useful scripts.

