Registry / devops / php-proxy-middleware

php-proxy-middleware

JSON →
library1.0.1jsnpmunverified

Middleware for Node.js (Express) that forwards HTTP requests to a built-in PHP development server. Version 1.0.1 is the latest stable release. It wraps two dependencies: proxy-middleware to proxy requests and php-built-in-server to spawn and manage a PHP process. Key differentiator: seamlessly integrates PHP processing into a Node.js/Express application without separate server setup. Supports configuration of PHP binary path, host, port, php.ini settings, and URL prefix for selective route forwarding. No updates since 2014.

npm install php-proxy-middleware
INSTALL
IMPORT
SIG · PHP-PROXY-MIDDLEWA
P
php-proxy-middleware
devopsjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const php = require('php-proxy-middleware');
CommonJS only; no ES module or named export available.
default (ESM style)
import php from 'php-proxy-middleware';
import { php } from 'php-proxy-middleware';
TypeScript may allow default import but this package has no types. Use require or set esModuleInterop.
default (with TypeScript)
import php = require('php-proxy-middleware');
import * as php from 'php-proxy-middleware';
For TypeScript with strict ESM, use import = require pattern.

Set up an Express app that forwards requests to a PHP server located in the 'php' directory.

const express = require('express'); const php = require('php-proxy-middleware'); const app = express(); // Serve static files or handle routes with Express first app.get('/', (req, res) => res.send('Hello from Express')); // Forward all other requests to PHP server app.use(php({ root: __dirname + '/php' })); app.listen(3000, () => { console.log('Server running on http://localhost:3000'); });
Debug
Known issues
breakingVersion 1.0.0 changed the function signature: you must pass an options object or path string, not separate arguments.
fix
Use php({ root: 'path' }) or php('path') instead of php('path', port, host).
affects: >=1.0.0
deprecatedThis package is no longer maintained. No updates since 2014. May have security vulnerabilities in dependencies.
fix
Consider alternatives like node-php-proxy or custom implementation using http-proxy-middleware.
affects: >=0.0.0
gotchaThe PHP built-in server is single-threaded; concurrent requests are queued. Not suitable for production.
fix
Use a real PHP-FPM setup behind nginx for production.
affects: >=0.0.0
gotchaRequires PHP CLI executable to be installed and available in PATH or specified via `phpPath` option.
fix
Ensure PHP is installed and accessible. Check with `php -v`.
affects: >=0.0.0
gotchaThe package does not handle URL decoding or encoding, which may cause issues with special characters in URLs.
fix
Ensure URLs are properly encoded before passing to PHP.
affects: >=0.0.0
Errors
Common errors & fixes
Error: spawn php ENOENT
PHP CLI not found in PATH or custom phpPath is incorrect.
fix
Install PHP and ensure it is in PATH, or set phpPath option to full path of PHP executable.
TypeError: php is not a function
Incorrect import: using import { php } instead of import php or require.
fix
Use const php = require('php-proxy-middleware'); or import php from 'php-proxy-middleware' (with esModuleInterop).
Error: listen EADDRINUSE :::<port>
The auto-detected port is already in use, or the specified port is occupied.
fix
Specify a different port using the port option, or kill the process using that port.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
proxy-middlewarerequiredHTTP proxy logic to forward requests to the PHP server
php-built-in-serverrequiredSpawn and manage the PHP built-in server process
Agent activity
4 hits · last 30 days
node
4
Resources
php-proxy-middleware — npm install php-proxy-middleware · libregistry