This is an abbreviated guide based on Amazon's tutorials and piecemealed advice from around the web to set-up a standard website server instance with EC2. For complete explanations regarding Amazon LAMP, visit this link: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html
HTTP 80 0.0.0.0/0
HTTPS 443 0.0.0.0/0
Custom TCP Rule 1024 - 1048 0.0.0.0/0
Custom TCP Rule 20 - 21 0.0.0.0/0
- sudo yum update -y
- sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd mod24_ssl
- sudo service httpd start
- sudo usermod -a -G apache ec2-user
- exit
- reconnect to instance through ssh
- sudo chown -R ec2-user:apache /var/www/
- sudo chown -R apache:apache /var/www/
- sudo chmod 2775 /var/www
- find /var/www -type d -exec sudo chmod 2775 {} \;
- find /var/www -type f -exec sudo chmod 0664 {} \;
- sudo chown -R apache:apache /var/www/html
- sudo service httpd restart
- sudo service mysqld start
- sudo mysql_secure_installation
- sudo chkconfig mysqld on
- sudo yum install vsftpd
- sudo nano /etc/vsftpd/vsftpd.conf
- change: anonymous_enable=NO
- uncomment: chroot_local_user=YES
- add:
- pasv_enable=YES
- pasv_min_port=1024
- pasv_max_port=1048
- pasv_address=aws.public.ip.address
- local_root=/var/www/
- pasv_enable=YES
- change: anonymous_enable=NO
- sudo chkconfig --level 345 vsftpd on
- sudo /etc/init.d/vsftpd restart
- ln -s /var/www/html ~/webroot
- sudo nano /etc/httpd/conf/httpd.conf
- for <Directory "/var/www/html"> change: AllowOverride All
- for <Directory "/var/www/html"> change: AllowOverride All
- sudo service httpd restart
- sudo nano /etc/ssh/sshd_config
- change: PasswordAuthentication yes
- change: PasswordAuthentication yes
- sudo service sshd restart
- sudo adduser username
- sudo passwd username
- type in user's password
- type in user's password
- sudo usermod -d /var/www/ username
- skip this step if you plan on having this user ssh into the insatnce in the future
- sudo usermod -a -G apache username
- find /var/www -type d -exec sudo chmod 2775 {} \;
- find /var/www -type f -exec sudo chmod 0664 {} \;
- sudo service httpd restart
- sudo ln -sf /etc/httpd/conf.d/php-conf.x.x /etc/alternatives/php.conf
- sudo ln -sf /etc/httpd/conf.modules.d/15-php-conf.x.x/etc/alternatives/10-php.conf
- sudo alternatives --config php
It is preferable to add the user via cloud-init if possible, however that requires stopping the instance.
- sudo adduser username
- sudo usermod -a -G apache username
- find /var/www -type d -exec sudo chmod 2775 {} \;
- find /var/www -type f -exec sudo chmod 0664 {} \;
- sudo service httpd restart
- sudo su username
- cd
- mkdir .ssh
- chmod 700 .ssh
- touch .ssh/authorized_keys
- chmod 600 .ssh/authorized_keys
- nano .ssh/authorized_keys
- paste public key and write-out
- paste public key and write-out
- ln -s /var/www/html ~/webroot
- exit
- sudo nano /etc/sudoers.d/cloud-init
- copy the following into the file replacing the user name and write-out
- username ALL=(ALL) NOPASSWD:ALL
- username ALL=(ALL) NOPASSWD:ALL
- exit
- login into instance using key
- ssh -i "path/to/key" username@instance-address
- ssh -i "path/to/key" username@instance-address