Multiple Domain for PHP
3 min read
Running Multiple Domain Names on PHP Server #
Dengan menggunakan multiple domain, Kamu bisa meningkatkan kemudahan penggunaan, efisiensi, dan skalabilitas aplikasi PHP-mu, serta tentunya menghemat biaya karena tidak perlu membuat instance terpisah untuk setiap domain.
Berikut langkah-langkah untuk menjalankan multiple domain pada server aplikasi PHP agar aplikasi kamu menjadi lebih scalable dan efektif :
1. Masuk ke dashboard Jagoan Cloud.
2. Klik tombol Create environment di pojok kiri atas dashboard.
3. Pada wizard yang muncul, buka tab PHP, pilih server aplikasi yang Lamu inginkan, dan tentukan jumlah resource yang dibutuhkan oleh aplikasi. Setelah itu, beri nama untuk environment-nya dan klik tombol Create.

Dalam beberapa saat, environment Kamu akan muncul di dashboard platform.

- Kamu perlu memiliki nama domain di DNS yang mengarah ke alamat IP milikmu. Untuk penjelasan lebih lanjut bisa Kamu baca di tutorial berikut : Custom Domain.
- Setelah itu, klik tombol Settings untuk environment-mu dan hubungkan domain-domain tersebut. Sebagai contoh, kita menggunakan URL: mydomain.com dan myseconddomain.com.

📝 NOTE
Dalam kasus ini, kita menambahkan entri pada file hosts untuk keperluan pengujian lokal, dan cara ini hanya akan berfungsi di mesin yang memiliki entri hosts tersebut.
6. Sekarang Kamu bisa mengunggah paket zip berisi aplikasimu ke Deployment Manager, lalu deploy ke environment yang sudah kamu buat sebelumnya.


7. Setelah aplikasimu berhasil di-deploy, Kamu perlu mengatur konfigurasi virtual host.
A. Untuk Apache:
Klik tombol Config di samping server Apache, lalu buka file httpd.conf (yang ada di direktori conf). Atur parameter VirtualHost secara terpisah untuk masing-masing domain dengan menentukan jalur ke konteks aplikasi yang sudah di-deploy serta nama domainnya, seperti ini:
Listen 80
<VirtualHost *:80> DocumentRoot /var/www/webroot/firstapp ServerName mydomain.com </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/webroot/secondapp ServerName myseconddomain.com </VirtualHost>
B. Untuk NGINX:
1. Klik tombol Config di samping server NGINX, lalu buka file nginx.conf di direktori conf. Tentukan pengaturan kamu di dalam blok server:
- server_name : Nama domain yang Kamu gunakan
- root : Konteks atau jalur aplikasi yang Kamu tentukan saat proses deploy
Perlu dicatat bahwa setiap domain yang Kamu hubungkan harus memiliki blok server tersendiri dengan pengaturannya masing-masing. Contohnya:
server { listen 80; server_name localhost; include /etc/nginx/aliases.conf; location / { root /var/www/webroot/ROOT; index index.html index.htm index.php; location ~ \.php$ { location ~ /\. { deny all; access_log off; log_not_found off; } include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /var/www/webroot/ROOT$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param DOCUMENT_ROOT /var/www/webroot/ROOT; } } index index.php index.html index.htm; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ /\. { deny all; access_log off; log_not_found off; } location ~ \.php$ { location ~ /\. { deny all; access_log off; log_not_found off; } include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /var/www/webroot$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param DOCUMENT_ROOT /var/www/webroot; } }
Dalam tutorial ini, kita akan menggunakan config berikut :
server { listen 80; server_name mydomain.com; include /etc/nginx/aliases.conf; location / { root /var/www/webroot/firstapp; index index.html index.htm index.php; location ~ \.php$ { location ~ /\. { deny all; access_log off; log_not_found off; } include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /var/www/webroot/firstapp$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param DOCUMENT_ROOT /var/www/webroot/firstapp; } } index index.php index.html index.htm; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ /\. { deny all; access_log off; log_not_found off; } location ~ \.php$ { location ~ /\. { deny all; access_log off; log_not_found off; } include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /var/www/webroot$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param DOCUMENT_ROOT /var/www/webroot; } } server { listen 80; server_name myseconddomain.com; include /etc/nginx/aliases.conf; location / { root /var/www/webroot/secondapp; index index.html index.htm index.php; location ~ \.php$ { location ~ /\. { deny all; access_log off; log_not_found off; } include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /var/www/webroot/secondapp$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param DOCUMENT_ROOT /var/www/webroot/secondapp; } } index index.php index.html index.htm; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ /\. { deny all; access_log off; log_not_found off; } location ~ \.php$ { location ~ /\. { deny all; access_log off; log_not_found off; } include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /var/www/webroot$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param DOCUMENT_ROOT /var/www/webroot; } }

8. Jangan lupa untuk menyimpan perubahan dan me-restart server aplikasi agar pengaturan baru bisa diterapkan.

9. Sekarang Kamu bisa mengecek hasilnya untuk memastikan semuanya berjalan dengan baik.

Semoga instruksi ini bermanfaat untuk Kamu. Selamat mencoba!
Powered by BetterDocs
