AWS EC2 Setup Up

Installing a LAMP Web Server

  1. Signup AWS account
  2. Create IAM account
  3. Create Private key pair
  4. Config Security Group for inbound rules
  5. Set up Elastic IP
  6. SSH to Instance
# set permission of your private key file
chmod 400 me-key-pair.pem
# login as ec2-user
ssh -i me-key-pair.pem ec2-user@public-dns

LAMP Server (Amazon Linux AMI)

# install lamp packages
yum install httpd24 php56 mysql57-server php56-mysqlnd php56-mbstring
# improve php 
yum install php56-fpm php56-opcache
# start web server and config to run at system boot
service httpd start
chkconfig httpd on
# start mysql server and config to run at system boot
service mysqld start
mysql_secure_installation
chkconfig mysqld on

Set LC_CTYPE

Fix `-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory` warning

sudo vi /etc/environment
# add below two lines
LANG=en_US.utf-8
LC_ALL=en_US.utf-8

Display Error in PHP

sudo vim /etc/php.ini
display_errors = On
sudo service httpd reload

Node JS and NPM Install

MongoDB

Install PHP Driver for Rockmongo

Apache Default Config

sudo vim /etc/httpd/conf.d/httpd.conf
sudo httpd -t
sudo service httpd reload
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT=”/etc/httpd”
-D SUEXEC_BIN=”/usr/sbin/suexec”
-D DEFAULT_PIDLOG=”/var/run/httpd/httpd.pid”
-D DEFAULT_SCOREBOARD=”logs/apache_runtime_status”
-D DEFAULT_ERRORLOG=”logs/error_log”
-D AP_TYPES_CONFIG_FILE=”conf/mime.types”
-D SERVER_CONFIG_FILE=”conf/httpd.conf”

Install phpMyAdmin

sudo yum --enablerepo=epel install phpmyadmin
sudo ln -s /usr/share/phpMyAdmin /data/webroot/uphpmyadmin

Webadmin Account Setup

# create user
sudo adduser webadmin
# set password
sudo passwd webadmin
# create webroot directory
sudo mkdir -p /data/webroot
sudo chown webadmin.webadmin /data/webroot
# change home dir to webroot
sudo usermod -m -d /data/webroot webadmin
# change PasswordAuthentication to yes 
vim /etc/ssh/sshd_config
# restart sshd
sudo service sshd restart
# add www groups for webroot
sudo usermod -a -G apache webadmin
sudo chown -R webadmin:apache /data/webroot
sudo chmod 2775 /data/webroot && find /data/webroot -type d -exec sudo chmod 2775 {} \;
find /
data/webroot -type f -exec sudo chmod 0664 {} \;

httpd.conf Sample

<VirtualHost *:80>
ServerName ec2–52–74–204–208.ap-southeast-1.compute.amazonaws.com
DocumentRoot /data/webroot/
DirectoryIndex index.html index.php
<Directory "/data/webroot/">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName superpowerlab.net
ServerAlias www.superpowerlab.net
DocumentRoot /data/webroot/superpowerlab.net
ErrorLog logs/superpowerlab.net_error_log
CustomLog logs/superpowerlab.net_access_log common
DirectoryIndex index.html index.php
<Directory "/data/webroot/superpowerlab.net">
AllowOverride All
Require all granted
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.superpowerlab\.net [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.superpowerlab.net/$1 [L,R,NE]
</IfModule>
</VirtualHost>

Wordpress Setup

# download latest source code
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
rm latest.tar.gz
# add apache to group www
sudo usermod -a -G www apache
# change owner to apache for file upload in wp-admin
sudo chown -R apache:www /data/webroot/domain.com/wordpress