How to run php server with Visual Studio Code
When I developed my pet-project about collecting malicious requests, php run on real server. It was written in notepad++, then copied into server via ssh and then tried whether it worked. It's ok for the hobby and for amateur, isn't it? Not quite easy one though.
Recently I found, that it's possible to try php code from IDE. Better later than never...
This article is "How to", as sometimes I need to start it from scratch and completely forget the steps by this time.
First - Download PHP from: https://windows.php.net/download
Latest version, Zip, Thread safe.
Second - Unpack downloaded zip. I was recommended to do it in C:\php\
Then rename php.ini-development into php.ini.
Third - open VS Code, open extensions and install "PHP Server" by brapifra.
Fourth - open "File" -> "Preferences" -> "Extensions".
Scroll to "PHP Server configuration" and write PHP Config Path: "C:\php\php.ini" and PHP Path: "C:\php.php.exe".
In search field of "Settings" input "json" and find something, that leads to "settings.json".
Fill settings.json fields:
"phpserver.phpConfigPath": "C:/php/php.ini",
"phpserver.phpPath": "C:/php/php.exe",
"php.validate.executablePath": "C:/php/php.exe"
Finally, as I'm using sqlite this time, in php.ini uncomment (delete ; at the beginning of row):
extension=pdo_sqlite
extension=sqlite3
That's it. Now open my project, click right mouse button and select "PHP Server: Serve project".
It became way easier now to work with PHP, as I can immediately watch how it's doing. Also this might recieve requests from browser, like POST, GET etc, so I can try to download file, request for data from server via javascript in browser and get it.