Code Monkey home page Code Monkey logo

php-fpm-cli's Introduction

php-fpm-cli

Running PHP-FPM, especially for website hosts using NGINX, is missing an important functionality to execute PHP scripts directly from the command-line.

With this simple script, one can execute PHP scripts directly from CLI. It is convenient to test PHP in CLI, run batch operations with PHP and for cronjobs.

This script is based on Mathias Leppich's gist, with added support for loading the script from a file (instead of input code as CLI argument), query-string parameters and verification of not only the exit code of the script - but also http-status-code.

See more details in: https://elisegev.medium.com/running-php-fpm-in-cli-e1f0f4b4f59a

Requirements

Dependencies

RHEL / CentOS

yum --enablerepo=epel install fcgi

Ubuntu / Debian

apt-get install libfcgi0ldbl

Setup

PHP script needs to be executable and owned by an allowed user (ACL):

vi /etc/php-fpm.d/www.conf
# add your ACL user to the comma-delimited list: listen.acl_users
# e.g. listen.acl_users = apache,nginx,myuser
systemctl restart php-fpm

Usage

Run PHP script:

./php-fqm-cli -f <path_to_php_file>

Run PHP script with query params:

./php-fqm-cli -f <path_to_php_file> -q "<query_params>"

Example:

./php-fqm-cli -f myscript.php -q "param1=val1&param2=val2"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.