-4

I'm using a laptop that runs on Windows 10 Home Single Language which is 64-bit Operating System, x64-based processor

Previously, I used to install WAMP/XAMPP on my machine to use PHP and MySQL.

In case of WAMP "www"was my document root directory and in case of XAMPP "htdocs" was my document root directory. In these directories I used to put my PHP files and run them from my browser by entering the URL as

http://localhost/dir_name/file_name.php

But, now I've come to know that since PHP 5.4.0 built-in server has been provided by PHP, so there is no need to install and configure a full-fledged web server.

I referred the file from official PHP documentation :

http://php.net/features.commandline.webserver

But I could not get how to run the built-in web-server on Windows machine as everything has been explained in the manual is with respect to Linux operating system.

Also, please let me know where should I keep my PHP files that I used to keep in a folder under "www" or "htdocs" folder.

Also, guide me in accessing these PHP files from a web browser using this built-in web server like I used to do previously(http://localhost/dir_name/file_name.php)

Thank You.

I tried with the following command in to command prompt:

php -S localhost:8000

but it gave me nothing

see below image

enter image description here

PHPLover
  • 1
  • 51
  • 158
  • 311
  • 2
    What exactly are you having problems with? The page you linked explains it perfectly? (Run `php -S host:port` from your shell and it listens on that host/port while using the current folder as the document root) – ccKep Feb 26 '17 at 19:11
  • @ccKep : It's been explained from Linux point of view and not for Windows. – PHPLover Feb 26 '17 at 19:13
  • It's exactly the same. – ccKep Feb 26 '17 at 19:14
  • @ccKep : See the screenshot I added end of my question. – PHPLover Feb 26 '17 at 19:18
  • That just means php.exe is not in your `PATH` configuration and windows doesn't know where to look for it. Either specify the whole path (eg. `C:\php\php.exe -S localhost:8000`) or add it to your `PATH` variable (google is your friend). – ccKep Feb 26 '17 at 19:19
  • @ccKep : Now tell me what should I do? That's why I asked this question. – PHPLover Feb 26 '17 at 19:20
  • [Windows 7 - Add Path](http://stackoverflow.com/questions/23400030/windows-7-add-path9), 1st answer - Sure, it's Win7.. but the steps are basically the same in Win10 (except for the "Advanced Tab" you use the link on the left saying basically the same thing) – ccKep Feb 26 '17 at 19:23
  • @ccKep : It would be better if you could all these steps as an answer. It will help me as well as other community members. – PHPLover Feb 26 '17 at 19:25
  • Check this link for setting the PATH Environment Variable: https://msdn.microsoft.com/en-us/library/office/ee537574(v=office.14).aspx – bronlund Feb 26 '17 at 19:31
  • I just remembered; Windows is kind of a bitch when it comes to changing the environment. You may have to reboot. It is possible to set the path directly in the console, but it will be forgotten as soon as you close it. – bronlund Feb 26 '17 at 19:48

1 Answers1

0

The instruction for Linux shouldn't be much different for Windows in respect to this. You still need a console though and preferably the path to PHP in the environment.

You could try to open a console by pressing the Windows key, type cmd and press enter. In the console try to type php -v and press enter. If the console know where to find PHP, you should see the current version.

If that worked, move to the directory you want to serve using the cd command and then run php -S localhost:8000

That directory is now the document root for the webserver at http://localhost:8000/

bronlund
  • 138
  • 8