How To Install WordPress with nginx on Centos 6

So far I have written how to install LEMP server (nginx, mysql, php-fpm) on centos. If you are planning to use WordPress with your LEMP server (nginx, mysql, php-fpm) stack, I will show you How To Install WordPress with nginx on Centos in this article.

Follow up previous article How to install LEMP web server with Nginx, PHP-FPM 5.5, MySQL 5.5 on Centos Linux. You should have a working LEMP server (nginx, mysql, php-fpm). The default html/php files for your website should be stored in /usr/share/nginx/html directory.

First of, WordPress requires PHP version 5.2.4 or greater and MySQL version 5.0 or greater which we have already installed on our Centos Linux server. In order install WordPress we are going to need a MySQL database with MySQL username and password. Even though we have configured MySQL root account and it’s password, I highly not recommend you to use MySQL root account to run any web application for security purpose. You should always create separate MySQL database and username for each web application you run.

To create a MySQL database and set privileges to a user

Use your MySQL root username with the password you have set for it to login to MySQL server

# mysql -u root -p


Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 13
Server version: 5.5.37 MySQL Community Server (GPL) by Remi
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

After sucessful login to MySQL server, you should see mysql> as you are in mysql shell instead of your Linux distro shell.

To create a MySQL database
Let say we are going to create a database named “wordpressdb” to run WordPress, you can choose whatever name you like, it does not have to be wordpressdb for WordPress.

mysql> create database wordpressdb;


Query OK, 1 row affected (0.00 sec)

To create MySQL username and password
As I said, we should not use root username and it’s password, it’s always a good idea to use a separate MySQL username and password for each web application. We are now going to create wpusername and make it to connect to the MySQL server from localhost. (replace wpusername to what you like)

mysql> grant usage on *.* to wpusername@localhost identified by 'wordpressusernamepassword';

Replace “wordpressusernamepassword” part with a new password for wpusername.

To grant all privileges on wordpressdb database to wpusername

mysql> grant all privileges on wordpressdb.* to wpusername@localhost;

You are pretty much done with mysql database and username part, now you can exit mysql shell but using exit command

mysql> exit

You should test if you can connect to MySQL server with the newly created wpusername and it’s password

# mysql -u wpusername -p'wordpressusernamepassword' wordpressdb
Download and Install WordPress

I’m going to download WordPress to /tmp/ directory. You can get the latest WordPress from this command

# cd /tmp
# wget
To decompress latest.tar.gz file
# tar -xzvf latest.tar.gz
The default nginx document_root is /usr/share/nginx/html If you want to run WordPress to run with your main domain, simply move all the files under wordpress directory we just decompressed from latest.tar.gz file to /usr/share/nginx/html directory
# cd /tmp/wordpress
# mv * /usr/share/nginx/html

Now open your web browser (Firefox/Google Chrome) and go to You should see WordPress comes up with “There doesn’t seem to be a wp-config.php file. I need this before we can get started.” error since we have not configured wp-config.php file for WordPress yet.

To create wp-config.php file, click on”Create a Configuration File” button. The next screen will show WordPress requires your database information. Click on “Let’s go!” to go to the next page where we can input our database information.

Fill out Database Name, User Name, Password which we created before, leave Database Host as localhost. After you fill everything out, click “Submit”.

After you click on “Submit” from the last page, WordPress setup script will give you wp-config.php file, we are going to copy the content of wp-config.php from WordPress setup script manually and create a new wp-config.php in /usr/share/nginx/html directory.

Sample wp-config.php file, now go back to our Centos Linux shell and create wp-config.php file with the content from WordPress setup script

# nano /usr/share/nginx/html/wp-config.php

with he wp-config.php content from your WordPress setup script, don’t copy mine 🙂

* The base configurations of the WordPress.
* This file has the following configurations: MySQL settings, Table Prefix,
* Secret Keys, WordPress Language, and ABSPATH. You can find more information
* by visiting {@link Editing
* wp-config.php} Codex page. You can get the MySQL settings from your web host.
* This file is used by the wp-config.php creation script during the
* installation. You don't have to use the wb site, you can just copy this file

* to "wp-config.php" and fill in the values.
* @package WordPress
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpressdb');
/** MySQL database username */
define('DB_USER', 'wpusername');
/** MySQL database password */
define('DB_PASSWORD', 'wordpressusernamepassword');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
* Authentication Unique Keys and Salts.
* Change these to different unique phrases!
* You can generate these using the {@link secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
* @since 2.6.0
define('AUTH_KEY',         'ntPO=fzFTWdzFnc#?yP-773z-{[6;6mkc1wu3U$;GqVCCEZ5cMi%.[}~&=t>4OQY');
define('SECURE_AUTH_KEY',  '.ek;fJppa)8 $ <W0.*tqp|1CH&zAk7D(1X)/Oz%A:c&}4|N.wn}u,RA#%~%%iqn');
define('LOGGED_IN_KEY',    'y=/f1JaO~}$<`<-4R O;@;86[DvcI?T(+;,eO<.0.@ZMo{]gH.Q,r-fZ|:E+[I,R');
define('NONCE_KEY',        'M5 HaC&p?Q8$k ](d<2[ckgKHnF^++e!rqd1)lmY]:6~;(toso-W0mP2]WFFB]Es');
define('AUTH_SALT',        '$q8Y{]1h .>i!&[.c~-+T9dc/v-H7h^OVHCY@LQ*IKEH*`H1H#I+/gWqJ|J[s@X[');
define('SECURE_AUTH_SALT', 'hL+2g-b*Nc +@4sJ,VYs3:U&S:z}xPG{G8eH~+V!;odc$zKeWuQrB-eY]C@c)iZY');
define('LOGGED_IN_SALT',   'mD-6WP+=z39n7>yMU_&Q7z[Hdot1w$KFE}9Y]pN8P.2f.tXL4g~>[#f5!5:5)z%E');
define('NONCE_SALT',       'O0mm!|-|Abe&_ >q1(+,Zh%3CNv/ hJH){0d{kDt-T8glK8 BR$q^&+:[so4FudG');
* WordPress Database Table prefix.
* You can have multiple installations in one database if you give each a unique
* prefix. Only numbers, letters, and underscores please!
$table_prefix  = 'wp_';
* WordPress Localized Language, defaults to English.
* Change this to localize WordPress. A corresponding MO file for the chosen
* language must be installed to wp-content/languages. For example, install
* to wp-content/languages and set WPLANG to 'de_DE' to enable German
* language support.
define('WPLANG', '');
* For developers: WordPress debugging mode.
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
define('WP_DEBUG', false);
/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

Save wp-config.php file, then click “Run the install” on your WordPress setup script with your web browser. You will be asked to to setup your WordPress Site Title, WordPress Username and Password, and your email address. Click “Install WordPress” after you filled out all those information.

If nothing went wrong, you should see “Success!” page from WordPress installation script. Click on “Log In” to login to your WordPress Admin Panel.

Well done, you have a working WordPress blog runs with nginx,php-fpm 5.5, and mysql 5.5 on Centos. Happy blogging 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *