Setting up your PHP development environment - Amazon Elastic Beanstalk
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Setting up your PHP development environment

Set up a PHP development environment to test your application locally prior to deploying it to Amazon Elastic Beanstalk. This topic outlines development environment setup steps and links to installation pages for useful tools.

For common setup steps and tools that apply to all languages, see Configuring your development machine for use with Elastic Beanstalk.

Installing PHP

Install PHP and some common extensions. If you don't have a preference, get the latest version. Depending on your platform and available package manager, the steps will vary.

On Amazon Linux, use yum:

$ sudo yum install php $ sudo yum install php-mbstring $ sudo yum install php-intl
Note

To get specific PHP package versions that match the version on your Elastic Beanstalk PHP platform version, use the command yum search php to find available package versions, such as php72, php72-mbstring, and php72-intl. Then use sudo yum install package to install them.

On Ubuntu, use apt:

$ sudo apt install php-all-dev $ sudo apt install php-intl $ sudo apt install php-mbstring

On OS-X, use brew:

$ brew install php $ brew install php-intl
Note

To get specific PHP package versions that match the version on your Elastic Beanstalk PHP platform version, see Homebrew Formulae for available PHP versions, such as php@7.2. Then use brew install package to install them.

Depending on the version, php-intl might be included in the main PHP package and not exist as a separate package.

On Windows 10, install the Windows Subsystem for Linux to get Ubuntu and install PHP with apt. For earlier versions, visit the download page at windows.php.net to get PHP, and read this page for information about extensions.

After installing PHP, reopen your terminal and run php --version to ensure that the new version has been installed and is the default.

Install Composer

Composer is a dependency manager for PHP. You can use it to install libraries, track your application's dependencies, and generate projects for popular PHP frameworks.

Install composer with the PHP script from getcomposer.org.

$ curl -s https://getcomposer.org/installer | php

The installer generates a PHAR file in the current directory. Move this file to a location in your environment PATH so that you can use it as an executable.

$ mv composer.phar ~/.local/bin/composer

Install libraries with the require command.

$ composer require twig/twig

Composer adds libraries that you install locally to your project's composer.json file. When you deploy your project code, Elastic Beanstalk uses Composer to install the libraries listed in this file on your environment's application instances.

If you run into issues installing Composer, see the composer documentation.

Installing the Amazon SDK for PHP

If you need to manage Amazon resources from within your application, install the Amazon SDK for PHP. For example, with the SDK for PHP, you can use Amazon DynamoDB (DynamoDB) to store user and session information without creating a relational database.

Install the SDK for PHP with Composer.

$ composer require aws/aws-sdk-php

Visit the Amazon SDK for PHP homepage for more information and installation instructions.

Installing an IDE or text editor

Integrated development environments (IDEs) provide a wide range of features that facilitate application development. If you haven't used an IDE for PHP development, try Eclipse and PHPStorm and see which works best for you.

Note

An IDE might add files to your project folder that you might not want to commit to source control. To prevent committing these files to source control, use .gitignore or your source control tool's equivalent.

If you just want to begin coding and don't need all of the features of an IDE, consider installing Sublime Text.