Wednesday, June 12, 2013

Amazon Tips and Tricks

Getting PHP and MySQL running on amazon EC2

http://www.alexkorn.com/blog/2011/03/getting-php-mysql-running-amazon-ec2/#note1back 



How to run PHP site using EC2 and S3

You need to start a new EC2 instance with a image (AMI) that contains the minimal configuration you need. You can use the Amazon Linux images which has nothing on it and install Apache and PHP or try to find a community image that already contains Apache and PHP.

Afterwards install your PHP application in the relevant places in the instance.

Create an S3 bucket.
Copy your static files (images, css, javascripts) to the bucket.

Update the references to images, css, js files in your code to point to the S3 bucket.

If you are not doing anything too fancy with your Javascript code they will run correctly even from S3.




To Launce an instance

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html?r=1874



Create database in amazon EC2 


Since you have an account with Amazon and EC2, you can use their console:https://console.aws.amazon.com/ec2/home.
In the console, click on Instances, then Launch Instance to create a new virtual machine. There are lots of operating systems to choose from; a good choice for a first instance would be 32-bit Ubuntu running on an m1.small instance.
If you already have a Keypair, select the one you want from the list. Otherwise, you can create a new Keypair in the Keypair dialog. When the new instance has been created, you can use the keypair to connect to it, using a command like:
ssh -i siva_keypair root@InstancePublicDNS
You can get the instance public DNS name from the console. At this point, you're basically logged on to a new machine, and can use it in any way you would use a real, physical machine.
By the sound of it, you're going to want to create some user accounts, install an FTP server and MySQL (use apt-get if you're on Ubuntu).
Note that you can lose data which you put on the local disk if an instance goes down - if you're running a database you should use EBS which is very easy to set up, and gets you persistent, fast storage which can be attached to any EC2 instance.



Load Data into Tables Using the AWS SDK for PHP



how to view php, mysql, apache2 install or not 
  • which php return /usr/bin/php
  • which mysql return /usr/bin/mysql
  • which apache2 return /usr/sbin/apache2

loginto mysql
  • mysql -u username -p

show databases

apache2 error log
  • /var/log/apache2

restart services command
  • sudo service mysql restart
get which service run in 80 port
  • sudo lsof -i:80



php setup in amazon nginx server

phpmyadmin setup in amazon nginx server


defult setting file in nginx server path
  • /etc/nginx/sites-available
Install smtp
  • sudo apt-get install sendmail



how to add cron-job in ubuntu

cron job log
  • /var/log/syslog 



How to connect amazon server using FTP
  • Open FileZilla and go to preferences.
  • Under preferences click sftp and add a new key. This is your key pair for your ec2 instance. You will have to convert it to the format FileZilla uses. It will give you a prompt for the file format conversion.
  • Click okay and go back to site manager
  • In site manager enter in your EC2 public address, this can also be your elastic IP
  • Make sure the protocol is set to SFTP
  • Write in the username its the name of ec2-user
  • Remove everything from the password field - leave it blank
  • All done! Now connect.

No comments:

Post a Comment