Needs

I just installed a WordPress on CentOS 7. So I thought I will write down all steps just in case I or someone “out there” will need that in the future.
So, let’s make it work.

Mysql database

  1. Most probably you want to use mariadb, which is a fork of well known Mysql database after it was acquired by Oracle. Simply install it with yum:
    yum install mysql
    

    I wanted to check percona-server, so in my case I had to add new repository and then install mysql:

    yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
    yum install Percona-Server-server-57
    

    Other steps should be identical on any database.

  2. You should set root password:

    mysql> ALTER USER root@localhost IDENTIFIED BY 'new_password'; 
    
  3. Make sure that your database will listen only on local address. To do so put a file in /etc/my.cnf.d/bind-address.cnf:
    [mysqld]
    bind-address = localhost
    
  4. Restart and enable mysql to start with system:
    systemctl restart mysqld.service
    systemctl enable mysqld.service
    
  5. Create a database for WordPress. It is a good idea to have database just for that. I prefer to name it after main url:
    mysql> create database blog_example_com;
    

    Don’t use dots in database name. Nor in table names or columns. Mysql does not like it.

  6. Create a user for WordPress:

    GRANT ALL PRIVILEGES ON blog_example_com.* to blog_example_com@localhost identified by 'secret_leet_password';
    

Apache server

  1. Install apache2 and required packages:
    yum install httpd php php-mysql php-xml
    
  2. You will need a config for your site. Note, that with ServerName directive apache will direct to this site only if domain matches. That mean that you will need blog.example.com domain properly configured.
    <VirtualHost *:80>
            ServerAdmin YOUREMAIL@ADDRESS
            ServerName blog.example.com
            ServerAlias www.blog.example.com
    
            DocumentRoot "/var/www/html/blog.example.com"
    
            <Directory "/var/www/html/blog.example.com">
                    Options FollowSymLinks MultiViews Includes ExecCGI
                    AllowOverride none
                    Order allow,deny
                    allow from all
                    Require all granted
                    RewriteEngine On
                    RewriteBase /
                    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
                    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
                    RewriteRule ^index\.php$ - [L]
                    RewriteCond %{REQUEST_FILENAME} !-f
                    RewriteCond %{REQUEST_FILENAME} !-d
                    RewriteRule . /index.php [L]
            </Directory>
    
            ErrorLog /var/log/httpd/blog.example.com-error.log
            LogLevel warn
            CustomLog /var/log/httpd/blog.example.com-access.log combined
    </VirtualHost>
    
  3. Restart and enable apache:
    systemctl restart httpd.service
    systemctl enable httpd.service
    

WordPress installation

  1. Download recent version of WordPress from official site and put it into your blog http directory (/var/www/html/blog_directory).
  2. Navigate to your /var/www/html/blog_directory and extract archive file:
    cd /var/www/html/blog_directory
    tar -xzvf /var/www/html/blog_directory/wordpress-version.tar.gz
    rm -fv /var/www/html/blog_directory/wordpress-version.tar.gz
    
  3. Change ownership of all files:
    chown apache.apache -R /var/www/html/blog_directory
    
  4. If you are using selinux, change context of your directory:
    semanage fcontext -a -t httpd_sys_rw_content_t /var/www/html/blog.example.com
    restorecon -vR httpd_sys_rw_content_t /var/www/html/blog.example.com
    
  5. If you are using selinux and you want to be able to send mails from your blog (and apache in general), then allow it:
    setsebool -P httpd_can_sendmail 1
    
  6. Navigate to your blog in web browser to continue with installation. Proceed with instructions provided on screen. Information you will need:
    • Database name: blog_example_com
    • Database user: blog_example_com
    • Database user password: You have created it 🙂
    • Database host: localhost
  7. Make sure that your config file is not widely accessible:
    chmod 600 /var/www/html/blog.example.com/wp-config.php
    
  8. You can now use your blog. Happily ever after.

Leave a Reply