How to use PHP built-in web server and disable access logging

Written by - 0 comments

Published on - Listed in PHP Linux


PHP comes with an internal (built in) server which can be used as a web server for development and testing purposes.

As this is a single thread process and runs each requested PHP script sequentially, the process waits for each script to be fully executed before moving on. That's why this should not be used in a production environment with public access. This is also clearly marked on the built-in web server documentation:

This web server is designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server. It should not be used on a public network.

The web server can be launched by using php on the command line with the -S parameter, defining the listener. An additional (optional) parameter -t can be used to set the "document root" for the web server.

ck@mintp /var/www/html $ php -S 0.0.0.0:8053 -t /var/www/html
[Mon Feb 28 09:02:38 2022] PHP 7.4.3 Development Server (http://0.0.0.0:8053) started

With each request on this web server...:

ck@mintp ~ $ curl localhost:8053

... the access to the requested path is logged:

ck@mintp /var/www/html $ php -S 0.0.0.0:8053 -t /var/www/html
[Mon Feb 28 09:02:38 2022] PHP 7.4.3 Development Server (http://0.0.0.0:8053) started
[Mon Feb 28 09:02:47 2022] 127.0.0.1:57186 Accepted
[Mon Feb 28 09:02:47 2022] 127.0.0.1:57186 [404]: (null) / - No such file or directory
[Mon Feb 28 09:02:47 2022] 127.0.0.1:57186 Closing

Of course when requesting a valid file, the (stdout) output from the web server shows this request:

ck@mintp ~ $ cat /var/www/html/echo.php
<?php echo "Hello world"; ?>

ck@mintp ~ $ curl localhost:8053/echo.php
Hello world

ck@mintp /var/www/html $ php -S 0.0.0.0:8053 -t /var/www/html
[Mon Feb 28 09:46:45 2022] PHP 7.4.3 Development Server (http://0.0.0.0:8053) started
[Mon Feb 28 09:49:22 2022] 127.0.0.1:57204 Accepted
[Mon Feb 28 09:49:22 2022] 127.0.0.1:57204 [200]: GET /echo.php
[Mon Feb 28 09:49:22 2022] 127.0.0.1:57204 Closing

But sometimes the access log is not wanted. In this case the additional -q parameter (standing for quiet) can be used:

ck@mintp /var/www/html $ php -S 0.0.0.0:8053 -t /var/www/html -q
[Mon Feb 28 09:53:35 2022] PHP 7.4.3 Development Server (http://0.0.0.0:8053) started

Only the very first (starting) line is shown in this case, no further request will be logged.


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder