Alternative
Amazon
Article
Writing
Art
AI
Angular
Photoshop
Premiere
Animal Crossing
Blog
Story
Android
Android Studio
Davinci Resolve
CSS
Clipchamp
ChatGPT
Crypto
DALL-E
Discord
Davinci Resolve
Davinci Resolve 18
Dream Studio
Express
Filmora
Flutter
PC Games
Git
GPT
GPT3
GPT4
GTA
GTA 6
Ghost Together
Ghost Together
HTML
iOS
iMovie
Illustrator
JavaScript
Mac
Mongo
Midjourney
Minecraft
Node.js
NBA 2k24
OSX
PHP
Palworld
Python
Playground AI
Roblox
React
Recipe (Cooking)
React Native
Semicolon.dev
Starfield PC Game
Snapchat
Steam
Stable Diffusion
SVG
Threads
Text To Image (AI)
VSCode
Vim
Web Development
Windows
WebGL
Php Tutorials

    How To Run PHP Script Files On 'localhost'

    On Windows (7, 10, 11) and Mac (M1, M2, M3, Macbook Pro, Macbook Air)

    How to run PHP files on localhost in browser on your PC in Windows 7 8 10 11 with XAMPP server / php, run, file, script , how to, index.php, mac, windows, 7, 10, 11, m1, m2, m3, xampp

    Running PHP on localhost address is the first thing you want to setup after installing Your Apache, PHP and MySQL (Usually with Xampp server.) This will give you a complete LAMP stack. So, from then on, how do you execute PHP files?

    Let's Ghost Together
    Sign Up Now  -  It's Free!

    Below you will see some of the best videos explaining how to run PHP in browser on your localhost. It's the fastest way to learn how to install Xampp and run PHP files on your localhost! Running PHP files in browser is actually quite simple.

    All you need to do is add your PHP file to htdocs folder in the directory where your PHP server (such as Xampp) was installed.

    How to run PHP file on localhost (with XAMPP server) on a Mac

    Running PHP in localhost on Mac is simple. Here's how:

    How to run PHP files on localhost Mac

    How to install XAMPP to run PHP file on localhost on a Mac

    How to install Xampp on Mac and run PHP on localhost in Safari, Firefox or Chrome browser (it doesn't really matter!)

    How to install Xampp and run PHP files on localhost on a Mac

    How to run PHP file on localhost (with XAMPP server) on Windows

    And here is how to make PHP run in localhost on Windows (7, 10 or 11)

    How To Run PHP Files On Localhost Windows 7 10 11

    How to run PHP on localhost

    Video Chapters

    1. 0:00 How to run PHP File on localhost
    2. 0:08 Make sure XAmpp server is installed and running on your PC
    3. 0:30 Go to C drive and to C:\xampp\htdocs folder (Xampp's localhost root folder)
    4. 1:05 Open index.php file you just created in VSCode (Visual Studio Code)
    5. 1:54 Open PHP script file in Chrome browser running on localhost

    How To Run PHP Script File In Terminal

    If you have XAMPP installed on your local machine, you can run PHP scripts directly from the terminal. To do so, open the terminal and navigate to the folder where the script is located. Then, type "php" followed by the name of the script and press Enter. The script will run and you should see the output in the terminal.

    How To Run PHP File On Localhost In Browser With Xampp Server

    Here's step by step instructions:

    1. If you don't have Xampp installed, go to Apache Friends and download the appropriate version for your operating system.

    2. Once Xampp is installed, open the application and start the Apache server by clicking on the "Start" button next to it.

    3. Now that the server is running, we can test it by creating a php file. Create a new file in your preferred text editor and save it as test.php in the htdocs folder located inside the Xampp folder (The htdocs directory will be located in Applications/Xampp/htdocs by default).

    4. In your PHP file, type the following code:

    <?php
       echo "Hello, world!";
    ?>

    5. Now open your browser and type localhost/test.php into the address bar. You should see the message "Hello, world!" printed on the screen.

    Congratulations, you've successfully run a php file on your local server!

    Another Simple PHP Example Program To Run On Your Localhost

    Well that was way too simple!

    In this next sample code we will write a new PHP function that adds two numbers.

    <?php
       function add(a, b) { return a + b; }
       $result = add(10, 20);
       print $result;
    ?>

    Here we created a simple PHP function called add. It takes two arguments a and b.

    After launching this PHP file in your browser you will see 30 displayed on the screen.

    30 is the value that was generated by the PHP function add with arguments 10 and 20, because in this simple example all it does is add up two numbers passed to the function.

    In function definition code a and b are function's parameters. Parameters are used as variable names. They are part of function definition.

    But when we pass 10 and 20 via those parameter names into the function they are called arguments. Sometimes arguments can be referred to as parameters interchangeably.

    PHP functions don't always require parameters, the parameter list can be empty. Some functions are created to repeat a number of statements on existing data without particular input.

    Go ahead and try passing different arguments to the function. Refresh the browser and you'll see that the result of the function has changed!

    So, that's how you can run PHP scripts on your local machine using XAMPP. With a little bit of practice, you should be able to get your scripts up and running in no time.

    Let's Ghost Together
    Sign Up Now  -  It's Free!
    Write For Us
    Sign Up Now  -  It's Free!

    How To Run PHP Script Files On 'localhost'

    Comments (2) New! (You can now post comments on articles!)

    (By posting a comment you are registering a Ghost Together account.)
    Register
    Register
    Post It
    DM Coming Soon
    f f