{"id":22700,"date":"2014-10-22T09:10:04","date_gmt":"2014-10-22T07:10:04","guid":{"rendered":"https:\/\/mamchenkov.net\/wordpress\/?p=22700"},"modified":"2014-10-22T09:10:04","modified_gmt":"2014-10-22T07:10:04","slug":"url-rewriting-in-built-in-web-server-of-php","status":"publish","type":"post","link":"https:\/\/mamchenkov.net\/wordpress\/2014\/10\/22\/url-rewriting-in-built-in-web-server-of-php\/","title":{"rendered":"URL rewriting in built-in web server of PHP"},"content":{"rendered":"<!-- google_ad_section_start -->\n<p>PHP comes with a handy for development built-in web server. \u00a0However, most web projects have friendly URLs these days which are either Apache (mod_rewrite) or Nginx specific configuration. \u00a0This almost renders built-in PHP web server useless. \u00a0Unless you provide a PHP-based routing, like so:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$request_uri = __DIR__ . $_SERVER&#x5B;&quot;REQUEST_URI&quot;];\r\nif (file_exists($request_uri)) {\r\n  return false;\r\n} else {\r\n  include __DIR__ . \u2018\/index.php';\r\n}\r\n<\/pre>\n<p>Start the PHP web server with the following command then (routing.php being a file with the above content):<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">\r\n$ cd my-project &amp;&amp; php -S localhost:8000 routing.php\r\n<\/pre>\n<p>Thanks to this <a href=\"http:\/\/gonzalo123.com\/2012\/10\/15\/how-to-rewrite-urls-with-php-5-4s-built-in-web-server\/\">blog post and comments<\/a>. \u00a0Now you can completely skip having Apache and Nginx on developer machines and all that shenanigan with configuring virtual hosts, modules, and such.<\/p>\n<!-- google_ad_section_end -->\n","protected":false},"excerpt":{"rendered":"<!-- google_ad_section_start -->\n<p>PHP comes with a handy for development built-in web server. \u00a0However, most web projects have friendly URLs these days which are either Apache (mod_rewrite) or Nginx specific configuration. \u00a0This almost renders built-in PHP web server useless. \u00a0Unless you provide a PHP-based routing, like so: $request_uri = __DIR__ . $_SERVER&#x5B;&quot;REQUEST_URI&quot;]; if (file_exists($request_uri)) { return false; } &hellip; <a href=\"https:\/\/mamchenkov.net\/wordpress\/2014\/10\/22\/url-rewriting-in-built-in-web-server-of-php\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">URL rewriting in built-in web server of PHP<\/span><\/a><\/p>\n<!-- google_ad_section_end -->\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_links_to":"","_links_to_target":""},"categories":[1,18,62,1334],"tags":[38,1330],"keyring_services":[],"class_list":["post-22700","post","type-post","status-publish","format-standard","hentry","category-general","category-programming","category-technology","category-web-work","tag-php","tag-web-development"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":27865,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/08\/21\/using-php-fpm-as-a-simple-built-in-async-queue\/","url_meta":{"origin":22700,"position":0},"title":"Using php-fpm as a simple built-in async queue","author":"Leonid Mamchenkov","date":"August 21, 2017","format":false,"excerpt":"Here's an interesting solution for a poor man's asynchronous queue using PHP-FPM: PHP-FPM already acts as a queue for Nginx\/Apache FastCGI clients. While your web-request is running you can just send another FastCGI request to the same PHP-FPM socket asynchronously and non-blocking. This request is immediately executed in another php-fpm\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":18031,"url":"https:\/\/mamchenkov.net\/wordpress\/2013\/04\/16\/apache2-vs-nginx-for-php-application\/","url_meta":{"origin":22700,"position":1},"title":"Apache2 vs Nginx for PHP application","author":"Leonid Mamchenkov","date":"April 16, 2013","format":"link","excerpt":"Apache2 vs Nginx for PHP application The conclusion is that it doesn\u2019t matter which server you are going to chose. The real performance wins are purely on PHP side. Using an accelerator with caching can multiply the number of requests your infrastructure can maintain.","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":28432,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/03\/14\/http-2-server-push-with-php\/","url_meta":{"origin":22700,"position":2},"title":"HTTP\/2 Server Push with PHP","author":"Leonid Mamchenkov","date":"March 14, 2018","format":false,"excerpt":"A few days ago I blogged about the exciting news from the Nginx about the support for HTTP\/2 Server Push.\u00a0 It's good to see that this is getting picked up pretty fast.\u00a0 Here are a couple of examples: HTTP\/2 Server Push (with PHP and the Symfony HttpKernel) Using HTTP\/2 Server\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":29034,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/11\/26\/roadrunner-high-performance-php-application-server-load-balancer-and-process-manager\/","url_meta":{"origin":22700,"position":3},"title":"RoadRunner &#8211; high-performance PHP application server, load-balancer and process manager","author":"Leonid Mamchenkov","date":"November 26, 2018","format":false,"excerpt":"RoadRunner is a high-performance PHP application server, load-balancer and process manager, written in Goland.\u00a0 It sounds like an excellent replacement for the built-in PHP server, and even more than that - it's production-ready.\u00a0 And it works on Windows too. RoadRunner is an open source (MIT licensed) high-performance PHP application server,\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24603,"url":"https:\/\/mamchenkov.net\/wordpress\/2015\/08\/19\/custom-single-sign-on-with-nginx-and-auth-request-module\/","url_meta":{"origin":22700,"position":4},"title":"Custom Single Sign-On with Nginx and Auth Request Module","author":"Leonid Mamchenkov","date":"August 19, 2015","format":false,"excerpt":"In a recent project I crashed into a wall. \u00a0At least for a couple of days that is. \u00a0The requirement was to integrate the Request Tracker (aka RT) installation on CentOS 7 server with Nginx to\u00a0a client's company single sign-on solution. \u00a0Which wasn't LDAP. \u00a0Or Active Directory. \u00a0Or anything standard\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26306,"url":"https:\/\/mamchenkov.net\/wordpress\/2016\/08\/04\/504-gateway-timeout-error-on-nginx-fastcgi-php-fpm\/","url_meta":{"origin":22700,"position":5},"title":"504 Gateway Timeout error on Nginx + FastCGI (php-fpm)","author":"Leonid Mamchenkov","date":"August 4, 2016","format":false,"excerpt":"\"504 Gateway Timeout\" error is a very common issue when using Nginx with PHP-FPM. \u00a0Usually, that means that it took PHP-FPM longer to generate the response, than Nginx was willing to wait for. \u00a0A few possible reasons for this are: Nginx timeout configuration uses very small values (expecting the responses\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"504","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2016\/08\/504-500x385.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/22700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/comments?post=22700"}],"version-history":[{"count":0,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/22700\/revisions"}],"wp:attachment":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/media?parent=22700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/categories?post=22700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/tags?post=22700"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/keyring_services?post=22700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}