Last active
February 5, 2016 06:37
-
-
Save AtsushiA/07f30e13d2800ac864ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Set sqlpassword | |
MYSQL_PASSSWORD="$(curl http://169.254.169.254/latest/meta-data/instance-id)" | |
#Set Timezon | |
cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime | |
sed -i -e "s/ZONE=.*$/ZONE=\"Asia\/Tokyo\"/" /etc/sysconfig/clock | |
sed -i -e "s/UTC=.*$/UTC=false/" /etc/sysconfig/clock | |
echo 'ARC=false' >> /etc/sysconfig/clock | |
service crond restart | |
#update | |
yum update -y | |
#install apache & MYSQL & PHP | |
sudo yum groupinstall -y "Web Server" "MySQL Database" "PHP Support" | |
yum install -y php php-devel php-mysql php-mbstring php-gd | |
#yum install -y php56-devel php56-mysqlnd php56-pdo php56-mbstring php56-gd | |
#Set apache setting | |
sed -e 's/AddDefaultCharset UTF-8/AddDefaultCharset Off/g' /etc/httpd/conf/httpd.conf | |
sed '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride all/' /etc/httpd/conf/httpd.conf | |
sed -i -e 's/User apache/User ec2-user/g' /etc/httpd/conf/httpd.conf | |
sed -i -e 's/Group apache/Group apache/g' /etc/httpd/conf/httpd.conf | |
#Set php setting | |
sed -i "s/^;date.timezone =$/date.timezone = \"Asia\/Tokyo\"/" /etc/php.ini | |
#Set User Group & Permission | |
usermod -a -G apache ec2-user | |
chown -R ec2-user:apache /var/www/ | |
chmod g+s -R ec2-user:apache /var/www/ | |
find /var/www/ -type d -exec chmod 755 {} + | |
find /var/www/ -type f -exec chmod 644 {} + | |
# we'll install 'expect' to input keystrokes/y/n/passwords | |
yum install -y expect | |
#Set mysql | |
service mysqld start | |
SECURE_MYSQL=$(expect -c " | |
set timeout 10 | |
spawn mysql_secure_installation | |
expect \"Enter current password for root (enter for none):\" | |
send \"\r\" | |
expect \"Set root password?\" | |
send \"y\r\" | |
expect \"New password:\" | |
send \"$MYSQL_PASSSWORD\r\" | |
expect \"Re-enter new password:\" | |
send \"$MYSQL_PASSSWORD\r\" | |
expect \"Remove anonymous users?\" | |
send \"y\r\" | |
expect \"Disallow root login remotely?\" | |
send \"y\r\" | |
expect \"Remove test database and access to it?\" | |
send \"y\r\" | |
expect \"Reload privilege tables now?\" | |
send \"y\r\" | |
expect eof | |
") | |
echo "$SECURE_MYSQL" | |
# Remove 'expect' to input keystrokes/y/n/passwords | |
yum remove -y expect | |
## Create swap files so we need to make one | |
## adding line to fstab so it's enabled on boot | |
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024 | |
sudo mkswap /swapfile | |
sudo chmod 0600 /swapfile | |
sudo swapon /swapfile | |
sudo sed -i '$ a\/swapfile swap swap defaults 0 0' /etc/fstab | |
#Service Start & Set apache | |
service httpd start | |
service mysqld start | |
chkconfig httpd on | |
chkconfig mysqld on | |
#reboot | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment