Saw this request on Reddit and thought it might be a neat challenge.
Disclaimer: This script will likely not result in a super secure installation of CentOS, Apache, MariaDB or WordPress. It will however get you a working deployment of WordPress on a blank CentOS 7 VM with the firewall and SELinux still enabled. I do not recommend using this in production with out performing additional hardening yourself or altering the script to perform it for you. Also it is generally bad practice to run random scripts from the internet so please review the script before executing it to make sure you are OK with everything it is doing.
I am going to assume you’ve built a VM in your preferred hypervisor (I’m using VMware Workstation) and you have the CentOS Minimal Installation ISO mounted to it’s CDROM so it will boot the CentOS installer. I am also going to assume you have DHCP and DNS working on your network so the VM will automatically get a IP and be able to access the internet.
I am not going to cover setting up a static IP, public/private DNS configuration, LetsEncrypt SSL, etc. All this script will do is get you a CentOS 7 VM with Apache, MariaDB, phpMyAdmin and WordPress on it.
I’ve built a VM with 2vCPUs, 2GB of RAM and a 20GB HD.
Installing CentOS into the VM
- Power on the VM
- Choose ‘Install CentOS 7’ and press <ENTER>
- Press <ENTER> to start the installation
- Click ‘Contiune’ on the language/keyboard selection screen
- Click ‘Network & Hostname’
- Change the hostname to whatever you’d like your VM to be called and click ‘Apply’
- Click the ‘Off’ button in the top right to turn on the network connection
- Verify you have an IP address and note it down so you can SSH in post installation, if not you have some fixing to do, if you do click ‘Done’
- Click ‘Date & Time’
- Pick your timezone
- Make sure ‘Network Time’ is set to ‘On’
- Click ‘Done’
- Click ‘Installation Destination’
- Select the VMs disk and click ‘Done’
- Click ‘Begin Installation’
- Click ‘Root password’, set a password and click ‘Done’
- Click ‘User creation’, fill out the boxes for your normal user account, checkmark ‘Make this user administrator’ and click ‘Done’
- Wait for the installation to complete
- Click ‘Reboot’ when it’s done
SSH into your server and run the install script
Note: If you didn’t write down the IP of your VM from the OS installation you can login with the root account or your non-root account and run “ip addr show” and you will see the IP of your VM under ‘ens##’ next to ‘inet’
- SSH into your VM using your non-root account you created during the installation
- Download the installation script by running the following:
1curl https://www.pickysysadmin.ca/static/installWordpressScript.sh > installWordpressScript.sh
- Verify the the file by running the following command. The output should say “OK”
1echo "27c25a27cbaddba4318a68f5d9d3b56de7b5493b installWordpressScript.sh" | sha1sum -c
- Inspect the script using vim or some other text editor to make sure you are OK with everything happening in the script. Running scripts randomly from the internet is usually a bad idea.
- Run the script
1sudo sh installWordpressScript.sh
- Enter your password when prompted and wait
- Near the end of the installation ‘mysql_secure_installation’ will be run which you will have to deal with interactively. There does not appear to be a way to have it run automatically
- When prompted for the root password just press <ENTER>
- When asked to set a root password hit <ENTER>
- Enter a root password of your choosing for MariaDB and note it down securely
- Hit <ENTER> for all of the other questions
- Once the script finishes it will output your WordPress database password, note it down somewhere secure
- You should now be able to access WordPress via http://<VMs IP>/ and phpMyAdmin via http://<VMs IP>/phpmyadmin
- Once you’ve finished the WordPress installation run the following command to reset the SELinux permissions we altered so the installer would work and reboot the VM in case one of the updates that was installed was a kernel update:
12sudo restorecon -v /var/www/htmlsudo shutdown -r now
Thank you to Nick for his SELinux tips: https://techblog.jeppson.org/2016/10/install-wordpress-centos-7/