DevOps 2.5: Effortless WordPress Automation
"Efficiently Automate WordPress Deployment and Configuration"
Table of contents
INTRODUCTION:
In "DevOps 2.5: Automate WordPress Setup," we'll dive into the world of automation to streamline the process of deploying and configuring WordPress websites efficiently. Whether you're a seasoned pro or just starting with DevOps, these automation techniques will save you time and effort while ensuring a smooth WordPress setup. Join us in simplifying your workflow and enhancing your website management capabilities. Before starting this go through my previous DevOps 2.3 article on how to launch a WordPress on Linux.
STEPS:
Begin by duplicating a Vagrant file from your previous WordPress project and relocating it to a fresh directory. Then, open it using VSCode to proceed with your setup.
Second change the IP address of the VM so that it does not collide with other VM.
Next, through provisioning, we are going to enter all the commands through which we set up the website.
Copy the below provisioning code to the vagrant file.
config.vm.provision "shell", inline: <<-SHELL
sudo apt update
sudo apt install apache2 \
ghostscript \
libapache2-mod-php \
mysql-server \
php \
php-bcmath \
php-curl \
php-imagick \
php-intl \
php-json \
php-mbstring \
php-mysql \
php-xml \
php-zip -y
sudo mkdir -p /srv/www
sudo chown www-data: /srv/www
curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www
cat > /etc/apache2/sites-available/wordpress.conf <<EOF
<VirtualHost *:80>
DocumentRoot /srv/www/wordpress
<Directory /srv/www/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /srv/www/wordpress/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
EOF
sudo a2ensite wordpress
sudo a2enmod rewrite
sudo a2dissite 000-default
mysql -u root -e 'CREATE DATABASE wordpress;'
mysql -u root -e 'CREATE USER wordpress@localhost IDENTIFIED BY "admin123";'
mysql -u root -e 'GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON wordpress.* TO wordpress@localhost;'
mysql -u root -e 'FLUSH PRIVILEGES;'
sudo -u www-data cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/database_name_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/username_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/password_here/admin123/' /srv/www/wordpress/wp-config.php
systemctl restart mysql
systemctl restart apache2
SHELL
Now let's run the VagrantFile by doing vagrant up
and vagrant ssh
.
Now if you paste the IP address in the browser you will get the web page.
Conclusion:
In "DevOps 2.5: Automate WordPress Setup using Provisioning," you've gained valuable insights into automating WordPress deployment. By harnessing the power of provisioning, you can efficiently and consistently set up WordPress sites, saving time and reducing errors. This knowledge empowers you to take your DevOps skills to the next level, making website deployment a breeze. Happy automating! ๐๐ป๐