Last active
March 20, 2018 03:17
-
-
Save plainspooky/3da6e80052f81c7a5dd9586ff1e74e0f to your computer and use it in GitHub Desktop.
Vagrantfile to setup a Wordpress site on virtual machine running Ubuntu 17.10
This file contains 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
.vagrant | |
*.log | |
*.tar.gz |
This file contains 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
#!/usr/bin/env bash | |
apt-get update &&\ | |
apt-get --yes install apache2 | |
This file contains 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
#!/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 | |
This file contains 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
#!/usr/bin/env bash | |
apt-get update &&\ | |
apt-get --yes install mariadb-server | |
This file contains 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
#!/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 | |
This file contains 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
#!/usr/bin/env bash | |
apt-get update &&\ | |
apt-get --yes install php php-mysql |
This file contains 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
#!/usr/bin/env bash | |
apt-get update &&\ | |
apt-get --yes dist-upgrade &&\ | |
apt-get --yes --purge autoremove | |
This file contains 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
# -*- 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 |
This file contains 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
wordpress |
This file contains 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
wordpress |
This file contains 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
/var/www/wordpress |
This file contains 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
#!/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 * | |
This file contains 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
#!/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}" | |
This file contains 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
#!/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