In this Tutorial we will cover, how to install WordPress. But before we start, make sure your server is ready and with root privileges.You also need to have nginx, PHP-FPM and MySQL installed on the server. ( You can follow this tutorial to setup the server with these : LEMP Server Setup
Now lets begin installing and setting up WordPress on your server :
Step 1 Download the latest WordPress from the WordPress website itself :
wget http://wordpress.org/latest.tar.gz
After the Download is completed, Unzip the downloaded file :
tar -xzvf latest.tar.gz
Step 2 Now you will be able to see the unzipped directory "wordpress".
Next we log in to MySQL using the root password to create the WordPress database.
mysql -u root -p
CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)
Create a user in this new database and create a password for this user.
CREATE USER wpusername@localhost;
Query OK, 0 rows affected (0.00 sec)
SET PASSWORD FOR wpusername@localhost= PASSWORD("password");
Query OK, 0 rows affected (0.00 sec)
In order for the WordPress installer to start, we need to grant privileges to the new user.
FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
exit
Step 3 Update the wp-config.php, WordPress configuration file.
First we copy the wp-config-sample.php as wp-config.php
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
Next we update the database information in the wp-config.php. Add your database name, username and password instead of the ones present.
// ** 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', 'wpusername');
/** MySQL database password */
define('DB_PASSWORD', 'password');
Save the file and exit.
Step 4 We will move the unziped folder to the server's www directory.
Make the directory if not there already :
mkdir -p /var/www
Copy the unzipped folder to this directory
cp -r ~/wordpress/* /var/www
Given permissions to the directory. Replace the 'username' with your server username
sudo chown www-data:www-data * -R
sudo usermod -a -G www-data username
Step 5 Setup Nginx
Create a new file for WordPress. you can copy the default configuration on nginx
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wordpress
Open the New WordPress config file :
sudo vi /etc/nginx/sites-available/wordpress
The server block of the file should have the following settings :
server {
listen 80;
root /var/www;
index index.php index.html index.htm;
server_name 192.34.59.214;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
try_files $uri =404;
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Save the file and exit
Step 7 Wrapping up
Create a symbolic link of the new wordpress nginx configuration file :
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
Restart nginx and php5-fpm
sudo nginx -t
sudo service nginx restart
sudo service php5-fpm restart
Now access the installation page by going through the site URL or the server IP.
www.example.com/wp-admin/install.php
Fill this form to complete the installation.