{"id":11386,"date":"2025-04-29T12:23:47","date_gmt":"2025-04-29T06:38:47","guid":{"rendered":"https:\/\/nestnepal.com\/blog\/?p=11386"},"modified":"2025-05-23T14:18:48","modified_gmt":"2025-05-23T08:33:48","slug":"change-php-version-using-htaccess-in-cpanel","status":"publish","type":"post","link":"https:\/\/nestnepal.com\/blog\/change-php-version-using-htaccess-in-cpanel\/","title":{"rendered":"Master Changing PHP Version Using .htaccess in cPanel (No Server Access Needed)"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Keeping your website running smoothly means staying updated \u2014 and that includes your PHP version. If you\u2019re looking for a simple and flexible way to change the <a href=\"https:\/\/www.php.net\/supported-versions.php\" target=\"_blank\" rel=\"noopener\">PHP version<\/a> for a specific site or directory without affecting the entire server, you can easily do it through the `.htaccess` file right from your <a href=\"https:\/\/nestnepal.com\/wordpress-hosting-in-nepal\/\">cPanel<\/a>.\u00a0\u00a0<\/span><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-11397 size-full lazyload\" data-src=\"https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/htaccess.webp\" alt=\".htaccess\" width=\"860\" height=\"430\" data-srcset=\"https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/htaccess.webp 860w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/htaccess-300x150.webp 300w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/htaccess-768x384.webp 768w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/htaccess-380x190.webp 380w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/htaccess-550x275.webp 550w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/htaccess-800x400.webp 800w\" data-sizes=\"(max-width: 860px) 100vw, 860px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 860px; --smush-placeholder-aspect-ratio: 860\/430;\" \/><\/p>\n<p><span style=\"font-weight: 400;\">In this guide, we\u2019ll walk you through everything step-by-step \u2014 no guesswork needed!<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">What is the .htaccess File?<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The `.htaccess` file (short for &#8220;hypertext access&#8221;) is a powerful configuration file used to control various server settings on a per-directory basis.\u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">It allows you to manage redirects, enable or disable features, improve security, and \u2014 in this case \u2014 set a custom PHP version for your site, without needing root access to the server.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&gt; <\/span><b>Note:<\/b><span style=\"font-weight: 400;\"> Any changes made in the `.htaccess` file will only apply to the directory where the file is located and its subdirectories.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">\u00a0Things to Check Before You Start<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Before you proceed, make sure:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">You know what PHP versions are available on your hosting server (this info is usually in your cPanel or can be confirmed with your hosting provider).<\/span><\/li>\n<li><span style=\"font-weight: 400;\">The PHP version is <\/span><b>not already being forced<\/b><span style=\"font-weight: 400;\"> by cPanel\u2019s <\/span><b>MultiPHP Manager<\/b><span style=\"font-weight: 400;\"> or <\/span><a href=\"https:\/\/nestnepal.com\/blog\/changing-php-version-via-php-selector-in-cpanel\/\"><b>PHP Selecto<\/b><\/a><span style=\"font-weight: 400;\">r. Otherwise, the `.htaccess` method might not override it correctly.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">If PHP is controlled by MultiPHP Manager or PHP Selector, you&#8217;ll need to adjust it from there instead.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">How to Change PHP Version Using .htaccess in cPanel (Step-by-Step)<\/span><\/h2>\n<h3><span style=\"font-weight: 400;\">\u00a01. Log in to your cPanel<\/span><\/h3>\n<ul>\n<li><span style=\"font-weight: 400;\">Visit yourdomain.com\/cpanel (or yourdomain.com:2083).<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Enter your username and password provided by your hosting provider.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">\u00a02. Open File Manager<\/span><\/h3>\n<ul>\n<li><span style=\"font-weight: 400;\">Inside cPanel, search for <\/span><b>File Manager<\/b><span style=\"font-weight: 400;\"> and open it.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">This tool allows you to view and manage all the files and folders of your website.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">\u00a03. Navigate to Your Website&#8217;s Root Directory<\/span><\/h3>\n<ul>\n<li><span style=\"font-weight: 400;\">Usually, your primary website\u2019s files are located under <\/span><b>public_html<\/b><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">If you want to change the PHP version for a specific addon domain or subdomain, navigate to that domain\u2019s folder instead.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">\u00a04. Show Hidden Files<\/span><\/h3>\n<ul>\n<li><span style=\"font-weight: 400;\">In File Manager, click <\/span><b>Settings<\/b><span style=\"font-weight: 400;\"> (top-right corner).<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Make sure to <\/span><b>check the option &#8220;Show Hidden Files (dotfiles)&#8221;<\/b><span style=\"font-weight: 400;\"> \u2014 this will make the `.htaccess` file visible.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">-&gt;If you don\u2019t see an `.htaccess` file, you can <\/span><b>create one<\/b><span style=\"font-weight: 400;\">:\u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">-&gt;Click <\/span><b>+ File<\/b><span style=\"font-weight: 400;\"> \u2192 name it `.htaccess` \u2192 Create.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">\u00a05. Edit the .htaccess File<\/span><\/h3>\n<ul>\n<li><span style=\"font-weight: 400;\">Right-click the `.htaccess` file and select <\/span><b>Edit<\/b><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Confirm the encoding if prompted.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Now, you\u2019re ready to add the PHP version code!<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">\u00a06. Add the PHP Version Handler<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Depending on which PHP version you want, add one of the following blocks of code into your `.htaccess` file:<\/span><\/p>\n<p><em><span style=\"font-weight: 400;\">&#8220;`apache<\/span><\/em><\/p>\n<p><em><span style=\"font-weight: 400;\"># Example for PHP 8.1<\/span><\/em><\/p>\n<p><em><span style=\"font-weight: 400;\">&lt;IfModule mime_module&gt;<\/span><\/em><\/p>\n<p><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0AddHandler application\/x-httpd-alt-php81 .php .php5 .phtml<\/span><\/em><\/p>\n<p><em><span style=\"font-weight: 400;\">&lt;\/IfModule&gt;<\/span><\/em><\/p>\n<p><em><span style=\"font-weight: 400;\">&#8220;`<\/span><\/em><\/p>\n<h3><span style=\"font-weight: 400;\">List of PHP Versions<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Here\u2019s the correct snippet for each version:<\/span><\/p>\n<p><img decoding=\"async\" class=\"wp-image-11399 alignleft lazyload\" data-src=\"https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/php-version-1.webp\" alt=\"php-version\" width=\"578\" height=\"302\" data-srcset=\"https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/php-version-1.webp 860w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/php-version-1-300x157.webp 300w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/php-version-1-768x402.webp 768w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/php-version-1-380x199.webp 380w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/php-version-1-550x288.webp 550w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/04\/php-version-1-800x419.webp 800w\" data-sizes=\"(max-width: 578px) 100vw, 578px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 578px; --smush-placeholder-aspect-ratio: 578\/302;\" \/><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>PHP Version<\/b><\/td>\n<td><b>Snippet<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PHP 5.4<\/span><\/td>\n<td><span style=\"font-weight: 400;\">application\/x-httpd-alt-php54<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PHP 5.5<\/span><\/td>\n<td><span style=\"font-weight: 400;\">application\/x-httpd-alt-php55<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PHP 5.6<\/span><\/td>\n<td><span style=\"font-weight: 400;\">application\/x-httpd-alt-php56<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PHP 7.0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">application\/x-httpd-alt-php70<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PHP 7.1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">application\/x-httpd-alt-php71<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PHP 7.2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">application\/x-httpd-alt-php72<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PHP 7.3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">application\/x-httpd-alt-php73<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PHP 7.4<\/span><\/td>\n<td><span style=\"font-weight: 400;\">application\/x-httpd-alt-php74<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PHP 8.0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">application\/x-httpd-alt-php80<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PHP 8.1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">application\/x-httpd-alt-php81<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PHP 8.2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">application\/x-httpd-alt-php82<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PHP 8.3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">application\/x-httpd-alt-php83<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Simply adjust the version number according to the PHP version you need.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">\u00a07. Save Your Changes<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">&#8211; After adding the code snippet, <\/span><b>save<\/b><span style=\"font-weight: 400;\"> the `.htaccess` file.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Close the editor.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">How to Verify the PHP Version Change<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">To double-check that the PHP version was successfully updated:<\/span><\/p>\n<ol>\n<li><b>Create a new file<\/b><span style=\"font-weight: 400;\"> (e.g., `info.php`) in your site&#8217;s root directory.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> Add this simple code:<\/span><\/li>\n<\/ol>\n<p><em><span style=\"font-weight: 400;\">&#8220;`php<\/span><\/em><\/p>\n<p><em><span style=\"font-weight: 400;\">&lt;?php phpinfo(); ?&gt;<\/span><\/em><\/p>\n<p><em><span style=\"font-weight: 400;\">&#8220;`<\/span><\/em><\/p>\n<ol start=\"3\">\n<li><span style=\"font-weight: 400;\"> Save it, and then visit `yourdomain.com\/info.php` in your browser.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">You\u2019ll see a detailed PHP configuration page showing the <\/span><b>current PHP version<\/b><span style=\"font-weight: 400;\"> running for that directory.<\/span><\/p>\n<ul>\n<li><b>Important:<\/b><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">&gt; Don\u2019t forget to delete the `info.php` file afterward to avoid exposing sensitive server information publicly.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">\u00a0Important Notes and Considerations<\/span><\/h2>\n<ul>\n<li><b>Directory Scope:<\/b><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0PHP changes via `.htaccess` <\/span><b>only apply to the directory where the `.htaccess` file is located<\/b><span style=\"font-weight: 400;\">, not globally across the server.<\/span><\/p>\n<ul>\n<li><b>Hosting Restrictions:<\/b><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0Some hosting providers may disable the ability to manually set PHP handlers via `.htaccess`. Always check with your host if you face issues.<\/span><\/p>\n<ul>\n<li><b>Compatibility Checks:<\/b><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0After changing the PHP version, <\/span><b>test your entire website<\/b><span style=\"font-weight: 400;\"> (especially forms, plugins, custom scripts) to make sure everything works.\u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0Some older plugins, CMS systems, or themes might not be compatible with newer PHP versions.<\/span><\/p>\n<ul>\n<li><b>Regular Updates:<\/b><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0Keeping your PHP version updated is essential for:<\/span><\/p>\n<ol>\n<li><b>Security<\/b><span style=\"font-weight: 400;\"> improvements<\/span><\/li>\n<li><b>Performance<\/b><span style=\"font-weight: 400;\"> boosts<\/span><\/li>\n<li><b>Access to new features<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0But always check compatibility before upgrading!<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">FAQs:<\/span><\/h2>\n<h3>1. Can I change the PHP version for just one folder using .htaccess?<\/h3>\n<p>Yes! When you set a PHP version via the .htaccess file, the change applies only to the folder where the file is located and its subdirectories. This lets you run different PHP versions on different parts of your website.<\/p>\n<h3>2. What happens if my hosting provider doesn\u2019t allow PHP changes through .htaccess?<\/h3>\n<p>If your hosting provider restricts PHP version changes via .htaccess, you\u2019ll need to update the PHP version using cPanel\u2019s MultiPHP Manager or PHP Selector instead. Always check your hosting settings or ask your provider for support.<\/p>\n<h3>3. How do I know which PHP versions are available on my server?<\/h3>\n<p>You can usually find the available PHP versions inside your cPanel under &#8220;Select PHP Version&#8221; or &#8220;MultiPHP Manager.&#8221; Alternatively, contact your hosting provider or check their documentation.<\/p>\n<h3>4. Will changing the PHP version via .htaccess affect my entire server?<\/h3>\n<p>No. Updating PHP through .htaccess only affects the directory where the .htaccess file is placed (and its subfolders). It will not impact other websites or directories on the same hosting account.<\/p>\n<h3>5. Is it safe to update my PHP version through .htaccess?<\/h3>\n<p>Yes, it\u2019s generally safe. However, before making changes, always back up your website and test compatibility, especially if you\u2019re running older themes, CMS platforms, or plugins that may not support newer PHP versions.<\/p>\n<h3>6. Why isn&#8217;t my new PHP version showing after updating .htaccess?<\/h3>\n<p>If the new PHP version isn&#8217;t taking effect, it might be overridden by cPanel\u2019s MultiPHP Manager or PHP Selector settings. Check those settings first, or clear your server and browser cache.<\/p>\n<h3>7. What should I do if my site breaks after changing the PHP version?<\/h3>\n<p>If your site experiences errors after switching PHP versions, revert to the previous version in your .htaccess file or through cPanel. Then, troubleshoot plugins, themes, or custom code for compatibility issues.<\/p>\n<h3>8. How often should I update my PHP version?<\/h3>\n<p>You should update your PHP version whenever a newer stable version is available and your website is compatible. Staying updated improves security, speed, and overall performance.<\/p>\n<h2><span style=\"font-weight: 400;\">Conclusion<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Changing your PHP version using the `.htaccess` file gives you more fine-tuned control over your website environment \u2014 and it\u2019s a fairly easy process once you know the steps.\u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">By staying on top of PHP updates, you ensure your site stays fast, secure, and ready for whatever\u2019s next.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Keep exploring, keep improving, and as always \u2014 <\/span><b>happy coding!<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Keeping your website running smoothly means staying updated \u2014 and that includes your PHP version. If you\u2019re looking for a&#8230;<\/p>\n","protected":false},"author":15,"featured_media":11919,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[369,205,112],"tags":[117],"class_list":["post-11386","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cms","category-control-panel","category-wordpress-hosting","tag-cpanel"],"_links":{"self":[{"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/posts\/11386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/comments?post=11386"}],"version-history":[{"count":4,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/posts\/11386\/revisions"}],"predecessor-version":[{"id":11400,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/posts\/11386\/revisions\/11400"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/media\/11919"}],"wp:attachment":[{"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/media?parent=11386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/categories?post=11386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/tags?post=11386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}