Berikut merupakan cara untuk menginstall webserver Nginx dengan PHP-FPM dan Userdir. Sebelum memulai pastikan Anda sudah memilki 1 server Ubuntu dengan RAM minimal 1GB.
Install Apache
1
2
apt update
apt install apache2
Selanjutnya edit /etc/apache2/mods-available/userdir.conf seperti berikut
1
2
3
4
5
6
7
8
9
10
11
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
UserDir enabled ubuntu
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
</Directory>
</IfModule>
ubuntu merupakan user yang digunakan. Anda dapat sesuaikan kembali jika menggunakan user lain.
Enable module userdir dan beberapa module lain untuk keperluan PHP
1
a2enmod userdir actions fcgid alias proxy_fcgi
Buat virtual host
1
nano /etc/apache2/sites-available/ubuntu.conf
Edit ubuntu.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster@localhost
DocumentRoot /home/ubuntu/public_html
# setting php
<IfModule mod_proxy_fcgi.c>
<Files ~ (\.php$)>
SetHandler proxy:unix:/run/php/php7.4-fpm.ubuntu.sock|fcgi://127.0.0.1:9000
</Files>
</IfModule>
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
Enable site ubuntu
1
a2ensite ubuntu
Install PHP
1
apt install php7.4 php7.4-bcmath php7.4-bz2 php7.4-cli php7.4-common php7.4-curl php7.4-enchant php7.4-fpm php7.4-imap php7.4-intl php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-xml php7.4-xmlrpc php7.4-zip
Buat pool fpm untuk user ubuntu
1
nano /etc/php/7.4/fpm/pool.d/ubuntu.conf
Edit ubuntu.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[ubuntu]
user = ubuntu
group = ubuntu
catch_workers_output = yes
chdir = /home/ubuntu/public_html/
listen = /run/php/php7.4-fpm.ubuntu.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = ondemand
pm.max_children = 5
pm.max_requests = 20
pm.process_idle_timeout = 10
pm.status_path = /status
ping.path = /ping
security.limit_extensions = .phtml .php .php3 .php4 .php5 .php6 .php7 .php8
; php.ini custom configuration directives
php_admin_flag[allow_url_fopen] = on
php_admin_flag[log_errors] = on
php_admin_value[disable_functions] = exec,passthru,shell_exec,system
php_admin_value[short_open_tag] = on
php_value[doc_root] = ""
php_value[error_log] = /home/ubuntu/logs/ubuntu.php.error.log
php_value[error_reporting] = E_ALL & ~E_NOTICE
php_value[max_execution_time] = 300
php_value[max_input_time] = 300
php_value[memory_limit] = 512M
;php_value[open_basedir] = "/home/ubuntu/:/tmp/"
php_value[post_max_size] = 256M
php_value[upload_max_filesize] = 128M
Buat Document Root
Login sebagai user ubuntu lalu buat folder public_html dan atur permission home user
1
2
mkdir public_html
chmod 711 /home/ubuntu/
Buat file index.php untuk test PHP
1
nano ~/public_html/index.php
Edit index.php
1
<?php phpinfo(); ?>
Restart service
Terakhir restart service apache dan php-fpm
1
systemctl restart apache2 php7.4-fpm
Test akses web melalui http://example.com
Optimasi
Berikut merupakan tambahan konfigurasi untuk optimasi webserver dan php-fpm.
Langkah ini opsional dan dapat Anda lewati.
httpd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
ExtendedStatus On
TraceEnable Off
ServerSignature Off
ServerTokens ProductOnly
FileETag None
StartServers 5
<IfModule prefork.c>
MinSpareServers 5
MaxSpareServers 10
</IfModule>
ServerLimit 256
MaxRequestWorkers 150
MaxConnectionsPerChild 10000
KeepAlive On
KeepAliveTimeout 5
MaxKeepAliveRequests 100
Timeout 300
php-fpm.conf
1
process_control_timeout = 10