Skip to content

Instantly share code, notes, and snippets.

@artnic
Created April 21, 2017 14:55
Show Gist options
  • Save artnic/274005643a587e44fa22c9cd4551f773 to your computer and use it in GitHub Desktop.
Save artnic/274005643a587e44fa22c9cd4551f773 to your computer and use it in GitHub Desktop.
This script install Apache + PHP + MySQL + Wordpress to given URL. It creates the database and do all the stuff necessary to run wordpress. If you don't want a wordpress installation, just skip the latter lines of this file
#!/bin/sh
# This is how I install apache + php + mysql + wordpress to get up and running in less than 1 minute
# this works for an Amazon AMI instance. Other distros migh need changes to this script
# You can put this script to run when creating an instance at AWS Console. Once machine is up, everything is set up
_SITE_URL_='site.example.com' # note that there's no protocol in the URL here
_DB_ROOT_PASS_='ReallyStrongDatabaseRootPassword'
_DB_USER_='MySQLUserAllowedToAccessFromOutside'
_DB_USERPASS_='CreatedMySQLUsersPassword'
_DB_NAME_='DatabaseNameForTheWPInstallation'
_WP_SITE_TITLE_='Wordpress Site Title'
_WP_ADMIN_PASS_='WordpressAdminPassword'
_WP_ADMIN_EMAIL_='WordpressAdminEmail' # once completed, server sends 'installation completed' email to this one
# I usually do this to know which sites are installed in this machine quickly
touch /root/${_SITE_URL_}
touch /home/ec2-user/${_SITE_URL_}
sudo yum update -y
sudo ln -sf /usr/share/zoneinfo/America/Sao_Paulo \
/etc/localtime
sudo yum install -y gcc make gcc-c++
# installing php, apache, mbstring, php-apc, php-gd, etc
sudo yum install httpd24 php54 php54-gd php54-mysql php54-mcrypt php54-mbstring php54-pdo php54-common php54-pecl-apc mod24_ssl -y
sudo yum install mysql-server -y
sudo service mysqld start
# configuring httpd.conf and adding a site (VirtualHost) to it
sudo mkdir -p /var/www/html/${_SITE_URL_}
sudo chown apache:apache /var/www/html/${_SITE_URL_} -Rf
sudo chmod +x /var/www/html/${_SITE_URL_} -Rf
echo '<VirtualHost *:80>
DocumentRoot /var/www/html/${_SITE_URL_}/
ServerName ${_SITE_URL_}
ServerAlias www.${_SITE_URL_}
<Directory "/var/www/html/${_SITE_URL_}">
Require all granted
Options +Indexes
</Directory>
ErrorLog logs/${_SITE_URL_}-error_log
CustomLog logs/${_SITE_URL_}-access_log common
</VirtualHost>' | sudo tee /etc/httpd/conf.d/${_SITE_URL_}.conf
sudo service httpd restart
# configuring mysql users
mysqladmin -u root password ${_DB_ROOT_PASS_}
mysql -uroot -p${_DB_ROOT_PASS_} -e "GRANT ALL on *.* to '${_DB_USER_}'@'localhost' identified by '${_DB_USERPASS_}';grant all on *.* to '${_DB_USER_}'@'%' identified by '${_DB_USERPASS_}'; FLUSH PRIVILEGES;"
mysqladmin -uroot -p${_DB_ROOT_PASS_} create ${_DB_NAME_}
# configuring services to run at startup
sudo chkconfig mysqld on
sudo chkconfig httpd on
# BONUS: installing Wordpress via wpcli with given URL and database
# You should remove lines below if you don't want to fresh install wordpress
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
/usr/local/bin/wp --info
sudo mkdir /opt/wpcli/
cd /opt/wpcli/
sudo wget https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash
sudo echo 'source /opt/wpcli/wp-completion.bash' >> /root/.bash_profile
sudo echo 'source /opt/wpcli/wp-completion.bash' >> /home/ec2-user/.bash_profile
cd /var/www/html/${_SITE_URL_}
sudo /usr/local/bin/wp core download --allow-root
sudo /usr/local/bin/wp core config --dbhost=localhost --dbname=${_DB_NAME_} --dbuser=${_DB_USER_} --dbpass=${_DB_USERPASS_} --allow-root
sudo /usr/local/bin/wp core install --url=${_SITE_URL_} --title="${_WP_SITE_TITLE_}" --admin_name=admin --admin_password=${_WP_ADMIN_PASS_} --admin_email=${_WP_ADMIN_EMAIL_} --allow-root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment