Sometime ago, I wrote an automated script to install WordPress on a CentOS 5 install of Linux. Over the years, the repos and WordPress requirements changed as did CentOS upgrades through CentOS 6. The script was modified accordingly. The script had to be modified considerably for CentOS 7 which facilitates the need for a new article. Here is an automated install script for WordPress on a minimal install of CentOS7.
Basically, write the script as seen below, make it an executable with chmod +x install-wordpress-centos7.sh and run it. When done, go to your browser of choice and type in your IP address. Done. You’ll be up and running in a matter of minutes.
#!/bin/bash # install-wordpress-centos7.sh # # Description: This script will download, configure and install WordPress for CentOS/RHEL 7.x Linux. # cd /opt # Open firewall ports firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --reload # Install the database yum -y install mariadb-server httpd php php-mysql systemctl enable mariadb.service systemctl start mariadb.service # Add to the database echo 'CREATE DATABASE wordpress;' | mysql echo "GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY 'password';" | mysql echo "FLUSH PRIVILEGES;" | mysql # Download and install WordPress curl -O https://wordpress.org/latest.tar.gz tar -C /var/www/html/ --strip-components=1 -zxvf latest.tar.gz && rm -f latest.tar.gz cd /var/www/html mkdir wp-content/{uploads,cache} chown apache:apache wp-content/{uploads,cache} # Configure WordPress cp wp-config-sample.php wp-config.php sed -i 's@database_name_here@wordpress@' wp-config.php sed -i 's@username_here@wordpress@' wp-config.php sed -i 's@password_here@password@' wp-config.php curl https://api.wordpress.org/secret-key/1.1/salt/ >> wp-config.php # Modify the .htaccess echo "# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress" >> .htaccess chmod 666 /var/www/html/.htaccess # Configure and start Apache sed -i "/^<Directory \"\/var\/www\/html\">/,/^<\/Directory>/{s/AllowOverride None/AllowOverride All/g}" /etc/httpd/conf/httpd.conf systemctl enable httpd.service systemctl start httpd.service
Just a quick note. This is a “quick” and dirty approach to simply get WordPress up and running in a matter of minutes. Changing of the usernames, passwords, and tables prefixes would be wise in a production environment. Also hardening the database would be prudent.
Source(s)
- http://linuxconfig.org/apache-webserver-httpd-service-installation-on-redhat-7-linux
- https://www.atlantic.net/community/howto/install-lamp-fedora-22/
- https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-centos-7