Installing Wordpress on Centos 8

Centos can be tricky, especially considering SELinux

💻 In this video, I install Wordpress Lamp stack (Linux, Apache, MySQL, and PHP) on a CentOS Linux virtual machine. The trick to making Wordpress work on CentOS is to overcome the blocks that are in place with SELinux.

#install Wordpress on Centos 8

# install php and mariadb
dnf install php-mysqlnd php-fpm mariadb-server httpd tar curl php-json

#install vim
dnf install vim

# link vim to vi to bypass vi
ln -s /usr/bin/vim /usr/local/bin/vi

# start mariadb and apache2
systemctl start mariadb
systemctl start httpd

# enable mariadb and apache2
systemctl enable mariadb
systemctl enable httpd

#secure mariadb
# create new DB schema and user
mysql -u root -p
mysql> CREATE USER `wpuser`@`localhost` identified by 'password';
mysql> GRANT ALL ON wp.* TO `wpuser`@`localhost`;
mysql> exit
# get WordPress
curl --output /var/www/wordpress.tar.gz
cd /var/www/
tar xf wordpress.tar.gz

# how many files are in the wordpress directory?
find /var/www/wordpress -type f | wc -l

# change ownership of all apache files:
chown -Rf apache:apache /var/www

# SELinux settings
# 1) allow apache httpd process to read and write to files in /var/www/wordpress
# if you don't do this, no one will be able to add a plugin, use a caching plugin, upload image files, etc
semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/wordpress(/.*)?"
semanage fcontext -l | grep httpd_sys_rw_content_t| grep "\/var\/www\/wordpress"

# 2) allow apache httpd process to connect to outside servers. Necessary if you want to download plugins:
setsebool -P httpd_can_network_connect on
getsebool -a | grep httpd_can_network_connect

# Create and edit the wordpress config file:
# If you create the wp-config.php file in this way, get 
# salted values from and replace 
# the constants from 'AUTH_KEY' to 'NONCE_SALT' and all between.
cd /var/www/wordpress
cp wp-config-sample.php wp-config.php
vi wp-config.php

vi /etc/httpd/conf.d/wordpress.conf
<VirtualHost *:80>
 ServerAdmin root@localhost
 DocumentRoot /var/www/wordpress
  <Directory "/var/www/wordpress">
    Options Indexes FollowSymLinks
    AllowOverride all
    Require all granted
 ErrorLog /var/log/httpd/wordpress_error.log
 CustomLog /var/log/httpd/wordpress_access.log common
#reload httpd so it shows wordpress:
service httpd restart

#open homepage:
# test the URL in a browser too

# now test and use wordpress!