BreadcrumbHomeResourcesBlog A Beginner's Guide To Deploying PHP On AWS November 9, 2023 A Beginner's Guide to Deploying PHP on AWSAWSZend ServerBy Yeshua HallDeploying a PHP application on AWS may seem daunting at first. While there are a veritable sea of images to choose from, sometimes it can be hard to track down documentation on how to actually install, configure, and deploy your application.In this blog, we walk through two ways to deploy PHP on AWS, the first via a ZendPHP image, and the second via a Zend Server image. We also discuss some of the basic concepts and ideas you need to have a handle on before you get started. Let's jump in!Table of ContentsTerms to Know Before You Deploy PHP on AWSAWS PHP ImagesDeploying a ZendPHP-Based Application on AWSDeploying Zend Server on AWSFinal ThoughtsTable of Contents1 - Terms to Know Before You Deploy PHP on AWS2 - AWS PHP Images3 - Deploying a ZendPHP-Based Application on AWS4 - Deploying Zend Server on AWS5 - Final ThoughtsBack to topTerms to Know Before You Deploy PHP on AWSBefore we jump into how to deploy PHP on AWS, let’s start with a simple vocabulary of common terms that are used when discussing AWS:AWS (Amazon Web Services)EC2 (Elastic Compute Cloud): an AWS service that provides computing resourcesAMI (Amazon Machine Image): a filesystem image with some metadata like type of OS in image and type of virtualization to use when starting new serverInstance: a Virtual Machine running on EC2 using some AMIInstance type: a combination of CPU, memory, storage, and networking capacityRDS (Relational Database Service): an AWS service that provides many relational databases (supports, but not limited to, MySQL)To help you understand the different AWS security settings, these security terms will become handy:VPC (Virtual Private Networking): allows you to define one or more networks which is composed of one or more VPC SubnetsVPC Subnet: similar to regular network subnetSecurity Group: a set of network rules. Resources on AWS can belong to one or more Security Groups.Key pair: regular SSH key pair. Must be specified when starting EC2 Instance to allow SSH access.Back to topAWS PHP ImagesThe AWS Marketplace has a myriad of full blown application servers with different PHP versions and SAPIs available out of the box; including community PHP, Zend Server, and ZendPHP; on many different operating systems. This makes it quick and simple to spin up an image and drop your PHP application in.ZendPHP ImagesAmong the many different application servers available through AWS Marketplace are the images we provide for ZendPHP. We provide images for configurations with Nginx or Apache on Ubuntu, RHEL, Amazon Linux, Debian, and more. There are options to have the license built into the image as well as bring your own license (BYOL).Back to topDeploying a ZendPHP-Based Application on AWSDeploying a ZendPHP-Based AMI follows the same process as any other AMI with the nuance of using zendphpctl to install and configure PHP.Step 1: Launching ZendPHP on AWSThere are two ways to launch PHP on AWS using ZendPHP. First is to use AWS Marketplace website (option A) and launch ZendPHP from there. Second is to use Marketplace inside AWS Console (option B). We will cover both ways here.Option A: Launch ZendPHP Using AWS Marketplace WebsiteOpen AWS Marketplace websiteSign in or create AWS account by clicking relevant link on top of pageType ‘ZendPHP’ in the search bar and press EnterIn the search result locate ZendPHP with relevant PHP version, edition, and operating system. For this guide please select 'ZendPHP with nginx on Ubuntu 2.0.04'.On the product page click on "Continue" button located on the rightConfigure and customize the launch settings of ZendPHP instance.Version: version of ZendPHP AMI to use. It’s recommended to always use latest versionRegion: which region ZendPHP instance should be startedInstance type: how much CPU/memory/Storage you want for your instanceVPC settings: which VPC and subnet instance is startedSecurity group: security group for instance, you can select existing security group or let AWS create new security group with default rules for ZendPHP (recommended)Key pair: which SSH key pair should be installed on this instanceReview the launch settings and click on "Accept Software Terms & Launch with 1-Click" button, After the first launch this button will be named "Launch with 1-Click".Login to AWS Console to see the new instance and get its detailsOption B: Launch ZendPHP Using AWS ConsoleLogin to AWS ConsoleOpen EC2 ConsoleOn dashboard click on "Launch Instance"buttonEnter 'ZendPHP' in the AMI search barSelect relevant ZendPHP product with the proper edition and operating system and click Continue button in product summary that is shown. For this guide please select 'ZendPHP with nginx on Ubuntu 2.0.04'.Select instance typeOn steps 3, 4, 5 various instance settings can be configured.Either select an existing key pair (and acknowledge you have access to it) or create a new one and click "Launch Instances"Enter friendly name for your instance that will be used to identify it, review the settings, and click on "Launch instance" buttonWait while the instance is created and then click on "View Instances" button at the bottom of a page Launch StatusBootstrap ZendPHPThe ZendPHP AMIs from AWS Marketplace come with zendphpctl preinstalled and ready to use with our repository preconfigured. Once the instance is up and running, SSH into the instance and use zendphpctl to finish setup:zendphpctl php install 8.2 zendphpctl ext install –php 8.2 curl dom mysqli sodium openssl imagick xml zip zendphpctl fpm install 8.2 zendphp-switch to 8.2 The above will install the PHP version of your choice, extensions needed for WordPress, add php-fpm for it, and ensure the vhost uses the correct php-fpm pool.Note: The ZendPHP AMIs have access to any ZendPHP versions (licenses required for those out of community support), and you simply install the one you need with zendphpctl, as shown above. Step 2: Follow the Rest of the Steps for Zend ServerIn order to get an example application going, simply follow steps 2-3 for Zend Server below, where we cover creating an RDS and launching WordPress.Back to topDeploying Zend Server on AWSStep 1 - Launching Zend Server on AWSThere are two ways to launch Zend Server on AWS. First is to use AWS Marketplace website (option A) and launch Zend Server from there. Second is to use Marketplace inside AWS Console (option B). We will cover both ways here.Option A: Launch Zend Server Using AWS Marketplace websiteOpen AWS Marketplace websiteSign in or create AWS account by clicking relevant link on top of pageType ‘Zend Server’ in the search bar and press EnterIn the search result locate Zend Server with relevant PHP version, edition, and operating system. For this guide please select 'PHP 7 - Zend Server (Ubuntu)'.On the product page click on "Continue" button located on the rightConfigure and customize the launch settings of Zend Server instance.Version: version of Zend Server AMI to use. It’s recommended to always use latest versionRegion: which region Zend Server instance should be startedInstance type: how much CPU/memory/Storage you want for your instanceVPC settings: which VPC and subnet instance is startedSecurity group: security group for instance, you can select existing security group or let AWS create new security group with default rules for Zend Server (recommended)Key pair: which SSH key pair should be installed on this instanceReview the launch settings and click on "Accept Software Terms & Launch with 1-Click" button, After the first launch this button will be named "Launch with 1-Click".Login to AWS Console to see the new instance and get its’ detailsOption B: Launch Zend Server using AWS ConsoleLogin to AWS ConsoleOpen EC2 ConsoleOn dashboard click on "Launch Instance" buttonEnter 'Zend Server' in the AMI search barSelect relevant Zend Server product with relevant PHP version, edition, and operating system and click Continue button in product summary that is shown. For this guide please select For this guide please select 'PHP 7 - Zend Server (Ubuntu)'.Select instance typeOn steps 3, 4, 5 various instance settings can be configured.Either select an existing key pair (and acknowledge you have access to it) or create a new one and click "Launch Instances"Enter friendly name for your instance that will be used to identify it, review the settings, and click on "Launch instance" buttonWait while the instance is created and then click on "View Instances" button at the bottom of a page Launch StatusBootstrap Zend Server to Get Zend Server Ready for WorkOnce you have finished either option A or B, you need to make Zend Server ready for work. We have to bootstrap it using very simple wizard. To do this we open the Zend Server UI which is accessible using a web browser on port 10081 of the instance we just started.We need to find out either the public DNS (what we use in this guide) or public IP of the instance. We will also need the instance ID to enter Zend Server UI. By default Zend Server UI is protected so you have to enter instance ID as login and password, but once you bootstrap Zend Server and set admin password you won’t have to use it again.Follow these steps to find “Public DNS” and “Instance ID” of your instance:Open AWS ConsoleEnter EC2 ConsoleIn the menu on the left click on “Instances” linkLocate your instance in the list of instances and click on itOn the bottom pane you will see information about the instance shown in 2 columns“Public DNS” field is on top of right column“Instance ID” field is on top of left columnNow that we have public DNS name of instance we can open our browser and enter the following address to access Zend Server UI: http://<Public DNS>:10081/Once you open Zend Server UI you will first be asked to authenticate. Enter “Instance ID” you found earlier as both login and password.You will then be presented a wizard that will guide you to setup Zend Server in a few very simple steps. Upon finishing wizard and successfully bootstrapping your Zend Server is fully ready to work.Note: bootstrap process can be fully automated by providing user data to instance. Step 2 – Launching RDS for MySQLWe have Zend Server, which means that we have fully working and configured web server with PHP. To go on and launch WordPress, we are still need to add a MySQL database server. We, of course, could install and configure it on the same instance with Zend Server, but it’s much simpler to use AWS RDS. RDS provides many database services including MySQL. So let’s setup an RDS instance and configure Security Group to allow access to it:Open AWS ConsoleOpen RDS ConsoleClick “Launch a DB Instance” buttonSelect “MySQL” tab on the left and click “Select” buttonSelect “MySQL” under Dev/Test section and click “Next Step” buttonConfigure all options you see on screen (once you select some option, it’s description is presented on the right), for our example fill following details:DB Engine Version: LatestDB Instance Class: db.m3.mediumMulti-AZ Deployment: NoStorage Type: General Purpose (SSD)Allocated Storage: 5GBDB Instance Identifier: unique name for your DB InstanceMaster Username: rootMaster Password: your password>Confirm Password: must be same as Master PasswordClick “Next Step” buttonAdvanced Settings step - as in previous step, clicking any option shows its description on the right. For this guide change only the following settings:VPC: select your default VPCSubnet Group: select any subnet groupPublicly Accessible: yesAvailability Zone: No preferenceVPC Security Group: select same Security Group as Security Group of EC2 instance you created (if you do not remember it, you can find it in EC2 console on details pane where you found “Instance ID” and “Public DNS” fields)Database Name: leave emptyBackup Retention Period: if you do not want to backup this RDS, select 0Click “Launch DB Instance”Now we have to wait till our new DB instance is launched and ready for use. While waiting we can configure our Security Group rules to allow communication between web server and MySQL DB server.Configure Security GroupThere are two options for configuration here: either allow communication only between web server and MySQL server (more suitable for production environments), or allow anyone to connect to MySQL DB server (more suitable for development environments). In this guide we will cover only second option.Allow anyone to connect to MySQL serverOpen AWS ConsoleOpen EC2 ConsoleClick on “Security Groups” link in the menu on the leftSelect relevant Security GroupIn the details pane on bottom click on tab “Inbound”Click on “Edit” buttonIn the dialog shown click “Add Rule”Fll values of new rule as following:Type - Custom TCP RuleProtocol - TCPPort Range - 3306Source - Custom IP and enter 0.0.0.0/0 as IPClick “Save” buttonTo find MySQL server DNS see how to find endpoint (which is also MySQL DNS) in next step.Step 3 - Deploy WordPressOnce RDS has finished starting (it can take 10 minutes or even more), you have to find its endpoint. For this follow these steps:Open AWS ConsoleOpen RDS ConsoleClick on “Instances” link in the menu on the leftClick on your RDS instanceLocate “Endpoint” field and save itOnce we have MySQL endpoint we can deploy the WordPress application. For this do the following:Open Zend Server UI (reminder - http://<instance public DNS>:10081/)Login to Zend Server (if needed)Click on “Getting Started” menu on the leftClick on WordPress icon located under “Deploy sample apps” sectionWait till WordPress application is downloaded and click “Next” buttonNext you will be presented “README” section with details about WordPress package, you can read them and then press “Next”Here you can fill application details:Display name: name that this application will have in applications listVirtual Host: on which virtual host application should be deployed (leave “default server”)Path: path under which application will be deployed (leave empty)Click “Next” to proceedRead EULA, check checkbox under it and click “Next”On next screen you will see prerequisites validation statusClick “Next” to continueNow the important part - user parameters, fill them as following:Site URL: must be http://<Instance Public DNS>/Blog Name: fill as you likeDatabase host: must be set to endpoint of RDS instanceDatabase username: rootDatabase password: password you entered when you created RDS instanceDatabase name: name of database for WordPress (change only if needed)WordPress admin username: username for admin user of WordPressWordPress admin password: password for admin user of WordPressWordPress admin email: email for admin user of WordPressTable prefix: prefix for tables created in database (change only if needed)Click “Next” buttonReview deployment summary and click “Deploy”Once you click “Deploy” application deployment will be started. It should take up to a few minutes to finish (but most of time it finishes in tens of seconds). Once the application status on applications list page changes to “Deployed”, you can access WordPress on http://<Instance Public IP>/Back to topFinal ThoughtsIn this blog we looked at two ways to deploy PHP on AWS. The first using ZendPHP, and the second using Zend Server. However, there are many other Zend PHP AWS images that we didn't walk through. With image options that include Nginx or Apache on Ubuntu, RHEL, Amazon Linux, Debian, and more, our goal is to make it as easy as possible for teams to deploy PHP applications in the cloud, on premises, or in hybrid environments.Explore Our AWS ImagesReady to get started deploying your own PHP application on AWS? Explore the Zend AWS listings via the link below.Explore Zend AWS ImagesAdditional Resources101 Guide - Developing Web Applications with PHPBlog - PHP Development: Using PHP ExtensionsTechnical Guide - Writing PHP ExtensionsBlog - PHP Encryption with LibsodiumBlog - 2024 PHP Deployment and Development TrendsBlog - How to Migrate Zend Server to ZendPHPBack to top
Yeshua Hall Senior Solutions Architect, Zend by Perforce Yeshua Hall is the Senior Solutions Architect at Perforce Software. Yeshua is passionate about helping customers overcome complex technical challenges to achieve their team and business goals.