Setting up your PHP development environment for Elastic Beanstalk
This topic provides instructions to set up a PHP development environment to test your application locally prior to deploying it to AWS Elastic Beanstalk. It also references websites that provide installation instructions for useful tools.
For common setup steps and tools that apply to all languages, see Configuring your development machine for use with Elastic Beanstalk.
Sections
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 php82
, php82-mbstring
, and php82-intl
. Then use sudo yum install
to install them.package
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 Formulaephp@8.2
. Then use the brew
install
to install them.package
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
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 AWS SDK for PHP
If you need to manage AWS resources from within your application, install the AWS 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
For more information, see the AWS SDK for PHP
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