PHP Scripts and NowSMS NextGen

PHP Scripts and NowSMS NextGen SearchSearch
Author Message
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 8391
Registered: 10-2002
Posted on Tuesday, February 02, 2021 - 09:13 pm:   

NowSMS uses HTTP callbacks for 2-way SMS commands and accounting callbacks.

We've made it easy to configure NowSMS NextGen to directly support PHP-FPM (FastCGI for Unix environments), so that it is possible for NowSMS to process PHP scripts directly without having to interface with another web server.

To set this up, install php-fpm. Depending on your flavor of Linux, one of the following commands should work:

sudo apt-get install php-fpm

sudo yum install php-fpm

To verify that the php-fpm service is active, use the following command to look for the active socket:

ls /var/run/php*/*.sock

If the socket file is not found, it is possible that the php-fpm has not been started. (apt-get seems to install and start that service, while yum only installs it.) Try these commands:

sudo systemctl enable php-fpm

sudo systemctl start php-fpm

In most cases, NowSMS will automatically detect that it is available ... especially if the command ls /var/run/php*/*.sock shows that a socket file exists.

To enable NowSMS to run a PHP script, create a php directory under /var/lib/nowsms (sudo mkdir /var/lib/nowsms/php), and then save any PHP scripts in that directory with a .php extension.

For example, here's a good test.php to verify things are working:


From a web browser on the same machine, connect to

For security reasons, NowSMS will only process PHP scripts for requests that are made from the local computer. So if you try to access /php/test.php from a different computer, an error will be displayed. (To allow connections from external IP addresses, use PHPAllowRemote=Yes under the [SMSGW] header.)

The URL can be used for a 2-way command. When configuring NowSMS to use one of these scripts, for example as an accounting callback, it is recommended to configure the callback URL as http://nowsmslocal/php/script.php. ("nowsmslocal" is a special keyword recognized by NowSMS, but will not be understood by a web browser.)

If a php directory is created, NowSMS NextGen is designed to auto-detect PHP FPM. By default, when php-fpm is running, it uses a socket named /var/run/php/php7.0-fpm.sock. NowSMS looks for /var/run/php*/*.sock to hopefully account for future variations. To configure NowSMS to use a specific Unix socket interface, in the SMSGW.INI, under the [SMSGW] header, use a PHPFPMSocket= setting. For example:


On macOS, PHP is frequently installed via HomeBrew (brew install php-fpm). HomeBrew uses a default configuration file that does not use a named Unix socket, but instead uses port 9000 on the localhost ( interface. To configure NowSMS to interface with PHP FPM via this interface, under the [SMSGW] header of SMSGW.INI use:


Add Your Message Here, or click here to start a new topic.
Bold text Italics Underline Create a hyperlink Insert a clipart image
Options: Automatically activate URLs in message