{"id":170,"date":"2006-11-28T10:20:11","date_gmt":"2006-11-28T10:20:11","guid":{"rendered":"https:\/\/bodhost.com\/kb\/\/web-hosting\/?p=170"},"modified":"2026-02-26T14:04:58","modified_gmt":"2026-02-26T14:04:58","slug":"execute-cgi-outside-cgi-bin","status":"publish","type":"post","link":"https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/","title":{"rendered":"Execute CGI outside CGI-bin"},"content":{"rendered":"<p><span style=\"color: #000000;\"><\/span><\/p>\r\n<p><span style=\"color: #000000;\">By default, many web servers (like Apache) are configured to run CGI scripts only inside the cgi-bin directory. While this is a good security practice, sometimes developers may want to execute CGI scripts from other folders for flexibility and easier application structure.<\/span><\/p>\r\n<p><span style=\"color: #000000;\">This guide explains how to enable CGI execution outside the default cgi-bin directory using a simple .htaccess configuration.<\/span><\/p>\r\n<h2 data-start=\"767\" data-end=\"797\"><span style=\"color: #000000;\">What is CGI and CGI-Bin?<\/span><\/h2>\r\n<ul data-start=\"798\" data-end=\"1059\">\r\n<li data-start=\"798\" data-end=\"970\">\r\n<p data-start=\"800\" data-end=\"970\"><span style=\"color: #000000;\">CGI (Common Gateway Interface): A standard method that allows web servers to run external scripts (written in Perl, Python, etc.) and send dynamic content to users.<\/span><\/p>\r\n<\/li>\r\n<li data-start=\"971\" data-end=\"1059\">\r\n<p data-start=\"973\" data-end=\"1059\"><span style=\"color: #000000;\">cgi-bin: The default directory where most servers store and execute CGI scripts.<\/span><\/p>\r\n<\/li>\r\n<\/ul>\r\n<p data-start=\"1061\" data-end=\"1196\"><span style=\"color: #000000;\">By enabling CGI outside this directory, you can run scripts from custom folders useful for projects with unique directory structures.<\/span><\/p>\r\n<h3><span style=\"color: #000000;\">Steps to Execute:<\/span><\/h3>\r\n<p><span style=\"color: #000000;\"><strong>1. Create or Edit the .htaccess File<\/strong><\/span><\/p>\r\n<p><span style=\"color: #000000;\">In the folder where you want to allow CGI, create (or edit) a file named .htaccess.<\/span><\/p>\r\n<p><span style=\"color: #000000;\"><strong>2. Add CGI Handler and Execution Options<\/strong><\/span><\/p>\r\n<p><span style=\"color: #000000;\">Insert the following lines into .htaccess:<\/span><\/p>\r\n<p><span style=\"color: #000000;\"><em>AddHandler cgi-script .pl .cgi<\/em><\/span><br \/><span style=\"color: #000000;\"><em>Options +ExecCGI<\/em><\/span><\/p>\r\n<p><span style=\"color: #000000;\">AddHandler cgi-script .pl .cgi &gt;&gt; tells Apache to treat .pl and .cgi files as executable scripts.<\/span><\/p>\r\n<p><span style=\"color: #000000;\">Options +ExecCGI &gt;&gt; enables execution of CGI scripts within that folder.<\/span><\/p>\r\n<p><span style=\"color: #000000;\"><strong>3. Set File Permissions<\/strong><\/span><\/p>\r\n<p><span style=\"color: #000000;\">Ensure your script files have execute permission:<\/span><\/p>\r\n<p><span style=\"color: #000000;\"><em>chmod 755 script.cgi<\/em><\/span><br \/><span style=\"color: #000000;\"><em>chmod 755 script.pl<\/em><\/span><\/p>\r\n<p><span style=\"color: #000000;\"><strong>4. Restart Apache (If Needed)<\/strong><\/span><\/p>\r\n<p><span style=\"color: #000000;\">If changes don\u2019t take effect immediately, restart Apache:<\/span><\/p>\r\n<p><span style=\"color: #000000;\"><em>systemctl restart httpd<\/em><\/span><\/p>\r\n<h4 data-pm-slice=\"0 0 []\">Best Practices:<\/h4>\r\n<ul>\r\n<li>Prioritize Security: Don\u2019t allow CGI scripts to run outside trusted areas (like the cgi-bin folder) to avoid security risks.<\/li>\r\n<li>Check Input: Make sure you clean and validate any user input to prevent attacks.<\/li>\r\n<li>Limit Access: Use .htaccess or file permissions to control who can access important scripts.<\/li>\r\n<li>Check for Errors: If scripts aren\u2019t working, look at the Apache error logs for clues.<\/li>\r\n<\/ul>\r\n<p><span style=\"color: #000000;\"><\/span><\/p>","protected":false},"excerpt":{"rendered":"<p>By default, many web servers (like Apache) are configured to run CGI scripts only inside the cgi-bin directory. While this is a good security practice, sometimes developers may want to execute CGI scripts from other folders for flexibility and easier application structure. This guide explains how to enable CGI execution outside the default cgi-bin directory [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[666],"tags":[1423],"class_list":["post-170","post","type-post","status-publish","format-standard","hentry","category-general","tag-cgi"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Executing CGI Outside the CGI-bin | Step-by-Step Guide<\/title>\n<meta name=\"description\" content=\"Learn how to execute CGI scripts outside the default cgi-bin directory by updating your .htaccess file. Step-by-step instructions and tips.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Executing CGI Outside the CGI-bin | Step-by-Step Guide\" \/>\n<meta property=\"og:description\" content=\"Learn how to execute CGI scripts outside the default cgi-bin directory by updating your .htaccess file. Step-by-step instructions and tips.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base - bodHOST\" \/>\n<meta property=\"article:published_time\" content=\"2006-11-28T10:20:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-26T14:04:58+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/execute-cgi-outside-cgi-bin\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/execute-cgi-outside-cgi-bin\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/c48414ad1536cea20e85282b0737a9f9\"},\"headline\":\"Execute CGI outside CGI-bin\",\"datePublished\":\"2006-11-28T10:20:11+00:00\",\"dateModified\":\"2026-02-26T14:04:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/execute-cgi-outside-cgi-bin\\\/\"},\"wordCount\":297,\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"keywords\":[\"CGI\"],\"articleSection\":[\"General Discussion\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/execute-cgi-outside-cgi-bin\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/execute-cgi-outside-cgi-bin\\\/\",\"name\":\"Executing CGI Outside the CGI-bin | Step-by-Step Guide\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\"},\"datePublished\":\"2006-11-28T10:20:11+00:00\",\"dateModified\":\"2026-02-26T14:04:58+00:00\",\"description\":\"Learn how to execute CGI scripts outside the default cgi-bin directory by updating your .htaccess file. Step-by-step instructions and tips.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/execute-cgi-outside-cgi-bin\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/execute-cgi-outside-cgi-bin\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/execute-cgi-outside-cgi-bin\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"General Discussion\",\"item\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/category\\\/general\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Execute CGI outside CGI-bin\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/\",\"name\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"alternateName\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\",\"name\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/Profile-Pic.png\",\"contentUrl\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/Profile-Pic.png\",\"width\":240,\"height\":240,\"caption\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/c48414ad1536cea20e85282b0737a9f9\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/51e53199212db3f59606920448d45a6ead224f904558e3ab9251d071a609b202?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/51e53199212db3f59606920448d45a6ead224f904558e3ab9251d071a609b202?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/51e53199212db3f59606920448d45a6ead224f904558e3ab9251d071a609b202?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Executing CGI Outside the CGI-bin | Step-by-Step Guide","description":"Learn how to execute CGI scripts outside the default cgi-bin directory by updating your .htaccess file. Step-by-step instructions and tips.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/","og_locale":"en_US","og_type":"article","og_title":"Executing CGI Outside the CGI-bin | Step-by-Step Guide","og_description":"Learn how to execute CGI scripts outside the default cgi-bin directory by updating your .htaccess file. Step-by-step instructions and tips.","og_url":"https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/","og_site_name":"Knowledge Base - bodHOST","article_published_time":"2006-11-28T10:20:11+00:00","article_modified_time":"2026-02-26T14:04:58+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/#article","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/"},"author":{"name":"admin","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/c48414ad1536cea20e85282b0737a9f9"},"headline":"Execute CGI outside CGI-bin","datePublished":"2006-11-28T10:20:11+00:00","dateModified":"2026-02-26T14:04:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/"},"wordCount":297,"publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"keywords":["CGI"],"articleSection":["General Discussion"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/","url":"https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/","name":"Executing CGI Outside the CGI-bin | Step-by-Step Guide","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/#website"},"datePublished":"2006-11-28T10:20:11+00:00","dateModified":"2026-02-26T14:04:58+00:00","description":"Learn how to execute CGI scripts outside the default cgi-bin directory by updating your .htaccess file. Step-by-step instructions and tips.","breadcrumb":{"@id":"https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.bodhost.com\/kb\/execute-cgi-outside-cgi-bin\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"General Discussion","item":"https:\/\/www.bodhost.com\/kb\/category\/general\/"},{"@type":"ListItem","position":2,"name":"Execute CGI outside CGI-bin"}]},{"@type":"WebSite","@id":"https:\/\/www.bodhost.com\/kb\/#website","url":"https:\/\/www.bodhost.com\/kb\/","name":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","description":"","publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"alternateName":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.bodhost.com\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.bodhost.com\/kb\/#organization","name":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","url":"https:\/\/www.bodhost.com\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2025\/10\/Profile-Pic.png","contentUrl":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2025\/10\/Profile-Pic.png","width":240,"height":240,"caption":"Web Hosting Knowledge Base | bodHOST Hosting FAQ"},"image":{"@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/c48414ad1536cea20e85282b0737a9f9","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/51e53199212db3f59606920448d45a6ead224f904558e3ab9251d071a609b202?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/51e53199212db3f59606920448d45a6ead224f904558e3ab9251d071a609b202?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/51e53199212db3f59606920448d45a6ead224f904558e3ab9251d071a609b202?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/www.bodhost.com\/kb\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/comments?post=170"}],"version-history":[{"count":9,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":14611,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/170\/revisions\/14611"}],"wp:attachment":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/tags?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}