Before testing PHP applications in a local environment, you must prepare the environment. This topic describes how to configure a PHP environment. It also provides download links for related tools.
Install PHP
Proceed as follows to install PHP and several commonly used extensions. If you do not have specific requirements, we recommend that you download the latest installation package.
- Download an installation package for Linux from the PHP official site. For example, php-7.3.8.tar.bz2 (sig).
- Open the directory where the installation package resides.
- Use the following command to install the package.
$ sudo yum install php
- Download an installation package for macOS from the PHP official site. For example, php-7.3.8.tar.bz2 (sig).
- Use the following command to install the package.
$ brew install php
- Download an installation package for Windows from the PHP official website. For example, PHP 7.3 (7.3.8).
- Open the directory where the installation package resides and double-click the package to install PHP. No further configuration is required.
Install Composer
Composer is an application-level package manager that helps you manage dependencies. You can use Composer to install libraries, track dependencies for applications, and create projects for popular frameworks.
- Use the following command to retrieve a PHP script from getcomposer.org to install Composer.
# curl -sS https://getcomposer.org/installer | php
- The installer creates a PHAR file in the current directory. Move the file to a directory
that is added to the PATH environment variable. Then, you can run the file under all
folders.
$ mv composer.phar ~/.local/bin/composer
- Use the require command to install Twig.
$ composer require twig/twig
Composer adds libraries that are installed on your localhost to the composer.json file of your project. When you deploy an application, Web App Service uses Composer to install libraries that are listed in the file on an application instance of your deployment environment. If you have any questions when you install Compose, visit the Composer official website.