How to setup a PHP environment on my laptop?
Download and install XAMPP.
Download and install Visual Studio Code.
Install the following extensions in Visual Studio Code:
- PHP server
- PHP debug
What is an extension in PHP?
Extensions are libraries like DLL files.
They contain specific functions.
How to load extensions in PHP?
Extensions are turned on or off in the php.ini file with a comment character.
What is the php.ini file ?
This is the configuration file for PHP. Each separate PHP version on your laptop must have its own php.ini file. The path in your environment defines which version of PHP is used.
What is Xdebug?
Xdebug is a browser extension that you can run inside your web browser. You install the Xdebug extension for example in google chrome or firefox by activating and configuring.
Next, you activate and configure the PHP debug extension in your visual studio code. The PHP debug extension in Visual studio code and Xdebug extension in your web-browser will be able to communicate with each other.
After installment and setting breakpoints in your PHP code, you can run your PHP in the web-browser and checking each step in your Visual Studio code editor.
How to setup debug in PHP in Visual studio code?
Well, this is quite complicated if you have only PHP server running in visual studio code. I advice to watch : https://www.youtube.com/watch?v=poty5nKk2m4
Why is phpinfo() important?
Phpinfo() prints information about where the php.ini file is located that is loaded, what extensions are loaded etc.
If your PHP application crashes, this might help you further to solve the challenge.
How to run php code?
You can create a file with an extension name .php (start.php) and in that file you put some code enclosed withing two markers:
<?php “your code” ?>
Put this file in the directory that apache is looking in. Most of the times this in the xampphtdocs directory.
Execute the file in the browser with http://yourserver(127.0.0.1)/start.php
You can also start a shell or console application in your environment and when your php environment is configured correctly, I mean the right environment path to find the php version to be used, then you can execute with php -f start.php.
The output will be the same.