RSS

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
mysql_secure_installation

# create new DB schema and user
mysql -u root -p
mysql> CREATE DATABASE wp;
mysql> CREATE USER `wpuser`@`localhost` identified by 'password';
mysql> GRANT ALL ON wp.* TO `wpuser`@`localhost`;
mysql> FLUSH PRIVILEGES;
mysql> exit

# get wordpress
curl https://wordpress.org/latest.tar.gz --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(/.*)?"
#verify:
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
#verify: 
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 https://api.wordpress.org/secret-key/1.1/salt/ 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
 ServerName ixixi.duckdns.org
 ServerAlias www.ixixi.duckdns.org
  <Directory "/var/www/wordpress">
    Options Indexes FollowSymLinks
    AllowOverride all
    Require all granted
  </Directory>
 ErrorLog /var/log/httpd/wordpress_error.log
 CustomLog /var/log/httpd/wordpress_access.log common
</VirtualHost>
#reload httpd so it shows wordpress:
service httpd restart

#open homepage:
curl http://ixixi.duckdns.org
# test the URL in a browser too

# now test and use wordpress!