Skip to content

Instantly share code, notes, and snippets.

@tmaybe
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmaybe/7c5ca79218c9a72c8bb2 to your computer and use it in GitHub Desktop.
Save tmaybe/7c5ca79218c9a72c8bb2 to your computer and use it in GitHub Desktop.
  1. If you haven't before, follow these instructions to get set up in Amazon EC2.

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/get-set-up-for-amazon-ec2.html

  1. Follow these instructions to launch a new Amazon EC2 Instance. Use the Ubuntu AMI: Ubuntu Server 14.04 LTS (HVM) and the m3.medium instance type. As part of this process, you'll download a .pem file, which you'll need to connect to the instance.

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-instance_linux.html

  1. Connect to the instance by opening a terminal in the same directory as the .pem file you saved in step 2 and typing this command, replacing xxx.pem with the name of your .pem file, and xxx.amazonaws.com with the public DNS name of your server, which is available on the EC2/Instances dashboard page.

ssh -v -i xxx.pem ubuntu@xxx.amazonaws.com

Now refresh your package index and set up the LAMP stack (Linux, Apache, MySQL, PHP) on the new server. You will be asked to set a root MySQL password as part of this process, don't forget it!

sudo apt-get update

sudo apt-get install lamp-server^

More details are available on the Ubuntu site: https://help.ubuntu.com/community/ApacheMySQLPHP

  1. Install git on the new server as well:

sudo apt-get install git

  1. Get the application code from GitHub.

git clone https://github.com/asiafoundation/afs.git

This will pull the application code into a folder named afs. If you've already cloned the repository and just want to update the code, cd into the repository's folder and pull the new code:

cd afs

git pull origin master

  1. Make the default configuration files active.

cp ~/afs/app/config/app.php.default ~/afs/app/config/app.php

cp ~/afs/app/config/database.php.default ~/afs/app/config/database.php

  1. Log in to MySQL.

mysql -u root -p

Here's where you'll use the MySQL password you created in step 3.

  1. You're now logged into MySQL and should see a mysql> prompt. Create a database with this command.

CREATE DATABASE asia_foundation_survey;

And create a user that the application can use to connect to the database with these commands. The user's password is the string following IDENTIFIED BY.

CREATE USER 'afs_user'@'localhost' IDENTIFIED BY 'unguessable-password';

GRANT ALL ON asia_foundation_survey.* TO 'afs_user'@'localhost';

To leave MySQL, enter

QUIT;

  1. Add information about the database to the file afs/app/config/database.php

vi ~/afs/app/config/database.php (I'm using vi as an example, you can use whatever text editor you like)

In that file, you'll see lines that look something like this:

'mysql' => array(
	...
	'database'  => 'asia_foundation_survey',
	'username'  => 'username_here',
	'password'  => 'password_here',
	...
  ),

Replace the contents of those lines with the details of the database and user you created.

'mysql' => array(
	...
	'database'  => 'asia_foundation_survey',
	'username'  => 'afs_user',
	'password'  => 'unguessable-password',
	...
  ),
  1. The app needs two directories to be writable. Make that change with these commands.

chmod -R +w ~/afs/app/storage

chmod -R +w ~/afs/app/modules

  1. Create a couple more directories, for PHP plug-in dependencies.

mkdir ~/afs/app/gateways

mkdir ~/afs/app/repositories/eloquent

  1. Confirm that you're in the application's directory and install Composer, a PHP dependency manager https://getcomposer.org/

cd ~/afs

curl -sS https://getcomposer.org/installer | php

  1. Install and configure Mcrypt, a required PHP extension.

sudo apt-get install php5-mcrypt

sudo php5enmod mcrypt

  1. Use composer to install and update the plug-ins that the application needs

php composer.phar update

  1. Now you can install the application using Avelca.

./avelca_install.sh

  1. Edit a new file called afs.conf in Apache's sites-available directory, and copy the contents of the attached file there.

sudo vi /etc/apache2/sites-available/afs.conf

  1. Disable the default site and enable your new site, then restart Apache.

sudo a2dissite 000-default

sudo a2ensite afs

sudo /etc/init.d/apache2 restart

  1. Change permissions on the storage directory so the application can write there.

chmod -R 777 ~/afs/app/storage

  1. Open a web browser and navigate to http://xxx.amazonaws.com/install
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/ubuntu/afs/public
<Directory /home/ubuntu/afs/public>
Options FollowSymLinks
AllowOverride All
Require all granted
#AuthType Basic
#AuthName "Restricted"
#AuthBasicProvider file
#AuthUserFile /home/ubuntu/httpauth/.htpasswd.aseanre
#Require valid-user
</Directory>
LimitRequestBody 2147483647
<IfModule expires_module>
ExpiresActive on
<LocationMatch "\.(ico|jpe?g|gif|png|css|js|swf|flv|pdf)(\?[0-9]+)?$">
ExpiresDefault "access plus 1 year"
</LocationMatch>
</IfModule>
# compress components with gzip
<IfModule deflate_module>
AddOutputFilterByType DEFLATE text/plain text/html text/css application/x-javascript application/javascript text/javascript text/xml application/xml application/xml+rss
</IfModule>
# Disable etags
<IfModule headers_module>
<LocationMatch "\.(ico|jpe?g|gif|png|css|js|swf|flv|pdf)(\?[0-9]+)?$">
Header unset Etag
FileETag none
</LocationMatch>
</IfModule>
# Custom log file locations
ErrorLog /var/log/apache2/asf-error.log
LogLevel notice
CustomLog /var/log/apache2/asf-access.log combined
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment