Skip to content

Instantly share code, notes, and snippets.

@plainspooky
Last active Mar 20, 2018
Embed
What would you like to do?
Vagrantfile to setup a Wordpress site on virtual machine running Ubuntu 17.10
.vagrant
*.log
*.tar.gz
#!/usr/bin/env bash
apt-get update &&\
apt-get --yes install apache2
#!/usr/bin/env bash
WP_DIR="$( cat /vagrant/wordpress_dir )"
if [[ ! -f /etc/apache2/mods-enabled/rewrite.* ]]; then
a2enmod rewrite
fi
a2dissite 000-default
cat >/etc/apache2/sites-available/wordpress.conf <<EOT
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot ${WP_DIR}
<Directory ${WP_DIR}>
AllowOverride All
</Directory>
ErrorLog \${APACHE_LOG_DIR}/${WP_DIR##*/}-error.log
CustomLog \${APACHE_LOG_DIR}/${WP_DIR##*/}-access.log combined
</VirtualHost>
EOT
a2ensite wordpress
systemctl restart apache2.service
#!/usr/bin/env bash
apt-get update &&\
apt-get --yes install mariadb-server
#!/usr/bin/env bash
WP_PASS_FILE="/vagrant/wordpress_db_passwd"
if [[ ! -f ${WP_PASS_FILE} ]]; then
cat /dev/urandom |\
tr -dc 'a-zA-Z0-9' |\
fold -w 32 |\
head -n 1 |\
tee > ${WP_PASS_FILE}
fi
WP_PASS=$( cat ${WP_PASS_FILE} )
WP_USER=$( cat /vagrant/wordpress_db_user )
WP_DBNAME=$( cat /vagrant/wordpress_db_name )
systemctl restart mariadb.service
mariadb --user=root <<EOT
create database ${WP_DBNAME};
create user '${WP_USER}'@'localhost' identified by '${WP_PASS}' ;
grant all privileges on ${WP_DBNAME}.* to '${WP_USER}'@'localhost';
EOT
#!/usr/bin/env bash
apt-get update &&\
apt-get --yes install php php-mysql
#!/usr/bin/env bash
apt-get update &&\
apt-get --yes dist-upgrade &&\
apt-get --yes --purge autoremove
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/artful64"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "512"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
end
config.vm.network "forwarded_port", guest: 80, host: 8000
config.vm.provision "shell", path:"./software_update.sh"
config.vm.provision "shell", path:"./apache2_install.sh"
config.vm.provision "shell", path:"./mariadb_install.sh"
config.vm.provision "shell", path:"./php7_install.sh"
config.vm.provision "shell", path:"./apache2_setup.sh"
config.vm.provision "shell", path:"./mariadb_setup.sh"
config.vm.provision "shell", path:"./wordpress_install.sh"
config.vm.provision "shell", path:"./wordpress_setup.sh"
config.vm.provision "shell", path:"./wordpress_parms.sh"
end
/var/www/wordpress
#!/usr/bin/env bash
WP_DIR="$( cat /vagrant/wordpress_dir )"
WP_FILE="/vagrant/wordpress_latest.tar.gz"
curl https://wordpress.org/latest.tar.gz > ${WP_FILE}
mkdir -p ${WP_DIR}
cd ${WP_DIR}
tar zxvf ${WP_FILE} --strip-components 1
chown -Rv www-data.www-data *
#!/usr/bin/env bash
WP_DIR=$( cat /vagrant/wordpress_dir )
WP_PASS=$( cat /vagrant/wordpress_db_passwd )
WP_USER=$( cat /vagrant/wordpress_db_user )
WP_DBNAME=$( cat /vagrant/wordpress_db_name )
echo "Database configuration for Wordpress"
echo "===================================="
echo "username ....: ${WP_USER}"
echo "password ....: ${WP_PASS}"
echo "database ....: ${WP_DBNAME}"
#!/usr/bin/env bash
WP_DIR="$( cat /vagrant/wordpress_dir )"
WP_SITE="${WP_DIR##*/}"
cd ${WP_DIR}
if [[ -f .htaccess ]]; then
mv .htaccess .htaccess_ORIGINAL
fi
cat > ${WP_DIR}/.htaccess <<EOT
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /${WP_SITE}/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /${WP_SITE}/index.php [L]
</IfModule>
EOT
chown www-data.www-data ${WP_DIR}/.htaccess
chown root.www-data ${WP_DIR}
chmod 775 ${WP_DIR}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment