PHP
→ php.net
Dev setup
PHP binaries
Download the version that you want from the download page. You may consider reading a little about thread safe (for Apache) and not thread safe versions (for IIS, nginx or command line).
On Windows, you'll download a zip file, you just have to extract it somewhere (more in a program folder). You can add the direetory in the environment PATH but it's not mandatory. For example, you can add the following line in a command window:
Once you're clear on your PHP installation setup, you should be able to get something like this:
By default, there is no php.ini
file in the installation folder, you can copy the development one to create your own file.
Nginx
CGI
Create a bat file, for example start-php-fcgi.bat:
Composer
Composer is the dependency (package) manager for PHP.
Once it is installed, you should be able to get the following:
You can install packages system or project wide. Here are some tools that are good to have system wide:
Composer configuration file is called composer.json
.
XDebug
XDebug is required to debug your code in your IDE (Eclipse PDT, VS Code, etc.).
Go on Installation page and select the version related to your PHP one, for example
php_xdebug-2.6.0-7.2-vc15-nts-x86_64.dll
.Copy the file in the ext directory of your PHP installation directory.
Edit your
php.ini
file to add the following lines to activate the debugging (if you don't know which php.ini file you're using make a phpinfo() file)
IDE
VS Code
Visual Studio Code is an indredible tool provided by Microsoft. You can review PHP Programming in VS Code for more information.
If you want to see a preview or get up to speed quickly, you can watch laracasts.com series.
You just have to set php.validate.executablePath
in your user settings in VS Code if it's not in the PATH (which could be a good practice if several PHP versions must be present on the machine).
Language
Conventions
phpcs is a good tool to validate the code that is written.
It can be easily configured, see the Configuration Options.
You can also change the behaviour directly in the file.
You can define your own ruleset, see Annotated ruleset.xml.
For example, custom_ruleset.xml file content:
You can configure it in VS Code or from the command line:
MongoDB Driver
There is a PHP extension and a PHP library to access MongoDB, see docs.mongodb.com.
Installation
(Windows) Download the zip file for the good version from pecl.php.net and copy the dll inside the zip file to your extension folder.
Add in your
php.ini
file:
From your project directory:
Reference: php.net.
First steps
Reference: Using the PHP Library for MongoDB (PHPLIB).
Libraries
Pimple: A simple PHP Dependency Injection Container
Tools
phpdbg
Unit tests
PHPUnit
PHPUnit is a testing framework for PHP. It is open source: sebastianbergmann/phpunit. It is available on packagist.
Getting started with PHPUnit
Install locally:
composer require phpunit/phpunit --dev
Check the tool is running file:
php vendor/phpunit/phpunit/phpunit --version
(orphp vendor/bin/phpunit
on a non-Windows environment)
Edit
composer.json
file and executecomposer install
to regenerate autoload fileCreate
phpunit.xml.dist
file:Launch the tests:
php vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist --log-junit junit.xml
With coverage (Code Coverage Analysis):
php vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist --coverage-html .build/coverage-report --coverage-clover .build/coverage.xml
Integration in SonarCloud: PHP Unit Tests and Coverage Results Import
We can also use phpdbg (that is now shipped with PHP):
phpdbg -qrr vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist
(comparison with xdebug here: Generating Code Coverage with PHPUnit and phpdbg)You can also use Symfony PHPUnit bridge:
composer install symfony/phpunit-bridge --dev
(and create a bin/console and update your gitignore)For Mocks : Test Doubles
Last updated