Setup nginx, php, wordpress in ubuntu

So after all these years I’ve had using apache for run something that runs with php, but since I know about nginx, I’ve been using this webserver instead of apache.

This wordpress blog is running with nginx and php-fpm, because not like apache that you can run anything about php without install the additional package. With nginx, you’ll need php-fpm to run php behind nginx.

This is the steps that I always use for make my php run behind nginx, especially when I setup this wordpress blog. Since I’m using mysql for database, you might want to install php package for mysql as well.

apt-get install php5-common php5-fpm php5-mysql

create nginx configuration for php website

vim /etc/nginx/conf.d/myweb.conf


server {
    listen 80;
    charset utf-8;
    gzip_vary on;
    access_log /var/log/nginx/myweb.access.log;
    error_log /var/log/nginx/myweb.error.log;
    add_header 'Access-Control-Allow-Origin' '*' always;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
    location / {
        root /var/www/pulpn;
        index index.php;
        try_files $uri $uri/ /index.php?q=$uri&$args;
        location ~* \.php {
            try_files $uri =404;
            include fastcgi_params;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass  unix:/var/run/php5-fpm.sock;

Restart your nginx :

service nginx restart


/etc/init.d/nginx restart

Vagrantfile example

Just an example of Vagrantfile in case I need it. you can also use it.

$ mkdir vagrant
~/vagrant:~$ touch Vagrantfile
~/vagrant:~$ vagrant up


# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config| = "ubuntu/xenial64" "private_network", ip: ""
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "2048"
  config.vm.provision :shell, :path => ""
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "playbook.yml"
    ansible.limit = "all"
    ansible.verbose = "vv"
    ansible.raw_arguments = [

My vim standard config

highlight Cursor guifg=white guibg=black
highlight iCursor guifg=white guibg=steelblue
set guicursor=n-v-c:block-Cursor
set guicursor+=i:ver100-iCursor
set guicursor+=n-v-c:blinkon0
set guicursor+=i:blinkwait10
set mouse=a

autocmd TextChanged,TextChangedI <buffer> silent write

set clipboard=unnamedplus
set paste
set nu
set tabstop=4

noremap <S-s> :w <Enter>

let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_winsize = 25
augroup ProjectDrawer
  autocmd VimEnter * :Vexplore
augroup END

function! NetrwOpenMultiTab(current_line,...) range
   " Get the number of lines.
   let n_lines =  a:lastline - a:firstline + 1

   " This is the command to be built up.
   let command = "normal "

   " Iterator.
   let i = 1

   " Virtually iterate over each line and build the command.
   while i < n_lines
      let command .= "tgT:" . ( a:firstline + i ) . "\<CR>:+tabmove\<CR>"
      let i += 1
   let command .= "tgT"

   " Restore the Explore tab position.
   if i != 1
      let command .= ":tabmove -" . ( n_lines - 1 ) . "\<CR>"

   " Restore the previous cursor line.
   let command .= ":" . a:current_line  . "\<CR>"

   " Check function arguments
   if a:0 > 0
      if a:1 > 0 && a:1 <= n_lines
         " The current tab is for the nth file.
         let command .= ( tabpagenr() + a:1 ) . "gt"
         " The current tab is for the last selected file.
         let command .= (tabpagenr() + n_lines) . "gt"
   " The current tab is for the Explore tab by default.

   " Execute the custom command.
   execute command

" Define mappings.
augroup NetrwOpenMultiTabGroup
   autocmd Filetype netrw vnoremap <buffer> <silent> <expr> t ":call NetrwOpenMultiTab(" . line(".") . "," . "v:count)\<CR>"
   autocmd Filetype netrw vnoremap <buffer> <silent> <expr> T ":call NetrwOpenMultiTab(" . line(".") . "," . (( v:count == 0) ? '' : v:count) . ")\<CR>"
augroup END

"execute "set <M-j>=\e1"
"nnoremap <M-j> :tabnew

noremap <Esc>1 1gt
noremap <Esc>2 2gt
noremap <Esc>3 3gt
noremap <Esc>4 4gt
noremap <Esc>5 5gt
noremap <Esc>6 6gt
noremap <Esc>7 7gt
noremap <Esc>8 8gt
noremap <Esc>9 9gt
noremap <Esc>z :tabnext <Enter>
noremap <C-w> :close <Enter> <Esc>
noremap <C-Tab> gt
noremap <C-S-Tab> gT
noremap <C-t> :tabnew <Enter>
noremap <Esc>e :Vex <Enter>
noremap <Esc>q :qa! <Enter>
noremap <Space>d <C-w>l
noremap <Space>a <C-w>h
noremap <Space>w <C-w>k
noremap <Space>s <C-w>j
noremap <Esc>s <C-w>w
noremap <C-s> :w <Enter>

" CTRL-Tab is next tab
noremap <C-Tab> :<C-U>tabnext<CR>
inoremap <C-Tab> <C-\><C-N>:tabnext<CR>
cnoremap <C-Tab> <C-C>:tabnext<CR>
" CTRL-SHIFT-Tab is previous tab
noremap <C-S-Tab> :<C-U>tabprevious<CR>
inoremap <C-S-Tab> <C-\><C-N>:tabprevious<CR>
cnoremap <C-S-Tab> <C-C>:tabprevious<CR>

noremap <silent> <F12> touch ~/.uwsgi.ini<cr>