# 06. Konfigurasi Nginx Web Server untuk menggunakan PHP-FPM

### Struktur Folder Nginx

login ke vps dengan ssh

[![Screenshot 2023-10-19 at 03.17.38.png](https://book.najamudinridha.com/uploads/images/gallery/2023-10/scaled-1680-/screenshot-2023-10-19-at-03-17-38.png)](https://book.najamudinridha.com/uploads/images/gallery/2023-10/screenshot-2023-10-19-at-03-17-38.png)

pada folder sites-available adalah kumpulan nginx virtualhost config, pada sites-enabled adalah config yang diaktifkan, untuk menghapus file virtualhost jika tidak digunakan cukup mengahapus symlink pada virtualhost di direktori sites-enabled

[![Screenshot 2023-10-19 at 03.19.43.png](https://book.najamudinridha.com/uploads/images/gallery/2023-10/scaled-1680-/screenshot-2023-10-19-at-03-19-43.png)](https://book.najamudinridha.com/uploads/images/gallery/2023-10/screenshot-2023-10-19-at-03-19-43.png)

### Konfigurasi Nginx dengan Pastcgi\_pass TCP

untuk merubah konfigurasi dari unix socket ke tcp, kita hanya perlu merubah pastcgi\_pass parameter seperi berikut ini

[![Screenshot 2023-10-19 at 03.25.54.png](https://book.najamudinridha.com/uploads/images/gallery/2023-10/scaled-1680-/screenshot-2023-10-19-at-03-25-54.png)](https://book.najamudinridha.com/uploads/images/gallery/2023-10/screenshot-2023-10-19-at-03-25-54.png)

dan menyesuaikan php pool untuk listen pada tcp

[![Screenshot 2023-10-19 at 03.26.15.png](https://book.najamudinridha.com/uploads/images/gallery/2023-10/scaled-1680-/screenshot-2023-10-19-at-03-26-15.png)](https://book.najamudinridha.com/uploads/images/gallery/2023-10/screenshot-2023-10-19-at-03-26-15.png)

### Menambahkan Access dan Error Log Nginx

untuk menambahkan access log dan error log per virtualhost, tambahkan config access\_log dan error\_log pada setiap virtualhost dengan lokasi penyimpanan yang diinginkan seperti berikut ini :

```nginx
server {
        listen 80;
        listen [::]:80;

        root /var/www/idrive;

        index index.html index.php index.htm index.nginx-debian.html;

        access_log /var/log/nginx/idrive.id.log;
        error_log /var/log/nginx/idrive.id.error.log;

        server_name idrive.id www.idrive.id;

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

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        }
}
```

[![Screenshot 2023-10-19 at 03.27.25.png](https://book.najamudinridha.com/uploads/images/gallery/2023-10/scaled-1680-/screenshot-2023-10-19-at-03-27-25.png)](https://book.najamudinridha.com/uploads/images/gallery/2023-10/screenshot-2023-10-19-at-03-27-25.png)

cek access\_log dengan perintah tail untuk melihat perubahan secara langsung

[![Screenshot 2023-10-19 at 03.32.20.png](https://book.najamudinridha.com/uploads/images/gallery/2023-10/scaled-1680-/screenshot-2023-10-19-at-03-32-20.png)](https://book.najamudinridha.com/uploads/images/gallery/2023-10/screenshot-2023-10-19-at-03-32-20.png)

<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen="allowfullscreen" frameborder="0" src="https://www.youtube.com/embed/O6_yVdL122U?si=6JZys02CWm414a1C" style="width: 100%; aspect-ratio: 16/10;" title="YouTube video player"></iframe>