Amazon EC2 Micro Instance - php

I am looking for a way to automatically turn off/on a microinstance on session based intervals. I need to be able to do this to automate when I am paying for the EC2 server. Does anyone know of any ways to do this using PHP or some other backend technology

You can always start and stop instances using the AWS command line tools (i.e. make a BASH script to do this) or by using the AWS PHP SDK. Of course the problem is that you will need some separate server on which you can run a cron or similar to execute your start/stop scripts.

Zend Framework 1.x have some classes to work with Amazon EC2 (Zend_Service_Amazon_Ec2).

Related

How to run python on a Godaddy shared server with cpanel?

Let me start off by saying that I know this is not the preferred way to run python, but I have had this website for several years and am looking to add additional functionality. If I try to move the site to a new host and server setup, I am afraid I will mess everything up.
I am using Godaddy shared server for my website, and I access it using cpanel. The website is a Wordpress blog but also has a few tools I built using PHP and SQL database to store the output. I want to create a chatbot using Python but from what I understand, I can't use Django on a shared Godaddy server.
Is there a way for me to run Python scripts given my limitations?
Is the best alternative for me to start a second server and build an API to process the conversation and send it back to my current website?
Shared hosting solutions tend to limit the software that can run on then. The last time I used GoDaddy, they had only a php stack, so probably no, you won't be able to use Python there.
But that's fine, you shouldn't!
If you plan on using Python, I recommend you to get a Vps, or switch to a cloud service, like Openshift.
You can find cheap and reliable Vps servers nowadays, so go for it.

Easiest way to deploy a simple AWS Beanstalk PHP app without any PHP frameworks, using RDS + ElastiCache for data

Hope someone can point me. Google doesn't yield much that's simple to understand (there's stuff like Pheanstalk, etc), and Amazon's own Beanstalk documentation as always is woefully arcane presuming that we use Laravel or Symfony2.
We have a simple set of 10 PHP scripts that constitute our entire "website", with fast functional programming. In our testing this has been much faster than doing the same things with needless OOP. Anyway, with PHP 7, we're very happy with the simple functional code we have.
We could go the EC2 route. Two EC2 servers load balanced by ELB. Both EC2 servers just have Nginx running with PHP-FPM, and calling the RDS stuff for data (ElastiCache for some caching speed for read-only queries).
However, the idea is to lower management costs for EC2 by relying on Beanstalk for the simple processing that's needed in these 10 PHP scripts.
Are we thinking the right way? Is it simple to "upload" scripts to Beanstalk in the way we do in EC2 via SSH or SFTP? Or is that only programatically available via git etc?
You can easily replicate your EC2 environment to Elastic Beanstalk using Docker containers.
Create a Docker container that contains required packages (nginx etc), any configuration files, and your PHP scripts. Then you'd deploy the container to Beanstalk.
With Beanstalk, you can define environment variables that are passed to underlying EC2 instances where you application is running. Typically, one would use environment variables to pass, for example, the RDS hostname, username, and password to the Beanstalk application.
Additionally, you can store the Dockerfile, configuration files, and scripts in your git repository for version control, and fetch them whenever you create the container.
See AWS documentation about deploying beanstalk application from Docker containers.

Using AWS for SQL and REST frontend

I'm trying to set up a PostgreSQL db with a REST(php) gate. I want to access this database the standard REST way (using GET and Headers), from a C# application.
Currently I am using a standard web hoster that has a MySQL database, but I want to jump ship to PostgreSQL.
Am I right in thinking Amazon's EC2 servers a good choice to do this? I just need a server with PostgreSQL installed and a bunch of php scripts (for REST).
Thanks
EC2 would work fine, or you could use an RDS PostgreSQL instance, and just run the PHP scripts on a small EC2 instance.
Check out restSQL. It's an open-source, ultra-lightweight persistence layer, with out of the box PostgreSQL support.
It's written in Java but you can use its HTTP API by deploying the service in a standard JEE container, e.g. Tomcat, or as a Docker container. The latest versions are on bundled as images on docker hub.
You can take it for a spin using the sandboxed instance and explore the docs at http://restsql.org.

How to host a PHP file with AWS?

After many hours of reading documentation and messing around with Amazon Web Services. I am unable to figure out how to host a PHP page.
Currently I am using the S3 service for a basic website, but I know that this service does not support dynamic pages. I was able to use the Elastic Beanstalk to make the Sample Application running PHP. But i have really no idea how to use it. I read up on some other services but they don't seem to do what I want or they are just way to confusing.
So what I want to be able to do is host a website with amazon that has dynamic PHP pages. Is this possible and what services do you use?
For a PHP app, you really have two choices in AWS.
Elastic Beanstalk is a service that takes your code, and manages the runtime environment for you - once you've set it up, it's very easy to deploy, and you don't have to worry about managing servers - AWS does pretty much everything for you. You have less control over the environment, but if your server will run in EB then this is a pretty easy path.
EC2 is closer to conventional hosting. You need to decide how your servers are configured & deployed (what packages get installed, what version of linux, instance size, etc), your system architecture (do you have separate instances for cache or database, whether or not you need a load balancer, etc) and how you manage availability and scalability (multiple zones, multiple data centers, auto scaling rules, etc).
Now, those are all things that you can use - you dont have to. If you're just trying to learn about php in AWS, you can start with a single EC2 instance, deploy your code, and get it running in a few minutes without worring about any of the stuff in the previous paragraph. Just create an instance from the Amazon Linux AMI, install apache & php, open the appropriate ports in the firewall (AKA the EC2 security group), deploy your code, and you should be up & running.
Your Php must run on EC2 machines.
Amazon provides great tools to make life easy (Beanstalk, ECS for Docker ...) but at the end, you own EC2 machines.
There is no a such thing where you can put your Php code without worrying about anything else ;-(
If you are having problems hosting PHP sites on AWS then you can go with a service provider like Cloudways. They provide managed AWS servers with one click installs of PHP frameworks and CMS.

PHP script on Amazon EC2 possibly cached

I've got a PHP script on an Amazon EC2 instance. I changed a couple things in it, but the output is the same when I load it in my browser. Does Amazon have some sort of caching in place? I know the East zone was down today, but my instance is running fine now. I've ruled out client-side caching already.
In our ec2 instances this sort of thing happens in 2 scenarios:
1) a bug in our deployment ( for example, puppet or another deploy tool did something funny) or
2) git : a branch was not pushed to head, but the server redeploy happend.
Unless you are using a caching system which you know of, there is no reason to think that ec2 is caching things under the hood - ec2 is controlled and configured quite directly .

Categories