How to Install WordPress with SSH and Nginx

wordpress_install

It feels like I’m installing a WordPress site just about every week, and I’ve put the following together to help me remember how to do it!  If it comes in useful to anyone else then I’m happy too.  We’ll assume you’re using Ubuntu 11.10 for this How To and running a LEMP server, although tailoring for Apache should be easy enough too using this method.

Logon to your server with your favourite SSH client:

ssh [email protected]

We’ll install unzip to player with the files:

apt-get install unzip

Lets get to the home directory:

cd /root

Download WordPress:

wget http://wordpress.org/latest.zip

Unzip:

unzip latest.zip

Create the destination folder:

mkdir /var/companya.com/httpdocs

Copy the files:

cp -rf ./wordpress/* /path/to/your/directory

For instance something like this:

cp -rf ./wordpress/* /var/companya.com/httpdocss

Lets make sure that the WordPress permissions are comfortable.

chown -hR 33:33 /var/companya.com/httpdocs

(If that doesn’t work for you see my post here.)

Now lets set up the database:

mysql -u[root] -p[password]

(Where [root] is your MySQL username and [password] is your MySQL password.)

create database database_name_you_want;

grant usage on database_name_you_picked.* to username_you_want@localhost identified by ‘password’;

(Where password is the password you want to use.)

grant all privileges on database_name_you_picked.* to ‘username_you_picked’@localhost;

exit

Now lets set up the Nginx virtual host.  Type in:

nano /etc/nginx/sites-enabled/companya.com

And now fill in that file with something like the following (obviously paying attention to your specifics I’ve highlighted in bold) use this as an Nginx template if you like:

server {
root /var/companya.com/httpdocs/;
index index.php index.html index.htm;
access_log /var/companya.com/logs/access.log combined;
server_name www.companya.com companya.com;

location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}

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

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 1w;
log_not_found off;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}

[ctrl]+o to save, then [ctrl]+x to close Nano.

Now lets restart Nginx

service nginx restart

Now open your website, for example www.gypthecat.com and you should be all good to install using the details you picked here.

Trackbacks for this post

  1. WordPress Security Tips from an Expert .. WordPress Insider | The WordPress Tip Center

Got something to say? Go for it!