Open In App

How to host local server on your Computer with PHP ?

In this article, we will see how to use the Localhost server to run the PHP code. Localhost server simulates a similar environment to compile & debug, in order to develop the code, just the same as in the real-time environment. Basically, the computer is talking to itself when you call the local host. When we are building a website on PHP, then we have to face some difficulties while hosting our websites on a local server. Especially if we store the PHP file other than htdocs (if using the XAMPP server), it always shows some errors. So, we need to strictly write code in the htdocs folder, that resides in the C-Drive of our computer.

How to use localhost in other drives or folders of our computer?



C:\xampp\htdocs

We can see this in the image below:

Environment Variable

Now just press ok and save the changes.



Check PHP version

php -S localhost:8000

And the server will start running. Check the below images:

 

Example: This example describes the basic implementation of the PHP code to run into the localserver in the computer.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
    "width=device-width, initial-scale=1.0">
    <title>
        Host local server on your
        Computer with PHP
    </title>
</head>
  
<body>
    <?php
        echo"<h1>Welcome to php Website</h1>";
        echo"Hello World";
    ?>
</body>
  
</html>

Output:

 

Article Tags :