Wednesday, April 2, 2014

Apache, MySQL, PHP installation on Amazon Linux AMI




Below is a quick reference on how to setup a free Amazon Web Services (AWS) Linux server and install Apache, MySQL and PHP. Learn more about AWS here.

Requirements:


Directions:

  1. Login to Amazon Web Services.
  2. Click EC2 icon from dashboard:
  3. Click Instances from Left Navigation
  4. Click Launch Instance Button
  5. Select Amazon Linux AMI
  6. Select Review & Launch Button
  7. Select Launch Button
  8. When Prompted Select "Create a new key pair" and enter "Key pair name"
  9. Click "Download Key Pair" button to download new key pair file (.pem file)
  10. Open Terminal on Local Machine and move .pem file to ~/.ssh directory:
    mv ./awsdevelopment.pem ~/.ssh/awsdevelopment.pem
  11. Change file permissions on .pem file:
    chmod 600 ~/.ssh/awsdevelopment.pem
  12. Add key to ssh to avoid having to specify key everytime you ssh:
    ssh-add -K ~/.ssh/awsdevelopment.pem
  13. Go back to AWS instance setup window in web browser and click "Launch Instances" button
  14. AWS will now build/launch your instance (this may take a few mins).
    Click on "View Instances" Button
  15. From Instances Dashboard, Select new Instance and copy Public DNS URL
  16. Go back to Terminal on Local Machine and SSH into new Instance:
    ssh ec2-user@my.public.dns.amazonaws.com
    Where: my.public.dns.amazonaws.com is your instance's Public DNS URL
  17. Update and Install Apache, MySQL and PHP:
    sudo yum update -y
    sudo yum groupinstall -y "Web Server" "MySQL Database" "PHP Support"
    sudo yum install -y php-mysql php-devel php-zlib php-gd php-pdo
    sudo yum install -y php-mbstring pcre-devel php-pecl-oauth
    sudo service httpd start
    sudo chkconfig httpd on
    sudo groupadd www
    sudo usermod -a -G www ec2-user
    exit
  18. SSH back into the Instance to continue with new group:
    sudo chown -R root:www /var/www
    sudo chmod 2775 /var/www
    find /var/www -type d -exec sudo chmod 2775 {} +
    find /var/www -type f -exec sudo chmod 0664 {} +
    sudo -i
    sudo echo "extension=oauth.so" >> /etc/php.ini
    exit
    sudo service httpd restart
  19. Go back to AWS Instances Dashboard and Select on Instance
  20. Then Select "launch-wizard-1" security group link:
  21. Click Inbound Tab, Then Click Edit Button to Add new Inbound Rule
  22. Click Add Rule, Then Select "HTTP", Repeat for "HTTPS", Click Save
  23. Open a new web browser window and navigate to your Public DNS URL to view default page:
    http://my.public.dns.amazonaws.com
    Where: my.public.dns.amazonaws.com is your instance's Public DNS URL

Additional Information:
  • http.conf is located in /etc/httpd/conf to edit:
    sudo vi /etc/httpd/conf/http.conf
  • how to restart httpd (apache) after editing http.conf file:
    sudo service httpd restart















5 comments: