Postingan ini tentang integrasi PlaySMS Kannel SMS Gateway di NGINX+Debian
PlaySMS:
PlaySMS adalah perangkat lunak manajemen SMS gratis dan open source, antarmuka web untuk gateway SMS dan layanan SMS massal. Pada artikel ini kita akan mengkonfigurasi PlaySMS di Debian 10 dengan server web NGINX dan Database MariaDB. Kita akan membutuhkan PHP untuk menjalankan aplikasi web PlaySMS dan Kannel SMS Gateway. Untuk menginstal Kannel SMS Gateway, silakan periksa artikel ini.
Info Host Lingkungan LAB:
PlaySMS dan IP Host Kannel Server:192.168.10.38
IP Host Klien:192.168.10.31
Memasang NGINX:
Kami akan menggunakan Paket Debian bawaan dari Repositori NGINX Resmi
Unduh dan tambahkan paket NGINX dan kunci penandatanganan repositori ke key ring program apt:
root@sms-gw:~# wget https://nginx.org/keys/nginx_signing.key
root@sms-gw:~# apt-key add nginx_signing.key
Untuk menambahkan daftar sumber NGINX, buat /etc/apt/sources.list.d/nginx.list file dengan konten di bawah ini
deb https://nginx.org/packages/debian/ buster nginx
deb-src https://nginx.org/packages/debian/ buster nginx
Perbarui daftar repositori dan instal NGINX
root@sms-gw:~# apt-get update
root@sms-gw:~# apt-get install –y nginx
Aktifkan dan Mulai layanan NGINX dan verifikasi bahwa NGINX Server aktif dan berjalan:
root@sms-gw:~# systemctl enable nginx.service
root@sms-gw:~# systemctl start nginx.service
root@sms-gw:~# netstat –lntp
root@sms-gw:~# curl -l 127.0.0.1
Dari Mesin Klien:
NGINX Server sedang berjalan dan menampilkan halaman defaultnya.
Menginstal PHP:
Sekarang instal PHP, PHP-FPM dan paket PHP lainnya yang diperlukan untuk PlaySMS
root@sms-gw:~# apt-get install –y php php-fpm php-mysql php7.3-mysql php7.3-cli php7.3-common php7.3-xml php7.3-xmlrpc php7.3-mbstring php7.3-gd php7.3-curl
Aktifkan dan Mulai layanan PHP7.3-FPM dan periksa status
root@sms-gw:~# systemctl enable php7.3-fpm.service
root@sms-gw:~# systemctl start php7.3-fpm.service
root@sms-gw:~# systemctl status php7.3-fpm.service
Konfigurasi NGINX untuk PlaySMS:
Buat /etc/nginx/fastcgi.conf file dengan konten di bawah ini menggunakan vim
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
Ubah www-data pengguna dan grup ke nginx di /etc/php/7.3/fpm/pool.d/www.conf untuk arahan konfigurasi di bawah ini
pengguna =www-data
grup =www-data
mendengarkan.pemilik =www-data
mendengarkan.group =www-data
ubah menjadi
pengguna =nginx
grup =nginx
dengar.pemilik =nginx
mendengarkan.group =nginx
root@sms-gw:~# sed -i 's/www-data/nginx/g' /etc/php/7.3/fpm/pool.d/www.conf
Ganti file konfigurasi default NGINX untuk PlaySMS agar berjalan dengan FPM/FastCGI
root@sms-gw:~# mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bk
root@sms-gw:~# vim /etc/nginx/conf.d/default.conf
Tambahkan baris di bawah ini ke /etc/nginx/conf.d/default.conf untuk PlaySMS
server {
listen 80;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name _;
access_log /var/log/nginx/playsms_access.log;
error_log /var/log/nginx/playsms_error.log;
charset utf-8;
location / {
try_files $uri $uri/ =404;
}
location ~ .php {
include fastcgi.conf;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Anda perlu mengatur zona waktu lokal Anda untuk PHP.
Batalkan komentar dan setel date.timezone config direktif di bawah [Tanggal] bagian di /etc/php/7.3/cli/php.ini dan /etc/php/7.3/fpm/php.ini untuk mendapatkan waktu lokal untuk zona waktu Anda. Contoh:untuk New York, konfigurasi USA adalah
date.timezone = America/New_York
Mulai ulang php7.3-fpm layanan setelah mengubah info zona waktu.
root@sms-gw:~# systemctl restart php7.3-fpm.service
Catatan: Untuk daftar zona waktu, silakan kunjungi:https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
Tempatkan halaman pengujian di direktori root NGINX untuk memeriksa konfigurasi PHP dengan NGINX
root@sms-gw:~# echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php
Jelajahi http://192.168.10.38/info.php dari mesin klien
PHP bekerja dengan baik dengan NGINX menggunakan soket PHP-FPM dan menampilkan info PHP.
Instal MariaDB:
Kami akan membutuhkan layanan database untuk PlaySMS. Di sini kami menggunakan MariaDB.
Impor kunci untuk MariaDB di gantungan kunci yang tepat
root@sms-gw:~# apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
Siapkan daftar sumber untuk MariaDB:buat /etc/apt/sources.list.d/MariaDB.list file termasuk baris di bawah ini
# MariaDB 10.3 repository list - created 2021-12-28 18:41 UTC
# https://mariadb.org/download/
deb [arch=amd64,arm64,ppc64el] https://download.nus.edu.sg/mirror/mariadb/repo/10.3/debian buster main
deb-src https://download.nus.edu.sg/mirror/mariadb/repo/10.3/debian buster main
Perbarui daftar repositori dan instal MariaDB
root@sms-gw:~# apt-get update
root@sms-gw:~# apt-get install –y mariadb-server
Jika meminta untuk memberikan kata sandi root untuk MariaDB, hindari. Kami akan mengaturnya nanti
Aktifkan dan Mulai layanan MariaDB
root@sms-gw:~# systemctl enable mariadb.service
root@sms-gw:~# systemctl start mariadb.service
Jalankan mysql_secure_installation perintah untuk mengatur kata sandi root dan arahan keamanan lainnya seperti di bawah ini
Setel kata sandi root? [Y/n] Y
Setel kata sandi root MariaDB
Hapus pengguna anonim? [Y/n] Y
Larang login root dari jarak jauh? [Y/n] Y
Hapus database pengujian dan akses ke sana? [Y/n] Y
Dan akhirnya …
Muat ulang tabel hak istimewa sekarang? [Y/n] Y
Buat database dan pengguna PlaySMS di MariaDB
root@sms-gw:~# mysql -u root –p
MariaDB [(none)]> CREATE DATABASE playsms;
MariaDB [(none)]> CREATE USER 'playsmsuser'@'localhost' IDENTIFIED BY 'playsmsSecuredPassword';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON playsms.* TO 'playsmsuser'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit
Sekarang MariaDB siap untuk PlaySMS.
Memasang PlaySMS:
Instal dependensi
root@sms-gw:~# apt-get install -y zip
Tambahkan mainan pengguna
root@sms-gw:~# adduser playsms --disabled-password --home=/usr/local/playsms/
Buat direktori Log dan atur izin yang sesuai untuknya
root@sms-gw:~# mkdir /var/log/playsms
root@sms-gw:~# chown nginx:nginx -R /var/log/playsms
Beralih ke playsms pengguna
root@sms-gw:~# su - playsms
Unduh dan buka formulir rilis Resmi PlaySMS terbaru https://github.com/playsms/playsms/archive/refs/tags/1.4.5.tar.gz
playsms@sms-gw:~$ cd /tmp/
playsms@sms-gw:/tmp$ wget https://github.com/playsms/playsms/archive/refs/tags/1.4.5.tar.gz
playsms@sms-gw:/tmp$ mv 1.4.5.tar.gz playsms-1.4.5.tar.gz
playsms@sms-gw:/tmp$ tar -zxf playsms-1.4.5.tar.gz
playsms@sms-gw:/tmp$ cd playsms-1.4.5/
Catatan: Jangan gunakan PlaySMS versi kurang dari 1.4.5, yang memiliki kerentanan keamanan yang telah diperbaiki di versi 1.4.5
Buat install.conf file dengan konten di bawah ini
DBUSER="playsmsuser"
DBPASS="playsmsSecuredPassword"
DBNAME="playsms"
DBHOST="localhost"
DBPORT="3306"
WEBSERVERUSER="nginx"
WEBSERVERGROUP="nginx"
PATHSRC="$(pwd)"
PATHWEB="/usr/local/playsms/html"
PATHLIB="/usr/local/playsms/lib"
PATHBIN="/usr/local/playsms/bin"
PATHLOG="/var/log/playsms"
PATHCONF="/usr/local/playsms/etc"
Jalankan install-playsms.sh file untuk menginstal PlaySMS
Periksa data Instalasi dan konfirmasi setiap langkah
playsms@sms-gw:/tmp/playsms-1.4.5$ ./install-playsms.sh
playSMS Install Script for Ubuntu (Debian based)
==================================================================
WARNING:
- This install script WILL NOT upgrade currently installed playSMS
- This install script WILL REMOVE your current playSMS database
- This install script is compatible ONLY with playSMS version 1.4
- Please BACKUP before proceeding
==================================================================
You are NOT running this installation script as root
That means you need to make sure that this Linux user has
permission to create necessary directories
==================================================================
Proceed ?
When you're ready press [y/Y] or press [Control+C] to cancel Y
==================================================================
INSTALL DATA:
MySQL username = playsmsuser
MySQL password = playsmsSecuredPassword
MySQL database = playsms
MySQL host = localhost
MySQL port = 3306
Web server user = nginx
Web server group = nginx
playSMS source path = /tmp/playsms-1.4.5
playSMS web path = /usr/local/playsms/html
playSMS lib path = /usr/local/playsms/lib
playSMS bin path = /usr/local/playsms/bin
playSMS log path = /var/log/playsms
playSMS conf path = /usr/local/playsms/etc
==================================================================
Please read and confirm INSTALL DATA above
When you're ready press [y/Y] or press [Control+C] to cancel Y
==================================================================
Are you sure ?
Please read and check again the INSTALL DATA above
When you're ready press [y/Y] or press [Control+C] to cancel Y
==================================================================
Installation is in progress
DO NOT press [Control+C] until this script ends
==================================================================
Getting composer from https://getcomposer.com
Please wait while the install script downloading composer
Composer is ready in this folder
Pleas wait while composer getting and updating required packages
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
Composer has been installed and packages has been updated
Start................end
PLAYSMSD_CONF = /usr/local/playsms/etc/playsmsd.conf
PLAYSMS_PATH = /usr/local/playsms/html
PLAYSMS_LIB = /usr/local/playsms/lib
PLAYSMS_BIN = /usr/local/playsms/bin
PLAYSMS_LOG = /var/log/playsms
DAEMON_SLEEP = 1
ERROR_REPORTING = E_ALL ^ (E_NOTICE | E_WARNING)
IS_RUNNING =
PIDS schedule =
PIDS ratesmsd =
PIDS dlrssmsd =
PIDS recvsmsd =
PIDS sendsmsd =
playsmsd has been started
schedule at pid 21444
ratesmsd at pid 21447
dlrssmsd at pid 21450
recvsmsd at pid 21453
sendsmsd at pid 21455
playsmsd is running
schedule at pid 21444
ratesmsd at pid 21447
dlrssmsd at pid 21450
recvsmsd at pid 21453
sendsmsd at pid 21455
playSMS has been installed on your system
Your playSMS daemon script operational guide:
- To start it : playsmsd /usr/local/playsms/etc/playsmsd.conf start
- To stop it : playsmsd /usr/local/playsms/etc/playsmsd.conf stop
- To check it : playsmsd /usr/local/playsms/etc/playsmsd.conf check
ATTENTION
=========
When message "unable to start playsmsd" occurred above, please check:
1. Possibly theres an issue with composer updates, try to run: "./composer update"
2. Manually run playsmsd, "playsmsd /usr/local/playsms/etc/playsmsd.conf start", and then "playsmsd /usr/local/playsms/etc/playsmsd.conf status"
Keluar dari playsms cangkang pengguna
Setel bin . yang tepat dan conf lokasi file di /usr/local/playsms/html/plugin/feature/playsmslog/config.php
$plugin_config['playsmslog']['playsmsd']['bin'] = '/usr/local/playsms/bin/playsmsd';
$plugin_config['playsmslog']['playsmsd']['conf'] = 'https://1118798822.rsc.cdn77.org/usr/local/playsms/etc/playsmsd.conf';
Juga perlu mengatur conf yang tepat lokasi file di /usr/local/playsms/bin/playsmsd
Ubah [dekat tentang baris#222 ]
$PLAYSMSD_CONF =”;
Ke
$PLAYSMSD_CONF =‘/usr/local/playsms/etc/playsmsd.conf’;
Karena pengguna/grup server web kami adalah nginx , untuk menghindari masalah izin, kami akan mengubah kepemilikan semua konten di direktori root web PlaySMS menjadi nginx:nginx
root@sms-gw:~# cd /usr/local/playsms/html/
root@sms-gw:/usr/local/playsms/html# chown nginx:nginx -R ./*
Setel direktori root web baru di /etc/nginx/conf.d/default.conf untuk PlaySMS
Mulai ulang layanan NGINX
root@sms-gw:~# systemctl restart nginx.service
Jelajahi http://192.168.10.38/ dari workstation klien dan login dengan default Username:admin, Password:admin
Di bawah Akun Saya> Preferensi Menu Ubah Kata Sandi default dan informasi lainnya
Mengintegrasikan PlaySMS dengan Kannel SMS Gatway:
Buka Setelan> Kelola Gateway dan SMSC di portal web admin PlaySMS, klik tanda Plus (+) di sebelah opsi kannel Gateway
Masukkan info Kannel Gateway seperti yang telah kita konfigurasikan di sendsms-user grup di kannel.conf. Ref:Instalasi Kannel
Catatan: Info ini untuk akses HTTP API dua arah antara Kannel dan PlaySMS. Saat kami menginstal kedua layanan di server yang sama, kami menggunakan localhost untuk Bearerbox, Kirim SMS dan URL PlaySMS. Harap gunakan Alamat IP/FQDN host Anda jika Anda menginstal Kannel dan PlaySMS di server yang berbeda.
SMSC Kannel akan ditambahkan di bawah Tab SMSC di Pengaturan> Kelola Gateway dan SMSC
Buka Setelan> Konfigurasi Utama . Setel Kannel sebagai SMSC Default dan simpan konfigurasinya.
Mengirim SMS dari PlaySMS:
Buka Akun Saya> Tulis pesan, tulis SMS dan kirim
Log Akses Kannel:
Telepon Penerima:
Menerima SMS di PlaySMS dari Kannel:
Untuk mendapatkan SMS masuk, kita harus menambahkan URL panggilan balik PlaySMS get-url di bawah layanan sms grup di kannel.conf berkas
group = sms-service
get-url = "http://localhost/index.php?app=call&cat=gateway&plugin=kannel&access=geturl&t=%t&q=%q&a=%a&Q=%Q&smsc=kannel"
Anda akan menemukan SMS masuk di Laporan> Kotak Pasir di Portal PlaySMS.
Dari Setelan> Rutekan SMS masuk Anda dapat mengatur tujuan/tindakan untuk SMS yang masuk.
Tambahkan playsmsd untuk memulai menggunakan systemd :
Buat unit systemd /etc/systemd/system/playsms.service dengan konten di bawah ini
[Unit]
Description=PlaySMS
Documentation=https://playsms.org/documentation/
After=network-online.target
Wants=network-online.target
[Service]
User=playsms
Type=forking
ExecStart=/usr/local/playsms/bin/playsmsd start
ExecReload=/usr/local/playsms/bin/playsmsd restart
ExecStop=/usr/local/playsms/bin/playsmsd stop
Restart=on-failure
[Install]
WantedBy=multi-user.target
Muat ulang systemd dan aktifkan/mulai playsms.service
root@sms-gw:~# systemctl daemon-reload
root@sms-gw:~# systemctl enable playsms.service
root@sms-gw:~# systemctl start playsms.service
root@sms-gw:~# systemctl status playsms.service
Referensi:
https://playsms.org/documentation/
https://mariadb.org/download/?t=repo-config
https://docs.nginx.com/nginx/admin-guide/installing-nginx/