Tutorials

How to Install and Configure WordPress on CentOS 7

Table of Contents

Introduction

WordPress is a free and open source blogging platform or content management system based on PHP and MySQL. Currently WordPress is the most popular CMS all over the world, and has 20000 plus plugins to extend its functionality.You can easily create a simple website, blog or complex portals and enterprise websites using WordPress.

WordPress provides lots of features. Some of them are listed below:

  • WordPress is available in more than 70 languages. So you can build a website in a language as your choice.
  • You can easily manage your content, schedule, look and publication using WordPress, and also secure your posts and content with a password.
  • WordPress comes with thousands of themes for you to create a beautiful website. You can also upload your own theme with the click of a button.
  • With the importers feature you can easily import your blog from another website to WordPress.
  • WordPress provides search engine optimization out of the box, and also provides many SEO plugins.

In this tutorial, we will discuss how to install and configure WordPress on a CentOS 7 server.

Requirements

  • A server running CentOS 7.
  • A non-root user with sudo privilege setup on your server.

Getting Started

Update your system with the latest package versions by running the following command:

sudo yum update -y

Once your system is up-to-date, you can proceed to the next step.

Installing LAMP

Before installing WordPress itself, you will need to install the LAMP stack and other required packages on your server.

You can install all the necessary packages with the following command:

sudo yum install httpd mariadb mariadb-server php php-common php-mysql php-gd php-xml php-mbstring php-mcrypt php-xmlrpc unzip wget -y

Once installation is complete, start the Apache and MariaDB services and enable them to start at boot with the following commands:

sudo systemctl start httpd
sudo systemctl start mariadb
sudo systemctl enable httpd
sudo systemctl enable mariadb

Configuring MariaDB for WordPress

By default MariaDB is not secured, so you will need to secure it first. You can do this by running mysql_secure_installation script:

sudo mysql_secure_installation

Answer all the questions as shown below:

Set root password? [Y/n] n
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Once you have finished, login to MariaDB console with the following command:

mysql -u root -p

Enter your MariaDB root password and hit Enter. After login, create a database for WordPress:

MariaDB [(none)]>CREATE DATABASE wordpress;
MariaDB [(none)]>GRANT ALL PRIVILEGES on wordpress.* to 'user'@'localhost' identified by 'password';
MariaDB [(none)]>FLUSH PRIVILEGES;
MariaDB [(none)]>exit

Installing and Configuring WordPress

You can download the latest version of the WordPress source from the official website. You can get the latest version of WordPress by running the following command:

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

Once download is finished, extract the downloaded file with the following command:

tar -xzvf latest.tar.gz

Next, move the extracted files to the Apache web root directory:

sudo cp -avr wordpress/* /var/www/html/

Next, create a directory for WordPress to store uploaded files:

sudo mkdir /var/www/html/wp-content/uploads

Next, assign proper ownership and permissions to your WordPress files and folders:

sudo chown -R apache:apache /var/www/html/
sudo chmod -R 755 /var/www/html/

Next, you will need to make some changes in the WordPress main configuration file, so it can be connected with the database and user.

First, rename and edit the WordPress main configuration file:

cd /var/www/html/
sudo mv wp-config-sample.php wp-config.php
sudo nano wp-config.php

Change the DB_NAME, DB_USER, and DB_PASSWORD variables as shown below:

define('DB_NAME', 'wordpress');
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');

Save and close the file when you are finished.

Accessing WordPress Web Installation Wizard

Before starting, you will need to allow access to the Apache ports using firewalld.

You can do this by running the following command:

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

Next, open your web browser and type the URL http://your-server-ip. You should see the following page:

WordPress language selection

Select language as per your need and click on Continue button, you should see the following page:

WordPress site info page

Fill out all the required site information and click on Install WordPress button. You should see the WordPress default dashboard as below:

WordPress dashboard page

Once installation is completed, you can login WordPress by typing the URL http://your-server-ip/wp-login.php? on your web browser. You should see the WordPress login page as below:

WordPress login page

Next, provide username and the password which you have created earlier and click on Log In button, you should see the following page:

WordPress dashboard

Summary

Congratulations! You have successfully installed WordPress on CentOS 7. I hope you have now enough knowledge to host your own WordPress blog easily. Feel free to comment below if you have any questions.

 
  • Next, move the extracted files to the Apache web root directory: sudo cp -avr wordpress/* /var/www/html/

    After this step, we had to do a:

    restorecon -r /var/www/html
    

    Prior to this, all the files that were copied into the /var/www/html directory would yield 403 errors when we tried pulling them up in our web browser.

    Solution Source

    Aside from that, excellent guide, thank you!

  • I successfully installed all component for my own home web server. Centos7/Apache/phpmyadmin/mariadb/Wordpress. When I type localhost in browser, it shows Testing 123 which means apache is running. I created wordpress website. When I type in my browser localhost/wordpress, I see my wordpress website. when I type my public ip address, I see testing 123, not my wordpress website. I want to see my website from outside world. I guess I need to do something more. For now I want to type ip address of my web server instead of domain name. please help with this issue. Thanks a lot

  • First, edit the following file:

    sudo nano /etc/httpd/conf.d/welcome.conf
    

    Remove the following lines:

    <LocationMatch "^/+$">
       Options -Indexes
       ErrorDocument 403 /error/noindex.html
    </LocationMatch>
    

    Then, restart apache web server.

    Or

    Delete /etc/httpd/conf.d/welcome.conf file:

    sudo rm -rf  /etc/httpd/conf.d/welcome.conf
    

    Then, restart apache web server.

  • Thank you so much for the expert answer.

  • and new plugin and theme error

    Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the WordPress Plugin Directory or upload a plugin in .zip format by clicking the button at the top of this page.

    Plugins list An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums. Try again http://s20.pixxxels.org/dn042stwt/Capture.4674567_PNG.png

  • I followed these steps and do not get the select language page but get the apache confirmation page. What did I miss?

  • I saw previous person had similar issue and I followed step to delete the welcome.conf file. Now I get this Forbidden You don't have permission to access / on this server. I am using MySQL itself with 'user' as the user.

  • installed wordpress on centos 7 when i try to add new plugins and themes i am getting this error message

    Error : Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the WordPress Plugin Directory or upload a plugin in .zip format by clicking the button at the top of this page.

    Plugins list An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums. Try again

    image kink >> http://s20.pixxxels.org/dn042stwt/Capture.4674567_PNG.png

  • I did every commend accordingly but when i browse my ip it say Error establishing a database connection. What I missed? What should I do now?

  • @btshamol You probably forgot to create virtual host (vhost) configuration files and add DNS record (to bind domain name to ip address). Try google how to create vhost configuration files for domain name on apache centos7 and how to add DNS A record. But if you dont have domain name, you only need to configure Vhost (google how to create vhost for ip apache centos 7), no need to add DNS record.

  • hi everyone, I follow all the step but when I type my server ip I only see the apache page and not wordpress page to configure it. And if i put "/worpress" after my server ip it says "not found The requested URL /wordpress was not found on this server." any idea to help me ?

  • I saw some people with same error than I, but yet didn't find a solution for it. After installed (great tutorial), looks like wordpress doesn't have permission to delete or create files or folders, but using the same user created for ftp in filezilla for example, I have permission to delete or create file and folders. So I still don't understand how to fix it. This wordpress installation is useless with I can't install plugins, themes or anything else.

    Anybody found a solution for it?

Log In, Add a Comment