Forked from reitermarkus/digitalocean-centos-wordpress.sh
Last active
July 18, 2018 03:51
-
-
Save CharlyRipp/667addcf7113b162ee99aadf8efc7a01 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/bash | |
rando() { | |
echo `dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev | sed 's#/#_#g' ` | |
} | |
DATABASE_NAME='wordpress' | |
DATABASE_USER='wordpress' | |
ROOT_MYSQL_PASSWORD=`rando` | |
WORDPRESS_MYSQL_PASSWORD=`rando` | |
# Write Passwords to File. | |
echo "Root MySQL Password: $ROOT_MYSQL_PASSWORD" >> /root/passwords.txt | |
echo "Wordpress MySQL Password: $WORDPRESS_MYSQL_PASSWORD" >> /root/passwords.txt | |
# Installs | |
yum -y install epel-release http://rpms.remirepo.net/enterprise/remi-release-7.rpm | |
yum-config-manager --enable remi-php72 | |
cat <<EOF >> /etc/yum.repos.d/MariaDB.repo | |
[mariadb] | |
name = MariaDB | |
baseurl = http://yum.mariadb.org/10.3/centos7-amd64 | |
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB | |
gpgcheck=1 | |
EOF | |
yum makecache fast | |
yum -y update | |
yum -y install wget firewalld httpd \ | |
MariaDB-server MariaDB-client \ | |
php php-mysqlnd php-opcache | |
## Startup | |
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 | |
# Set up Database User | |
systemctl enable mariadb.service | |
systemctl start mariadb | |
mysqladmin -u root -h localhost password $ROOT_MYSQL_PASSWORD | |
mysql -uroot -p$ROOT_MYSQL_PASSWORD <<_EOF_ | |
DELETE FROM mysql.user WHERE User=''; | |
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1'); | |
DROP DATABASE IF EXISTS test; | |
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'; | |
CREATE USER '${DATABASE_USER}'@'localhost' IDENTIFIED BY '${WORDPRESS_MYSQL_PASSWORD}'; | |
CREATE DATABASE ${DATABASE_NAME}; | |
GRANT ALL PRIVILEGES ON ${DATABASE_NAME}.* TO '${DATABASE_USER}'@'localhost'; | |
FLUSH PRIVILEGES; | |
_EOF_ | |
# Install | |
rm -f /var/www/html/index.html | |
mkdir /var/www/wordpress/ | |
wget -qO- https://wordpress.org/latest.tar.gz | tar xvz --strip-components=1 -C /var/www/wordpress/ | |
cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php | |
sed -i "s/'database_name_here'/'$DATABASE_NAME'/g" /var/www/wordpress/wp-config.php | |
sed -i "s/'username_here'/'$DATABASE_USER'/g" /var/www/wordpress/wp-config.php | |
sed -i "s/'password_here'/'$WORDPRESS_MYSQL_PASSWORD'/g" /var/www/wordpress/wp-config.php | |
for i in $(seq 1 8); do | |
sed -i "0,/put your unique phrase here/s//`rando`/" /var/www/wordpress/wp-config.php | |
done | |
mkdir /var/www/wordpress/wp-content/uploads | |
semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/wordpress/wp-content/uploads(/.*)?" | |
restorecon -Rv /var/www/wordpress/wp-content/uploads | |
chcon -R -t httpd_sys_rw_content_t /var/www/wordpress/ | |
chown -Rf apache:apache /var/www/wordpress | |
cat <<EOF >> /etc/httpd/conf.d/wordpress.conf | |
Alias / "/var/www/wordpress/" | |
<Directory "/var/www/wordpress/"> | |
Order Deny,Allow | |
Deny from all | |
Allow from all | |
AllowOverride all | |
</Directory> | |
EOF | |
systemctl enable httpd.service | |
systemctl start httpd | |
# Create Swapfile | |
dd if=/dev/zero of=/swapfile count=512 bs=1MiB | |
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 |
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 | |
# Helpers | |
rando() { | |
echo `dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev | sed 's#/#_#g' ` | |
} | |
# Config | |
DATABASE_NAME='wordpress' | |
DATABASE_USER='wordpress' | |
ROOT_MYSQL_PASSWORD=`rando` | |
WORDPRESS_MYSQL_PASSWORD=`rando` | |
# 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. | |
yum -y install epel-release http://rpms.remirepo.net/enterprise/remi-release-7.rpm | |
yum-config-manager --enable remi-php72 | |
# Update packages. | |
yum -y update | |
# Install packages. | |
yum -y install wget firewalld httpd \ | |
mariadb mariadb-server \ | |
php php-mysqlnd php-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 -qO- https://wordpress.org/latest.tar.gz | tar xvz --strip-components=1 -C /var/www/html/ | |
cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php | |
sed -i "s/'database_name_here'/'$DATABASE_NAME'/g" /var/www/html/wp-config.php | |
sed -i "s/'username_here'/'$DATABASE_USER'/g" /var/www/html/wp-config.php | |
sed -i "s/'password_here'/'$WORDPRESS_MYSQL_PASSWORD'/g" /var/www/html/wp-config.php | |
for i in $(seq 1 8); do | |
sed -i "0,/put your unique phrase here/s//`rando`/" /var/www/html/wp-config.php | |
done | |
rm -f /var/www/html/index.html | |
chown -Rf apache:apache /var/www/html | |
# Create Swapfile | |
dd if=/dev/zero of=/swapfile count=512 bs=1MiB | |
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