{"id":3902,"date":"2021-11-18T06:50:29","date_gmt":"2021-11-18T06:50:29","guid":{"rendered":"https:\/\/www.itersdesktop.com\/?p=3902"},"modified":"2021-11-18T06:59:20","modified_gmt":"2021-11-18T06:59:20","slug":"is-it-possible-to-start-a-web-server-from-any-php-web-based-directory","status":"publish","type":"post","link":"https:\/\/www.itersdesktop.com\/fr\/2021\/11\/18\/is-it-possible-to-start-a-web-server-from-any-php-web-based-directory\/","title":{"rendered":"Is it possible to start a web server from any php web based directory?"},"content":{"rendered":"<p>I recently discovered another way to start a web server from any location for any application written in <a href=\"https:\/\/php.net\">PHP<\/a>. As of PHP web developer, I bet all of you are aware of <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">htdocs<\/code> or <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">www<\/code> directory sounding very popular in the world of LAMPP or XAMPP. Don&rsquo;t let you waste your time. I am going to write how to do so instantly.<\/p>\n<h1>Steps<\/h1>\n<p>To practise this tutorial, I have made a simple web application and pushed it to <a href=\"https:\/\/github.com\/ITersDesktop\">the blog&rsquo;s GitHub<\/a> to help you approach quickly the instruction. The repository can be found at <a href=\"https:\/\/github.com\/ITersDesktop\/phplog\">https:\/\/github.com\/ITersDesktop\/phplog<\/a>.<\/p>\n<p>From your terminal,<\/p>\n<ul>\n<li>run <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git clone<\/code> to copy this repo to your local working directory.<\/li>\n<li>start the server <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">php -s 0.0.0.0:[port-number]<\/code>. For example, <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">php -S 0.0.0.0:2021<\/code> to start the server at the current directory on port 2021.<\/li>\n<\/ul>\n<p>If you clone the repo into your already established application server which is being used to run PHP based apps, you don&rsquo;t need to start the server as instructed above. The result will look like this:<\/p>\n<figure id=\"attachment_3903\" aria-describedby=\"caption-attachment-3903\" style=\"width: 644px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3903\" src=\"https:\/\/www.itersdesktop.com\/wp-content\/uploads\/2021\/11\/start-a-php-server.png\" alt=\"Start a PHP server at any directory\" width=\"644\" height=\"239\" srcset=\"https:\/\/www.itersdesktop.com\/wp-content\/uploads\/2021\/11\/start-a-php-server.png 644w, https:\/\/www.itersdesktop.com\/wp-content\/uploads\/2021\/11\/start-a-php-server-300x111.png 300w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><figcaption id=\"caption-attachment-3903\" class=\"wp-caption-text\"><em>Start a PHP server at any directory<\/em><\/figcaption><\/figure>\n<p>The screenshot shows that the server has been started at the address 0.0.0.0 on port 2021. The application can be accessed from http:\/\/127.0.0.1:2021.<\/p>\n<h1>Comments<\/h1>\n<p>The reason why I want to capture the steps and leave them on this blog is to make my work more efficient. So far all we know is that PHP based web applications must be placed in htdocs or www directories of the traditional and common servers recommended using for developing websites with PHP, MySQL as well as Apache. The drawbacks of this way can be shown, for example, the web application is too large to move to those specific directories, my application is trivial so I want to test a feature as quickly as possible. By using this new proposed way, I can stay anywhere on my favourite study or research directory, start a simple web server and begin testing the feature of interest. This approach is similar to the way of <a href=\"https:\/\/www.itersdesktop.com\/2016\/12\/11\/running-a-simple-http-server\/\">running a simple HTTP server with Python<\/a> introduced and published in this blog.<\/p>\n<p>The job&rsquo;s done!<\/p>\n<p>As always, all constructive comments are welcomed.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently discovered another way to start a web server from any location for any application written in PHP. As of PHP web developer, I bet all of you are&hellip; <\/p>\n","protected":false},"author":2,"featured_media":3903,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,637],"tags":[89,528,294],"class_list":["post-3902","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-engineering","category-web-server","tag-php","tag-serveur-web","tag-web-server"],"_links":{"self":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts\/3902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/comments?post=3902"}],"version-history":[{"count":3,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts\/3902\/revisions"}],"predecessor-version":[{"id":3906,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts\/3902\/revisions\/3906"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/media\/3903"}],"wp:attachment":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/media?parent=3902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/categories?post=3902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/tags?post=3902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}