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

myweb.conf

server {
    listen 80;
    server_name www.pulpn.com pulpn.com;
    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

Or

/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

Vagrantfile:

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

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

Jasa pembuatan website Pondok Kelapa

Bagi yang berminat untuk dibuatkan website baik itu berupa blog, eCommerce, company profile, private API,  toko online untuk umum, kerjaan atau tugas kuliah/sekolah, skripsi, silahkan hubungi saya di bawah ini :

Contact: 085814729385 (SMS/Whatsapp)

Alamat: Pondok Kelapa, Duren sawit – Jakarta Timur

Jasa pembuatan aplikasi android Pondok Kelapa