Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Muminur/568f548260205d009d071e1e7e82817c to your computer and use it in GitHub Desktop.
Save Muminur/568f548260205d009d071e1e7e82817c to your computer and use it in GitHub Desktop.
Install WordPress on DigitalOcean CentOS Droplet with PHP 7
#!/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