Last active
April 24, 2019 05:28
-
-
Save reitermarkus/e9b1c9e979e829469fa6 to your computer and use it in GitHub Desktop.
Install WordPress on DigitalOcean CentOS Droplet with PHP 7
This file contains hidden or 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/sh | |
DATABASE_NAME='wordpress' | |
DATABASE_USER='wordpress' | |
ROOT_MYSQL_PASSWORD=`dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev` | |
WORDPRESS_MYSQL_PASSWORD=`dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev` | |
# Write Passwords to File. | |
echo "Root MySQL Password: $ROOT_MYSQL_PASSWORD" >> /root/passwords.txt | |
echo "Wordpress MySQL Password: $WORDPRESS_MYSQL_PASSWORD" >> /root/passwords.txt | |
# Add PHP 7 repos. | |
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm | |
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm | |
# Update packages. | |
yum -y update | |
# Install packages. | |
yum -y install httpd | |
yum -y install mariadb mariadb-server | |
yum -y install php70w php70w-cli php70w-common php70w-mysql php70w-opcache | |
# Start Services | |
systemctl enable firewalld.service | |
systemctl start firewalld | |
firewall-cmd --permanent --zone=public --add-service=http | |
firewall-cmd --permanent --zone=public --add-service=https | |
firewall-cmd --reload | |
systemctl enable httpd.service | |
systemctl start httpd | |
systemctl enable mariadb.service | |
systemctl start mariadb | |
# Set up Database User | |
mysqladmin -u root -h localhost create $DATABASE_NAME | |
mysqladmin -u root -h localhost password $ROOT_MYSQL_PASSWORD | |
mysql -uroot -p$ROOT_MYSQL_PASSWORD -e "CREATE USER $DATABASE_USER@localhost IDENTIFIED BY '"$WORDPRESS_MYSQL_PASSWORD"'" | |
mysql -uroot -p$ROOT_MYSQL_PASSWORD -e "GRANT ALL PRIVILEGES ON $DATABASE_NAME.* TO $DATABASE_USER@localhost" | |
# Install WordPress | |
wget https://wordpress.org/latest.tar.gz -O /tmp/wordpress.tar.gz | |
cd /tmp/ && tar xf wordpress.tar.gz && cp wordpress/wp-config-sample.php wordpress/wp-config.php | |
sed -i "s/'database_name_here'/'$DATABASE_NAME'/g" /tmp/wordpress/wp-config.php | |
sed -i "s/'username_here'/'$DATABASE_USER'/g" /tmp/wordpress/wp-config.php | |
sed -i "s/'password_here'/'$WORDPRESS_MYSQL_PASSWORD'/g" /tmp/wordpress/wp-config.php | |
for i in $(seq 1 8); do | |
wp_salt=$(</dev/urandom tr -dc 'a-zA-Z0-9!@#$%^&*()\-_ []{}<>~`+=,.;:/?|' | head -c 64 | sed -e 's/[\/&]/\\&/g') | |
sed -i "s/put your unique phrase here/$wp_salt/g" /tmp/wordpress/wp-config.php | |
done | |
cp -Rf /tmp/wordpress/* /var/www/html/ | |
rm -f /var/www/html/index.html | |
chown -Rf apache:apache /var/www/html | |
# Create Swapfile | |
fallocate -l 512M /swapfile | |
chmod 600 /swapfile | |
mkswap /swapfile | |
swapon /swapfile | |
echo '/swapfile swap swap sw 0 0' >> /etc/fstab | |
echo 'vm.swappiness = 10' >> /etc/sysctl.conf | |
echo 'vm.vfs_cache_pressure = 50' >> /etc/sysctl.conf | |
reboot -h now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Greetings! Great yet simple -- I'm doing this on AWS and thought I'd leave a few findings.
I opted to go to PHP7.2 and some dependencies were not on a base CentOS 7 box (at least in AWS)
For random password/key generation, I standardized using the
dd
command and made a small helper functionNote the replacement of
/
with_
as forward slashes were causing issues insed
commands replacing passwords and salts.This was also used in the salt generation, which your
sed
command replaces globally, setting all salts to the first generated salt in thefor
loop. I fixed this and streamlined it:Finally the swapfile - I was having an issue where
fallocate
wasn't physically allocating the space, causingswapon
to fail. Switching to usingdd
to establish the file seemed to fix it. See https://unix.stackexchange.com/questions/294600/i-cant-enable-swap-space-on-centos-7I created a fork incase anyone was interested in the full file - https://gist.github.com/CharlyRipp/667addcf7113b162ee99aadf8efc7a01
Tried to piece it back together to closely resemble the original - my end product is more split out to have an ephemeral AMI that spins up, syncs with existing instances, and joins the autoscaling group.