Welcome to a PHP installation guide that's anything but ordinary! Whether you're a curious beginner dipping your toes into programming or a seasoned developer setting up a new environment, this tutorial is designed to make the process smooth, engaging, and even a little fun. We'll walk you through installing PHP on both Windows and Ubuntu, offering unique approaches like using the Windows Subsystem for Linux (WSL) for a seamless cross-platform experience. By the end of this guide, you'll not only have PHP up and running but also write your first script to proudly display "Hello! It works!"
- a small yet satisfying milestone in your coding journey.
If you're on Windows, why not embrace the power of Linux without leaving your OS? WSL allows you to run Ubuntu (or other Linux distributions) directly on Windows. Here's how to set it up:
wsl --install
sudo apt update
sudo apt install php
php -v
If you prefer to stick to native Windows, follow these steps:
php-8.x.x-Win32-vs16-x64.zip
).C:\php
.Path
variable, click "Edit," and add the path to your PHP directory (e.g., C:\php
).php -v
Ubuntu makes installing PHP a breeze. Here's how:
sudo apt update
sudo apt install php
php -v
If you want the latest PHP version, you can add a Personal Package Archive (PPA):
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.x
Replace 8.x
with the desired version number.php -v
Now that PHP is installed, let's create a simple script to print"Hello! It works!"
and celebrate your success.
<?php
echo "Hello! It works!";
?>
hello.php
in your PHP directory (e.g., C:\php\hello.php
).hello.php
is saved.php hello.php
Hello! It works!
nano hello.php
<?php
echo "Hello! It works!";
?>
Ctrl + X
, then Y
to confirm).hello.php
is saved.php hello.php
Hello! It works!
If you want to see your script in a browser, you can set up a local web server:
sudo apt install apache2 libapache2-mod-php
Move hello.php
to /var/www/html/
and access it via http://localhost/hello.php
.hello.php
in the htdocs
directory and access it via http://localhost/hello.php
.That's it! You've not only installed PHP but also created your first script. Now go forth and build something amazing!