Introduction
WordPress is a free and open-source content management system written in PHP and paired with a MySQL or MariaDB database. WordPress is used by more than 40.5% of the top 10 million websites as of March 2021, WordPress is one of the most popular blog-publishing and content management system solutions in use.
Prerequisites:
- You have already deploy a Cybree Instance with CentOS 7 image.
- You have already completed the "How to install LAMP on Centos 7 tutorial”, and installed LAMP (Linux, Apache, MySQL, PHP) on your server
- You have your root mysql password so you can log into mysql as root.
Step 1: Create a Database
- After you login to your Cybree instance, run the following command to log in as root user
mysql -u root -p
-
You will be prompted for the password you set earlier as root when you installed MySQL. If you do not have your root password, you will have to reset it.
-
Once logged in, we can create a database with the following command. You can call it whatever you would like, but for this article, we are calling it WordPress. Please note that every mysql command will require a ; (colon) at the end of every statement
CREATE DATABASE wordpress;
- Once our database is created, you need to create a user for that database. Once again I am using a very simple username, and password so feel free to make yours more secure. Do remember your username and password as we will need it later in this article. Type the following command.
CREATE USER adminuser@localhost IDENTIFIED BY 'password';
- Now we need to give that user permissions to access the database. We can add those permissions with the following command. If you use your own database name, user, and password, you should also replace it in the command. Also note that the password is contained in single quotes followed by a colon;
GRANT ALL PRIVILEGES ON wordpress.* TO adminuser@localhost IDENTIFIED BY 'password';
- Now we want to flush MySQL so that it is made aware of those changes.
FLUSH PRIVILEGES;
- and finally, exit MySQL
Exit
Step 2) Install WordPress
- Download the latest wordpress file
cd ~
wget http://wordpress.org/latest.tar.gz
- Now, let’s unzip that tar file
tar -xzvf latest.tar.gz
- That should create a file named WordPress in our home directory. Next, we want to move that file and its contents to our public_html folder, so it can serve up the content for our website. We want to keep the same file permission, so we use the following rsync command.
sudo rsync -avP ~/wordpress/ /var/www/html/
- For WordPress to be able to upload files, we need to create an uploads directory. Go ahead and use the following:
mkdir /var/www/html/wp-content/uploads
- Lastly, update the Apache permissions for new WordPress files
sudo chown -R apache:apache /var/www/html/*
Step 4) Configuring WordPress
- Next, we have to update the wp-config.php file in WordPress for it to connect to the database successfully. So let’s go to the html folder where your WordPress install is located.
cd /var/www/html
- Create a wp-config.php file by copying the sample file WordPress has provided.
cp wp-config-sample.php wp-config.php
- Now, we need to edit the new wp-config.php file with the correct database information we created in Step 1. I used vim to make that change, but you can use any editor you are comfortable with.
sudo nano wp-config.php
- Next, we need to add info into the following fields of the database, user, and password we created in Step 1.
Old Settings:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
New Settings:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );
/** MySQL database username */
define( 'DB_USER', 'adminuser' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password' );
- Once you have made those changes, go ahead and save the file using CTRL+X (to exit) and Y and Enter (to save changes, and close the file).
Step 5) Setup through wp-admin and verification
- Now, let’s verify that your WordPress install is working. You should see something like the following on your server page. Replace server_domain_name_or_IP with your server name or IP. http://[server_domain_name_or_IP]/wp-admin
- If this is what you see then congrats!!! You have successfully installed WordPress on your Centos server. You can continue with the rest of the Wordpress setup to configure your wordpress blog.