Web Hosting on Amazon AWS (PHP + MySQL)

47,425

Solution 1

Depends on your needs. Elastic Beanstalk might be a good option for many apps, but I chose EC2 for my app's backend (using PHP, MySQL and S3 for storage).

Quick steps to get you up and running:

  1. Log into the AWS Mangement Console and start a new EC instance (Windows server 2012 R2 Base > t2.micro should be good enough for a start!)

  2. At step "6. Configure Security Group", add Rules for at least HTTP, HTTPS and RDP (so you can connnect via Remote Desktop)

  3. Connect to your new instance via Remote Desktop and install a decent browser (Enable File Downloads in IE's Security Settings and download Chrome or Firefox)

  4. Open the Windows Firewall and add rules for the same ports you opened in the Security Group of your Instance in the AWS Management Console. (Right-click on “Inbound Rules”, then select “New Rule…”)

  5. Download and install XAMPP (I put it in C:\xampp)

  6. Open the XAMPP Control panel and install Apache and MySQL as services (so they will start automatically when your instance launches); make sure everything is started up.

  7. Now put your files in C:\xampp\htdocs\ and you're ready to go!

Bonus Steps:

  • Set up Filezilla FTP Server (and open the required ports in both the instance's security group and the Windows Firewall) so you can upload/download files without having to go through Remote Desktop.

  • Get an Elastic IP and assign it to your instance, so it's IP address will never change.

  • Get an SSL certificate so you can use HTTPS

Solution 2

The answer depends on the load that you are expecting and the resources you have to handle all the administration tasks.

If you expect heavy or variable loads, there are many reasons why not to deploy a production PHP + MySQL application on a EC2.

Here are some of the benefits of deploying to Elastic Beanstalk instead of a manual configured EC2:

  • You get version control of each deployment.

  • You can scale up or down automatically if you need more/less instances to handle new load.

  • You get a load-balancer in front of your EC2s instances with a bunch of out-of-the-box "recommended" configurations.

Regarding MySQL, if you go for an Amazon RDS instance you can handle replication, monitorization and automatic backups with pretty low effort. A lot of the configurations you would need to tweak are now available through parameter-groups.

On the other hand, if you want to have full control of everything that is going on on your server (that means you have time to monitor, backup and do maintenance tasks, which is not my case :), or if you do not plan to have much traffic, or if you want the less expensive option, you should go with a low cost EC2 instance.

In my experience, (after 2 years of working on AWS with 10 production applications, I'm kind of a regular AWS user) pretty much every customization or change I needed on both RDS and EBS I was able to tweak it and get it working, so I'm pretty satisfied with choosing the EBS+RDS option.

Share:
47,425
AKA
Author by

AKA

Updated on January 25, 2022

Comments

  • AKA
    AKA over 2 years

    I am totally confused on how to host a Dynamic website created using PHP and MySQL in Amazon Cloud.

    I went through Amazon S3 and I hosted a static website there!

    Then I tried Amazon EC2 and I learned some aspects about the concept of VPC. I thought that the dynamic websites are hosting in Amazon Cloud using EC2. I followed some steps and they taught me how to launch a website using Drupal (But, I didn't want that !! )

    No other tutorials on EC2 to deploy my web application was not found.

    Then I found AWS Elastic Beanstalk, I uploaded a simple PHP document and I can see that deployed successfully.

    But Still, I am not satisfied. Because, I don't know which is the correct way to deploy my PHP application.

    So can anyone direct me on Deploying a PHP MySQL Application in AWS ?

  • omrakhur
    omrakhur almost 8 years
    The steps above are great for a development/staging environment. However, I wouldn't recommend using XAMPP in a production environment, especially if you plan on scaling the application. XAMPP/WAMP/MAMP are best for development or static site hosting reddit.com/r/webdev/comments/3n5a5a/…
  • Oliver Kucharzewski
    Oliver Kucharzewski almost 8 years
    Hi @omrakhur, What would you recommend for deploying it in a production environment?
  • omrakhur
    omrakhur almost 8 years
    @OliverKuchies, I would rather use an ElasticBeanstalk environment.
  • Code Wiget
    Code Wiget about 7 years
    Hi @rboe and col00r, I have tried your steps, and they work great! I successfully created the server on AWS, but now I have no idea how to access the server. I am using AFNetworking from an ios app, so I just need the URL to connect to. Any tips?
  • col000r
    col000r about 7 years
    Hi @Ryan, you should be able to find the URL on the AWS EC2 control panel. Usually it will look like this: ec2-IP-ADDRESS.REGION.compute.amazonaws.com
  • Code Wiget
    Code Wiget about 7 years
    @col000r , thanks for your help! I got the url from your steps. I then had the problem of blocking the firewall on my Windows server. Turns out its not as easy as just adding an inbound rule, you have to enable specific existing rules that enable port 80 and port 443. For example, creating a rule that allowed ports 0-1 did not allow pings, but enabling a separate rule did open up those ports. Anyways, thanks for the help!
  • Buttle Butkus
    Buttle Butkus almost 6 years
    Deploying a PHP/MySQL application in Windows? Why? That seems very odd.