AWS EC2 Setup Up

Installing a LAMP Web Server

Set Elastic IP

Config Security Group for inbound rules

Migrate PHP 5.3 to 5.6

# remove old package of php 5.3 and Apache 2.2
sudo yum remove php httpd php-cli php-xml php-common httpd-tools
# install new package
sudo yum install httpd24 php56 mysql55-server php56-mysqlnd php56-mbstring
# optional install for other php dependencies
sudo yum install php56-opcache php56-mcrypt php56-gd php56-mbstring
# check version
php -v
apachectl -V
# start web server and config to run at system boot
sudo service httpd start
sudo chkconfig httpd on
# start mysql server and config to run at system boot
sudo service mysqld start
sudo mysql_secure_installation
sudo 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 php-5.6.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 webroot owner for FTP access for wordpress
sudo chown -R apache:apache /data/webroot
# change home dir to webroot
sudo usermod -m -d /data/webroot webadmin
# change PasswordAuthentication to yes 
sudo vim /etc/ssh/sshd_config
# restart sshd
sudo service sshd restart
# add www groups for webroot
sudo groupadd www
sudo usermod -a -G www webadmin
sudo chown -R webadmin:www /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
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.