Press "Enter" to skip to content

How to install WordPress on Apache-based CentOS Server using Linux Command

Do you want to install latest version of WordPress on Apache-based CentOS Server using Linux Command?

What is WordPress?

WordPress is a free and open-source content management system based on PHP and MySQL.

Here’s are the easy step-by-step how to install latest WordPress on Apache-based CentOS Server using Linux Command:

Step 1 – First thing first, you have to create new MySQL database and user then grant all privileges for that user to the database. I’ve posted some basic and most common MySQL commands but in this tutorial I’ll repeat some of those commands so you can simply follow the steps straight forward.

Login to main MySQL screen at first. In this case I use root:

mysql -u root -p

Type in the password.

login mysql

Step 2 – Once you are in MySQL screen, here you can create new database for your blog. Use this command:

CREATE DATABASE databasename;

**change databasename with your own database name. You better not use space in the name. In this example I use “myblog”:

create database

If you wish to use space you can use underscore e.g: wp_456.

Step 3 – So you have created new database. Next, you have to create new MySQL username and grant full access to that new database. This is considered safer than using your root login. Use this command:

GRANT ALL ON databasename.* TO [email protected] IDENTIFIED BY 'password';

**change databasename, sqluser and password with your own. For example:

GRANT ALL ON myblog.* TO [email protected] IDENTIFIED BY 'pass1234';

In that example I create “sawiyatidb” as my user for database named “myblog” while pass1234 is the password for user sawiyatidb.

create new mysql user

That’s it. You must remember: database name, database username and its password. Once done, exit MySQL screen by typing “\q“.

Step 4 – Now edit the “wp-config-sample.php” using either vi or Nano. Assuming you are already in the root directory of your site, you can issue this command:

1
nano wp-config-sample.php

Or if you are still in very root directory of your server, you can use this command:

nano /var/www/domain.com.com/public_html/wp-config-sample.php

Then edit following lines:

edit wp-config

Please replace:

  • database_name_here with your newly created database (step 2 above)
  • username_here with your newly created MySQL user (step 3 above)
  • password_here with the password of that user.
  • You can leave “localhost” as it is in MySQL hostname section, unless you are using remote database.

It looks like this in my server:

wp config playground

OPTIONAL BUT RECOMMENDED: You can also define following lines:

salt key

Visit https://api.wordpress.org/secret-key/1.1/salt/ to generate each value. Here it will look like:

salt key

Once done, hit Control+O to save and Control+X to exit nano editor.

Step 5 – Rename that sample file then change its permissions:

Command to rename:

1
mv wp-config-sample.php wp-config.php

Command to change its permissions to 644:

1
chmod 644 wp-config.php

wp-config sample

Step 6 – Launch WordPress installation wizard in your browser. In this case I use Firefox. Type in your domain name then hit Enter. Now you’ll see the first page of its Installation Wizard which looks like following:

wordpress install wizard

Next, scroll down the page a little bit and you’ll see several fields under “Information Needed” section you have to fill in:

wordpress installation detail

Once done, simply hit the “Install WordPress” button in the bottom part.

install wordpress

That’s it. Now you can simply login to your newly installed blog at:

http://domain.com/wp-admin/

Optional but you may need it: Also create .htaccess file:

1
nano .htaccess

Once Nano editor appears, you can simply enter following lines there:

1
2
3
4
5
6
7
8
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Now hit Control+O to save then Control+X to exit. Entering those lines in your .htaccess file allows you to change your blog’s permalink to domain.com/year/month/post-title.

Next, change its permissions to 777:

1
chmod 777 .htaccess

You can then change it to another permalink structure via your Admin Dashboard. Do not forget to change its permissions back to 644 once done edition.

Congratulation, you are now installed your newly WordPress blog. Once login you can download your favorite SEO plugins freely. Do not hesitate to drop a comment below.