Installing Wordpress on CentOS 7.X

Installing LAMP

Once your server is built, make sure the server is up to date.

$ yum update -y

Install Apache (httpd).

yum install httpd

Now start Apache

systemctl start httpd.service

Check to make sure Apache is working by going to http://your-ip-address.

Make sure Apache will start on reboot

systemctl enable httpd.service

You can find your server's ip address using the following command:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

Install MySQL/MariaDB - yum install mariadb-server mariadb

Start MariaDB - systemctl start mariadb.service

Run a security script that will remove some dangerous defaults and lock down access to our database system - mysql_secure_installation

Configure MariaDB to automatically start on reboot - systemctl enable mariadb.service

Install PHP - yum install php php-mysql

Restart Apache for it to work with PHP - systemctl restart httpd.service

Test PHP processing on the web server by using phpinfo() - vi /var/www/html/info.php

Run the following commands to allow HTTP and HTTPS traffic:

$ firewall-cmd --permanent --zone=public --add-service=http
$ firewall-cmd --permanent --zone=public --add-service=https
$ firewall-cmd --reload

Now test if the web server is correctly displaying content generated by the PHP script.

The address is:

http://your_server_ip/info.php

Setting up MySQL

The first thing we need to do is to get into MySQL:

$ mysql -u root -p

Now we need to create the database and user that Wordpress is going to use:

$ CREATE DATABASE wordpress;

You can list the databases to confirm creation:

$ SHOW DATABASES;

Now create the user

> CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
> GRANT ALL PRIVILEGES ON wordpress.* TO 'user'@'localhost' WITH GRANT OPTION;

Installing Wordpress Files

Now that we have our LAMP sever setup, we need to install Wordpress. From within the DocumentRoot (/var/www/html), run the following command to pull down the tarball from Wordpress:

wget https://wordpress.org/latest.tar.gz

Run the following command to untar the file:

tar -zxvf latest.tar.gz

Now move all of the Wordpress files from /wordpress into DocumentRoot:

$ mv wordpress/* .

Now we need to copy wp-config-sample.php to wp-config.sample

$ cp wp-config-sample.php wp-config.php

Edit the file with all of the pertinent information

$ vi wp-config.php

Make sure to add this line to the bottom of wp-config.php. This will insure that you're able to add themes and update your install of Wordpress without having to use FTP.

define('FS_METHOD', 'direct');

Setting Ownership and Permissions

Wordpress is very picky about permissions and ownership, especially when it comes to installing themes and updates.

Add the following line to the bottom of wp-config.php:

define('FS_METHOD', 'direct');

Now, allow Apache to own the wordpress files:

$ chown -R 48 /var/www/wordpress_directory