{"id":139,"date":"2020-07-20T17:16:57","date_gmt":"2020-07-20T17:16:57","guid":{"rendered":"http:\/\/toogreen.ca\/blog\/?p=139"},"modified":"2022-09-03T19:26:32","modified_gmt":"2022-09-03T19:26:32","slug":"run-a-web-server-from-any-folder-on-your-mac","status":"publish","type":"post","link":"https:\/\/toogreen.ca\/blog\/index.php\/2020\/07\/20\/run-a-web-server-from-any-folder-on-your-mac\/","title":{"rendered":"Run a Web Server from Any Folder on Your Mac!"},"content":{"rendered":"\n<p>I just discovered this really simple hack which is both a time and life saver if you want to quickly test simple websites on your machine. From any folder (a GIT folder for example where your code is), you simply need to run this simple Python command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python -m SimpleHTTPServer 8000<\/code><\/pre>\n\n\n\n<p><strong>UPDATE! <\/strong>Since Python 3, it has now changed to this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python3 -m http.server<\/code><\/pre>\n\n\n\n<p>As you may have guessed, this will start a web server on port 8000. So from your browser, now all you need to do is go to http:\/\/localhost:8000 and, magic, you can now see the website you&#8217;re working on. To make it faster in the future, make it an executable file. Here&#8217;s a quick and easy way to do that, again, from that folder you&#8217;re working in:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"python -m SimpleHTTPServer 8000\" &gt; run.sh\nchmod a+x run.sh<\/code><\/pre>\n\n\n\n<p>Or, if you are using Python 3:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"python3 -m http.server\" > run.sh\nchmod a+x run.sh<\/code><\/pre>\n\n\n\n<p>Then to run it next time without having to remember the whole thing, simply type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/run.sh<\/code><\/pre>\n\n\n\n<p>That&#8217;s it! Enjoy. Below is the source of where I found this awesome trick:<\/p>\n\n\n\n<p><a href=\"https:\/\/lifehacker.com\/start-a-simple-web-server-from-any-directory-on-your-ma-496425450\">https:\/\/lifehacker.com\/start-a-simple-web-server-from-any-directory-on-your-ma-496425450<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just discovered this really simple hack which is both a time and life saver if you want to quickly test simple websites on your machine. From any folder (a GIT folder for example where your code is), you simply need to run this simple Python command: UPDATE! Since Python 3, it has now changed&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36,85],"tags":[34,84,60,90,58,86,91,87,88,81],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-coding","category-mac-os","tag-coding","tag-css","tag-html","tag-html5","tag-javascript","tag-mac-os","tag-python","tag-unix","tag-web-development","tag-webdev"],"_links":{"self":[{"href":"https:\/\/toogreen.ca\/blog\/index.php\/wp-json\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/toogreen.ca\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/toogreen.ca\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/toogreen.ca\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/toogreen.ca\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=139"}],"version-history":[{"count":2,"href":"https:\/\/toogreen.ca\/blog\/index.php\/wp-json\/wp\/v2\/posts\/139\/revisions"}],"predecessor-version":[{"id":480,"href":"https:\/\/toogreen.ca\/blog\/index.php\/wp-json\/wp\/v2\/posts\/139\/revisions\/480"}],"wp:attachment":[{"href":"https:\/\/toogreen.ca\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/toogreen.ca\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/toogreen.ca\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}