How to install WordPress with nginx on Debian Wheezy

Install WordPress

WordPress is the most popular Content Management System (CMS) on the planet. Over 20% of websites, is powered by WordPress. It is free and open-source. WordPress is built with PHP as a server-side language and MySql as a database.

Prerequisites for WordPress Installation

To get started with installing WordPress you’ll need to make sure that your server is ready for it.
You’ll need a Debian based server with root privileges and make sure you’ve Nginx, PHP and MySql installed. If you don’t have these things installed, learn how to install nginx, PHP & MySql.

Download WordPress:

To download WordPress write the following command on your terminal:


Unzip the downloaded file with the following command:

tar -xzvf latest.tar.gz

This will unzip the WordPress files and you’ll get all of these files in a directory called WordPress on your home directory.

Create WordPress Database and User

As WordPress will need a MySql database, you’ll need to create one.
Let’s login to MySql now by executing the following command:

mysql -u root -p

Provide your password and you’re logged in!

Create a database for WordPress:


Replace “yourdbname” with your desired database name.

Now let’s create a user for the above database:

CREATE USER youruser@localhost;

Replace “youruser” with your preferred username.

Set password for the above user:

SET PASSWORD FOR youruser @localhost= PASSWORD("password");

Replace “youruser” & “password” with your username and password.

Now grant permission to the user for this database:

GRANT ALL PRIVILEGES ON yourdbname.* TO youruser@localhost IDENTIFIED BY 'password';

Refresh MySql:


We’re done with MySql, let’s exit:


Setup the WordPress Configuration:

Create a copy of the wp-config-sample.php file as wp-config.php. This file will contain all of your configurations:

cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php

Now open wp-config.php file:

sudo nano ~/wordpress/wp-config.php

Find the following lines of codes and replace with your own database information:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'yourdbname');

/** MySQL database username */
define('DB_USER', 'youruser');

/** MySQL database password */
define('DB_PASSWORD', 'password');

Now, save the file and exit.

Move the files

Let’s create a directory where all of your WordPress files will be located. Replace with your domain name:

sudo mkdir -p /var/www/

Move the WordPress files to WordPress root directory:

sudo mv -r ~/wordpress/* /var/www

Give ownership to nginx user, replace username with your server username:

sudo chown -R www-data:www-data /var/www/
sudo usermod -a -G www-data username

Set up nginx server blocks:

Now, you’ll need to set up your Nginx server blocks (virtual host). Create a new file for the WordPress host, copying the format from the default configuration. Replace with your domain name:

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/

Open up the newly created file:

sudo nano /etc/nginx/sites-available/

Add the following codes on that file, replace with your domain:

server {
  listen 80;

  root /var/www/;
  index index.php;


  location / {
    try_files $uri $uri/ /index.php?$args;

  # pass the PHP scripts to FastCGI server listening on
  location ~ .php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;

Save the file and exit.

Create Symbolic link for server block:

Create symbolic link for server block with the following command:

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Remove the default server block:

sudo rm /etc/nginx/sites-enabled/default

Restart nginx:

service nginx restart

WordPress Installation:

Now, access your WordPress online installation page by visiting this page:

Provide the information that the page is asking & you’re done!

Have a happy blogging!