I can run a simple built-in webserver with command "php -S localhost:8001" I find it very simple and useful for creating bookmarklets for the browser, as .js files. Now I would like to know if it is able to run CGI scripts too? I should maintain a simple key-value database from the javascript code of the bookmarklet.
No, it can't.
You could probably write a wrapper around a CGI program in PHP, but it would be easier to use a more suitable webserver.