PHP (Hypertext Preprocessor) is a popular server-side scripting language used for web development. In this tutorial, we’ll go over how to install PHP and run your first PHP script.
Follow these steps to install PHP on your system:
brew install php
if you have Homebrew installed.sudo apt install php
(Ubuntu/Debian).php -v
in your terminal or command prompt. You should see the PHP version displayed.To run PHP code, you need a local server. Here’s how to set one up:
php -S localhost:8000
.Create a new file named index.php
and add the following code:
<?php echo "Hello, World!"; ?>
Save the file in your server’s root directory (e.g., htdocs
for XAMPP).
Open your browser and navigate to http://localhost/index.php
. You should see:
Hello, World!
Now that you’ve set up PHP, explore its syntax and features. Try creating dynamic web pages and connecting to a database like MySQL. Happy coding!