{"id":2145,"date":"2025-06-25T09:24:47","date_gmt":"2025-06-25T09:24:47","guid":{"rendered":"https:\/\/hostrago.com\/knowledge-base\/?p=2145"},"modified":"2025-06-26T07:58:17","modified_gmt":"2025-06-26T07:58:17","slug":"how-to-set-custom-php-version","status":"publish","type":"post","link":"https:\/\/hostrago.com\/knowledge-base\/how-to-set-custom-php-version\/","title":{"rendered":"How To Set Custom PHP Version Per Directory"},"content":{"rendered":"\n<p>In many web hosting environments, especially when using <strong>shared hosting or working with multiple applications<\/strong>, different PHP versions might be required across various parts of a single domain. Fortunately, if you&#8217;re using cPanel, you can How To Set Custom PHP Version Per Directory using <code>.htaccess<\/code>.<\/p>\n\n\n\n<p>This guide will show you how to set a specific PHP version for a folder inside your hosting account, while keeping a different version active for the rest of the domain. This is especially helpful for <strong>legacy PHP projects<\/strong>, or when testing compatibility with newer PHP releases.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps To How To Set Custom PHP Version Per Directory<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Step 1: Log In to Your cPanel<\/h3>\n\n\n\n<p>Open your browser and log in to your <a href=\"https:\/\/cpanel.net\/\" target=\"_blank\" rel=\"noopener\">cPanel <\/a>account via:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Step 2: Open File Manager<\/h3>\n\n\n\n<p>Navigate to <strong>File Manager<\/strong> under the <strong>Files<\/strong> section.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Step 3: Create or Edit the <code>.htaccess<\/code> File<\/h3>\n\n\n\n<p>If it already exists, right-click the file and select <strong>Edit<\/strong>.<\/p>\n\n\n\n<p>If the folder doesn\u2019t have a <code>.htaccess<\/code> file, right-click and choose <strong>Create New File<\/strong>, then name it <code>.htaccess<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"543\" src=\"https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/06\/Using-.htaccess-1024x543.webp\" loading=\"lazy\" alt=\"Using .htaccess\" class=\"wp-image-2148\" srcset=\"https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/06\/Using-.htaccess-1024x543.webp 1024w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/06\/Using-.htaccess-300x159.webp 300w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/06\/Using-.htaccess-768x407.webp 768w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/06\/Using-.htaccess-1536x815.webp 1536w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/06\/Using-.htaccess-2048x1086.webp 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">4. tep 4: Add PHP Version Handler<\/h3>\n\n\n\n<p>Add one of the following lines based on your required PHP version.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"491\" src=\"https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/06\/insert-a-handler-1024x491.webp\" loading=\"lazy\" alt=\"insert a handler\" class=\"wp-image-2147\" srcset=\"https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/06\/insert-a-handler-1024x491.webp 1024w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/06\/insert-a-handler-300x144.webp 300w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/06\/insert-a-handler-768x368.webp 768w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/06\/insert-a-handler-1536x736.webp 1536w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/06\/insert-a-handler-2048x981.webp 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">5. Verify the PHP Version<\/h3>\n\n\n\n<p>To verify the PHP version for that directory:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a <code>phpinfo.php<\/code> file inside the same folder.<\/li>\n\n\n\n<li>Add the following code:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code lang-php\"><code>phpCopyEdit<code>&lt;?php phpinfo(); ?&gt;\n<\/code><\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Open the file in your browser, e.g., <code>yourdomain.com\/old-script\/phpinfo.php<\/code><\/li>\n\n\n\n<li>Look for the \u201cPHP Version\u201d field. It should reflect the version you applied in <code>.htaccess<\/code>.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Important Notes<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This method works <strong>per directory<\/strong> and overrides the default PHP version set via MultiPHP Manager.<\/li>\n\n\n\n<li>Only files within the directory (and its subdirectories) will use the custom version.<\/li>\n\n\n\n<li>If you&#8217;re not sure which handlers are available, contact your host\u2019s support team. If you use <strong><a>Hostrago<\/a><\/strong>, our technical experts can help identify supported versions.<\/li>\n\n\n\n<li>Avoid using outdated versions (e.g., PHP 5.6) in live environments for <strong>security reasons<\/strong>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Final Thoughts<\/h2>\n\n\n\n<p>Setting different PHP versions for individual directories is a powerful way to manage multi-version compatibility, especially when working with older applications or testing development environments. With just a few tweaks to the <code>.htaccess<\/code> file, you can tailor your hosting environment to meet the needs of each application.<\/p>\n\n\n\n<p>If you&#8217;re hosting with <strong><a class=\"\" href=\"https:\/\/hostrago.com\">Hostrago<\/a><\/strong>, our cPanel plans fully support multiple PHP versions, allowing flexible development and deployment. Need help? <a href=\"https:\/\/hostrago.com\/contact-us\">Contact our support team<\/a> or explore our <a href=\"https:\/\/hostrago.com\/knowledge-base\">Knowledge Base<\/a> for more helpful tutorials.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In many web hosting environments, especially when using shared hosting or working with multiple applications, different PHP versions might be required across various parts of&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2146,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[455,329,456,457,185,387],"class_list":["post-2145","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpanel","tag-htaccess-php-config","tag-cpanel-guide","tag-custom-php-version","tag-directory-level-php-setup","tag-hostrago-tutorial","tag-php-handler"],"menu_order":0,"_links":{"self":[{"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/2145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=2145"}],"version-history":[{"count":1,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/2145\/revisions"}],"predecessor-version":[{"id":2150,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/2145\/revisions\/2150"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/media\/2146"}],"wp:attachment":[{"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=2145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=2145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=2145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}