IGOS Nusantara dan nginx dan php: Perbedaan revisi

Dari IGNwiki
Langsung ke: navigasi, cari

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /var/www/html/igos-nusantara-web/wiki/includes/diff/DairikiDiff.php on line 438
(Mengaktifkan situs di home directory)
(Mengaktifkan situs di home directory)
Baris 57: Baris 57:
 
== Mengaktifkan situs di home directory ==
 
== Mengaktifkan situs di home directory ==
  
location ~ ^/~(?<userdir_user>.+?)(?<userdir_uri>/.*)?$
+
=== Buar berkas userdir.conf ===
 +
 
 +
Berkas buat di: /etc/nginx/conf.d/'''userdir.conf'''
 +
 
 +
server
 
  {
 
  {
alias /home/$userdir_user/public_html$userdir_uri;
+
    server_name localhost;
fastcgi_pass  127.0.0.1:9001;
+
include fastcgi_params;
+
fastcgi_param SCRIPT_FILENAME $request_filename;
+
index index.html index.htm index.php;
+
autoindex on;
+
}
+
 
   
 
   
location ~ ^/~(.+?)(/.*)?$ {
+
    # Userdir - php
alias /home/$1/public_html$2;
+
    location ~ ^/~([^/]+)/(.+\.php)$ {
index index.html index.htm index.php;
+
        if (!-f /home/$1/public_html/$2) {
autoindex on;
+
            rewrite ^ 404;
  }
+
        }
 +
        alias /home/$1/public_html/$2;
 +
        fastcgi_pass  127.0.0.1:9000;
 +
        fastcgi_index index.php;
 +
        fastcgi_param SCRIPT_FILENAME $request_filename;
 +
        include fastcgi_params;
 +
    }
 +
 +
    # Userdir - static
 +
    location ~ ^/~([^/]+)(/.*)?$ {
 +
        alias /home/$1/public_html$2;
 +
        autoindex on;
 +
    }
 +
}
 +
 
 +
=== Atur hak akses home directory ===
 +
Misal nama pengguna "igos" akan mengaktifkan home directory
 +
 
 +
  #
 +
chmod 701 /home/igos/
 +
 
 +
$
 +
cd /home/igos
 +
mkdir public_html
 +
 
 +
=== Buat berkas coba.html dan coba.php ===
 +
Berkas dibuat oleh pengguna igos di /home/igos/public_html
 +
 
 +
$
 +
cd /home/igos/public_html
 +
echo "tes1" > coba.html
 +
echo "<?php phpinfo(); ?>" > coba.php
 +
 
 +
=== Tes di perambah ===
 +
Akses ke:
 +
  http://localhost/~igos/

Revisi per 21 Juli 2014 04.57

Panduan ini telah dicoba di IGOS Nusantara 9.2

Pasang nginx dan modul-modul php

# Pasang nginx
yum install nginx
# Pasang modul modul php
yum install php-fpm php-common php-pecl-apcu php-cli \
   php-pear php-pdo php-mysqlnd php-pgsql \
   php-pecl-mongo php-pecl-memcache php-pecl-memcached \
   php-gd php-mbstring php-mcrypt php-xml
# Pasang Zend OPcache 
yum install php-opcache

Jalankan

#
systemctl start  nginx.service
systemctl start  php-fpm.service

Tes halaman default

Silakan test dari browser:

http://localhost

Aktifkan nginx dan php-fpm

#
systemctl enable nginx.service
systemctl enable php-fpm.service

Konfgurasi /etc/nginx/nginx.conf

Baris 77 sampai 83 menjadi

       location ~ \.php$ {
           root           /usr/share/nginx/html;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           include        fastcgi_params;
       }

Jalankan ulang nginx

#
systemctl reload nginx.service

Buat berkas /usr/share/nginx/html/info.php

<?php 
   phpinfo();
?>

Tes skrip info.php

Silakan test dari browser:

http://localhost/info.php

Mengaktifkan situs di home directory

Buar berkas userdir.conf

Berkas buat di: /etc/nginx/conf.d/userdir.conf

server
{
   server_name localhost;

   # Userdir - php
   location ~ ^/~([^/]+)/(.+\.php)$ {
       if (!-f /home/$1/public_html/$2) {
           rewrite ^ 404;
       }
       alias /home/$1/public_html/$2;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $request_filename;
       include fastcgi_params;
   }

   # Userdir - static
   location ~ ^/~([^/]+)(/.*)?$ {
       alias /home/$1/public_html$2;
       autoindex on;
   }

}

Atur hak akses home directory

Misal nama pengguna "igos" akan mengaktifkan home directory

#
chmod 701 /home/igos/
$
cd /home/igos
mkdir public_html

Buat berkas coba.html dan coba.php

Berkas dibuat oleh pengguna igos di /home/igos/public_html

$
cd /home/igos/public_html
echo "tes1" > coba.html
echo "<?php phpinfo(); ?>" > coba.php

Tes di perambah

Akses ke:

http://localhost/~igos/