Friday, November 22, 2013

EC2 Ubuntu Apache PHP MySQL Setup


  1. In order to connect to the instance we need to assign an IP address. In the left menu in the EC2 Management Console select Elastic IPs under Network & Security. Allocate a new address and assign it to your instance. Elastic IPs are free as long as they are assigned to an instance, so remeber not to leave any unallocated IP addresses as you will get charged by the hour. Remember the assigned IP.
  2. On your local machine use the pem key to SSH into your instance. On OS X change the permission of the key to 600 and use following command in terminal:
    ssh -i yourkeyname.pem ubuntu@yourelasticip
    and boom you are in.
  3. Update the Ubuntu package manager and the installed packages:
    sudo apt-get update
    sudo apt-get dist-upgrade
  4. Install Apache:
    sudo apt-get install apache2
  5. Enable .htaccess files by editing the /etc/apache2/sites-available/default file, fx with vi or nano. Look for the /var/www directory and make sure it contains AllowOverride All.     <Directory /var/www/>
                    Options Indexes FollowSymLinks MultiViews
                    AllowOverride All
                    Order allow,deny
                    allow from all
    </Directory>
  6. Enable the rewrite module in Apache:
    sudo a2enmod rewrite
  7. Install PHP5:
    sudo apt-get install libapache2-mod-php5
  8. Restart Apache:
    sudo /etc/init.d/apache2 restart
  9. Ensure that Apache is running by typing the instance IP in your browser.
  10. Allow the Ubuntu user to work with the /var/www folder:
    sudo adduser ubuntu www-data
    sudo chown -R www-data:www-data /var/www
    sudo chmod -R g+rw /var/www
    Logout and login again to pick up the new user group. Test by creating a directory and deleting it again in www without having to sudo. This will make your life easier since permissions will get messed up less once you start adding frameworks and tools to your web service.
  11. Test PHP by cd into /var/www folder and typing sudo vi phptest.php. Hit i key to enter insert mode and just write a simple php script with a phpinfo() call.
    Hit ESC to exit insert mode and type :wq to save and quit the vi editor. Go to instanceIP/phptest.php in your browser and you should see the phpinfo displayed.
  12. Install MySQL:
    sudo apt-get install mysql-server
    sudo apt-get install php5-mysql
    Insert root password for the database and remember it.
  13. To test MySQL let’s install PHPMyAdmin:
    sudo apt-get install phpmyadmin
Next I think you need to install git.I don't prefer to use FTP client.
  1. sudo apt-get install git