php-env-server
Use a PHP's built-in development web server.
Don't use for production!!
Still in development.
Only tested on Windows 10 x64
Features
- PHP's built-in
- Available operating systems:
- win32: Windows
- Available PHP versions:
- win32 (Windows)
- 7.3.10
- 8.2.7
- win32 (Windows)
- Easy way of using it
Install
npm install php-env-server
Usage
(async () => {
// VARIABLES
const { server } = require("php-env-server");
const php = await server({});
// ... code
})();
By default, the server is configured to run under the following specifications:
-
host
- localhost. -
port
- 3000. -
root
- public. -
target
- system.
If the system doesn't match with the above configuration the server will throw an error.
Ofcourse you can change these and other options as indicated below.
API
server({...options?})
Returns an object with the following properties:
-
url
- The URL to the server. -
stop()
- A function to stop the server.
hostname
Type: string
Default: localhost
The hostname the server will use.
port
Type: number
Default: 3000
The port used by the server.
root
Type: string
Default: public
The directory the server will use as the main directory.
target
Type: string
Default: "system"
The source which indicates where PHP will be used from.
By default, it's value is system
, which means node will try to find PHP in your system to use that version and it's configuration.
It also accepts 2 more values:
-
module
: When used, theversion
(PHP version) value is required. -
custom
: This means you can use your own configuration to specify which files the server will use to work properly.
Note:
The specified version when using module
must be part of the module. Check Features section above.
version
Type: string
Default: ""
This will work only using target
as module
.
This is needed when using target
as module
.
Specify the PHP version to use.
Check Features section above to use the correct version available for your operating system.
directives
Type: object
Default: {}
Define properties in the object to specify the server configuration the directives to use instead of the ones configured in php.ini.
When using module
as target
, by default this object is configured as follow:
{
"session.save_path",
"curl.cainfo"
}
These 2 properties have a default value pointing to the paths located in the module. You can overwrite them.
-
session.save_path
: A folder to save PHP's session files created by a PHP script usingsession_start()
-
curl.cainfo
: In case you use curl in PHP to access external urls, the path to this file will tell PHP which SSL to use.
Check List of php.ini directives for more information.
arguments
Type: array
Default: []
This will work only using target
as custom
.
An array containing the arguments to use in PHP. If you want to use an argument, you must specify it's type first. Example:
-
["-c", ".../php.ini"]
: Where"-c"
is the type which indicates that the following element of the array will be the path to php.ini.
Check Command line options for more information.
Note:
To use directives, use directives
object as indicated above instead of using ["-d", "directive value"]
to avoid any error.
php_cgi
Type: string
Default: ""
This will work only using target
as custom
.
This have to be the path of the php-cgi
file to execute PHP scripts.
env
Type: object
Default: {}
Set environment variables for the PHP process.
Note:
Be REALLY careful when using env variables cause you can affect the correct functionality of PHP established by default by the module.
Check $_ENV for more information.