Script to install WordPress and phpMyAdmin on CentOS 7

Update 2019-08-22 – I recieved a request to update this script so that PHP 7.2 is used instead of the stock PHP 5.4 that comes with CentOS 7. I also swapped out MariaDB 10.2 with the latest 10.4. The instructions are nearly identical as before but there is now one extra step with the v1.1 script. Both versions are still available below. Really I should probably take the time to learn Ansible which would be a much more graceful way of doing this. Maybe when CentOS 8 comes out.


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

  1. Power on the VM
  2. Choose ‘Install CentOS 7’ and press <ENTER>
  3. Press <ENTER> to start the installation
  4. Click ‘Contiune’ on the language/keyboard selection screen
  5. Click ‘Network & Hostname’
  6. Change the hostname to whatever you’d like your VM to be called and click ‘Apply’
  7. Click the ‘Off’ button in the top right to turn on the network connection
  8. 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’
  9. Click ‘Date & Time’
  10. Pick your timezone
  11. Make sure ‘Network Time’ is set to ‘On’
  12. Click ‘Done’
  13. Click ‘Installation Destination’
  14. Select the VMs disk and click ‘Done’
  15. Click ‘Begin Installation’
  16. Click ‘Root password’, set a password and click ‘Done’
  17. Click ‘User creation’, fill out the boxes for your normal user account, check mark ‘Make this user administrator’ and click ‘Done’
  18. Wait for the installation to complete
  19. 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’

  1. SSH into your VM using your non-root account you created during the installation
  2. Download one of the two installation scripts by running the following:
    # v1.0 - Original version, installs the default PHP 5.4 that comes with CentOS and MariaDB 10.2
    curl >
    # v1.1 - New as of 2019-08-22, installs PHP 7.2 and MariaDB 10.4
    curl >
  3. Verify the the installation script you downloaded by running the following command. The output should say “OK”
    # v1.0
    echo "27c25a27cbaddba4318a68f5d9d3b56de7b5493b" | sha1sum -c
    # v1.1
    echo "792e15a137ffbde0fa008d788bfbca8f21cfe753" | sha1sum -c
  4. 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.
  5. Run the script
    sudo sh
  6. Enter your password when prompted and wait
  7. 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
  8. When prompted for the root password just press <ENTER>
  9. (IF USING v1.1) When prompted to “Switch to unix_socket authentication” enter “n”
  10. When asked to set a root password hit <ENTER>
  11. Enter a root password of your choosing for MariaDB and note it down securely
  12. Hit <ENTER> for all of the other questions (this will automatically choose “Y” for you)
  13. Once the script finishes it will output your WordPress database password, note it down somewhere secure
  14. You should now be able to access WordPress via http://<VMs IP>/ and phpMyAdmin via http://<VMs IP>/phpmyadmin
  15. 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:
    sudo restorecon -v /var/www/html
    sudo shutdown -r now



Thank you to Nick for his SELinux tips:

Thank you to Vivek for his PHP 7.2 on CentOS 7 guide:

Replace MySQL with MiriaDB on CentOS 6

Last modified: [last-modified]

I’m running CentOS 6.3 64-bit and have been for a little while. I decided I wanted to swap out MySQL 5.1.x with MiriaDB 5.3.x.

Why? Because I can. Plus I’ve read a bit and it sounds like MiriaDB is better optimized than MySQL. Also Oracle is evil.

These instructions are based off my history file. I didn’t think to write this down as I did it. That means there may be a mistake in the following process but with some Googling you should be able to fix any problems you come across.

One thing to know before proceeding  If you’re using PHP 5.3.3 that comes with CentOS 6 you will get a header miss-match error when PHP uses the ‘php-mysql’ package to access MySQL. I believe you can safely ignore this. I did for a few hours and nothing seemed broken. I’ll include steps on fixing this problem in another post as it requires completely replacing PHP in CentOS with PHP from another repository. If you’ve compiled your own PHP then you’ll just want to re-compile it with the MySQL Native Driver (mysqlnd).

  1. Stop your webserver and any other applications that may be trying to access your MySQL Database
  2. Take a full backup of your MySQL database just in case
    mysqldump --add-drop-database --add-drop-table --allow-keywords --all-databases --complete-insert --quick --user=root --password=<ROOT PASSWORD> > fullDataset.sql
    service stop mysqld
    cp -Ra <Path to MySQL DB> <Path to MySQL DB>.bak
  3. Next find out what MySQL RPMs you have installed and remove them. This will automatically create a backup of your existing ‘/etc/my.cnf’ file.
    rpm -qa |grep mysql
    # --- Command output start ---
    # --- Command output end ---
    rpm -e --nodeps mysql-5.1.67-1.el6_3.x86_64 mysql-server-5.1.67-1.el6_3.x86_64 mysql-devel-5.1.67-1.el6_3.x86_64 mysql-libs-5.1.67-1.el6_3.x86_64
  4. Alright now you’ve got no MySQL on your system. Lets drop MiriaDB in.
    vim /etc/yum.repos.d/MariaDB.repo
    #--- Add the content below to the file ---
      name = MariaDB
      baseurl =
    #--- Save and close the file ---
    yum install MariaDB-client.x86_64 MariaDB-devel.x86_64 MariaDB-server.x86_64 MariaDB-shared.x86_64
  5. You should now have MariaDB 5.3.x installed. Next we want to put the old configuration file back.
    cp /etc/my.cnf.rpmsave /etc/my.cnf
  6. Fire up MiriaDB, verify the version and upgrade the databases
    /etc/init.d/mysql start
    mysql --version
    # --- Command output start ---
    mysql  Ver 15.1 Distrib 5.3.10-MariaDB, for unknown-linux-gnu (x86_64) using readline 5.1
    # --- Command output end ---
    # Upgrade the database
    mysql_upgrade -u root -p
  7. Configure MiriaDB to start on boot
    chkconfig --add mysql
    chkconfig --levels 35 mysql on

That’s it! You should now be running the latest stable version of MariaDB 5.3.x which you will be able to keep up to date with the ‘yum’ command.