{"id":13325,"date":"2023-11-01T16:36:11","date_gmt":"2023-11-01T20:36:11","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=13325"},"modified":"2023-11-01T16:36:14","modified_gmt":"2023-11-01T20:36:14","slug":"how-to-change-php-version-in-ubuntu-22-04","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/","title":{"rendered":"How to Change PHP Version in Ubuntu 22.04"},"content":{"rendered":"\n

Ubuntu 22.04, the latest LTS (Long Term Support) release, brings several enhancements and updates to the world of Linux. If you’re a web developer or server administrator, you might need to work with different versions of PHP<\/a> for various projects. Fortunately, Ubuntu 22.04 makes it relatively easy to change the PHP version on your system. In this step-by-step guide, we’ll walk you through the process of changing the PHP version on your Ubuntu 22.04<\/a> system.<\/p>\n\n\n\n

1. Check the Current PHP Version<\/h2>\n\n\n\n

Before you change the PHP version, it’s essential to verify which version is currently installed on your system. Open your terminal and run the following command:<\/p>\n\n\n\n

$ php -v<\/code><\/pre>\n\n\n\n

This command will display information about your current PHP version.<\/p>\n\n\n\n

2. Add a PPA (Personal Package Archive)<\/h2>\n\n\n\n

To easily switch between PHP versions, we’ll use a PPA that provides different PHP versions. We’ll use the well-maintained ondrej\/php<\/code> PPA for this purpose. Open your terminal and run the following commands to add the PPA to your system:<\/p>\n\n\n\n

$ sudo add-apt-repository ppa:ondrej\/php<\/code><\/pre>\n\n\n\n

You’ll need to confirm the addition of the repository. After adding the PPA, update your package list:<\/p>\n\n\n\n

$ sudo apt update<\/code><\/pre>\n\n\n\n

3. Install the Desired PHP Version<\/h2>\n\n\n\n

Now that you’ve added the PPA, you can install the PHP version of your choice. You can install PHP 7.2, 7.4, 8.0, or any other available version. Use the following command to install a specific PHP version. Replace x.x<\/code> with the desired PHP version, e.g., 7.2, 7.4, or 8.0:<\/p>\n\n\n\n

$ sudo apt install phpX.X<\/code><\/pre>\n\n\n\n

For example, to install PHP 7.4, you would run:<\/p>\n\n\n\n

$ sudo apt install php7.4<\/code><\/pre>\n\n\n\n

4. Switch Between PHP Versions<\/h2>\n\n\n\n

Ubuntu 22.04 provides a handy tool called update-alternatives<\/code> to switch between different PHP versions. You can configure the default PHP version and choose which one you want to use.<\/p>\n\n\n\n

Use the following command to set the default PHP version to the one you just installed (replace x.x<\/code> with the PHP version you installed):<\/p>\n\n\n\n

$ sudo update-alternatives --set php \/usr\/bin\/phpX.X<\/code><\/pre>\n\n\n\n

For example, if you installed PHP 7.4, you would run:<\/p>\n\n\n\n

$ sudo update-alternatives --set php \/usr\/bin\/php7.4<\/code><\/pre>\n\n\n\n

5. Verify the PHP Version<\/h2>\n\n\n\n

After changing the default PHP version, verify that the switch was successful. Run the php -v<\/code> command once again:<\/p>\n\n\n\n

$ php -v<\/code><\/pre>\n\n\n\n

You should now see the updated PHP version displayed in your terminal.<\/p>\n\n\n\n

6. Configure PHP Extensions<\/h2>\n\n\n\n

When you switch PHP versions, keep in mind that you might need to reinstall or configure PHP extensions for the specific version you’re using. Extensions are not always compatible between different PHP versions, so make sure to install and enable the necessary extensions for your projects.<\/p>\n\n\n\n

Conclusion<\/h2>\n\n\n\n

Changing the PHP version on Ubuntu 22.04 is a straightforward process, thanks to the ondrej\/php<\/code> PPA. Whether you’re developing web applications or hosting websites on your server, having the flexibility to work with different PHP versions is a valuable tool in your toolkit. By following the steps outlined in this guide, you can seamlessly switch between PHP versions, ensuring that your projects run smoothly and efficiently.<\/p>\n","protected":false},"excerpt":{"rendered":"

Ubuntu 22.04, the latest LTS (Long Term Support) release, brings several enhancements and updates to the world of Linux. If you’re a web developer or server administrator, you might need…<\/p>\n","protected":false},"author":1,"featured_media":13381,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,16],"tags":[354,424,433,449,452,526,531,591,598],"yoast_head":"\nHow to Change PHP Version in Ubuntu 22.04 Linux Systems<\/title>\n<meta name=\"description\" content=\"This guide shows how you can safely change PHP version in Ubuntu 22.04 or related Debian based Linux systems\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Change PHP Version in Ubuntu 22.04 Linux Systems\" \/>\n<meta property=\"og:description\" content=\"This guide shows how you can safely change PHP version in Ubuntu 22.04 or related Debian based Linux systems\" \/>\n<meta property=\"og:url\" content=\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/\" \/>\n<meta property=\"og:site_name\" content=\"Brightwhiz.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/brightwhiz\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-01T20:36:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-01T20:36:14+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2023\/10\/Change-PHP-Version-Ubuntu-22.04.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Bright\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:site\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Bright\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/\"},\"author\":{\"name\":\"Michael Bright\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\"},\"headline\":\"How to Change PHP Version in Ubuntu 22.04\",\"datePublished\":\"2023-11-01T20:36:11+00:00\",\"dateModified\":\"2023-11-01T20:36:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/\"},\"wordCount\":456,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2023\/10\/Change-PHP-Version-Ubuntu-22.04.jpg\",\"keywords\":[\"Linux\",\"Open Source\",\"Optimization\",\"Performance\",\"PHP\",\"Security\",\"Server\",\"Tools\",\"Ubuntu\"],\"articleSection\":[\"Articles\",\"Guides\",\"How To\",\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/\",\"url\":\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/\",\"name\":\"How to Change PHP Version in Ubuntu 22.04 Linux Systems\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2023\/10\/Change-PHP-Version-Ubuntu-22.04.jpg\",\"datePublished\":\"2023-11-01T20:36:11+00:00\",\"dateModified\":\"2023-11-01T20:36:14+00:00\",\"description\":\"This guide shows how you can safely change PHP version in Ubuntu 22.04 or related Debian based Linux systems\",\"breadcrumb\":{\"@id\":\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#primaryimage\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2023\/10\/Change-PHP-Version-Ubuntu-22.04.jpg\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2023\/10\/Change-PHP-Version-Ubuntu-22.04.jpg\",\"width\":1280,\"height\":680,\"caption\":\"Change PHP Version Ubuntu 22.04\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/local.brightwhiz\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Change PHP Version in Ubuntu 22.04\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/local.brightwhiz\/#website\",\"url\":\"http:\/\/local.brightwhiz\/\",\"name\":\"Brightwhiz.com\",\"description\":\"Best Tech guides, Tutorials, and News\",\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/local.brightwhiz\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/local.brightwhiz\/#organization\",\"name\":\"Brightwhiz\",\"url\":\"http:\/\/local.brightwhiz\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"width\":706,\"height\":135,\"caption\":\"Brightwhiz\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/brightwhiz\/\",\"https:\/\/x.com\/brightwhizmag\",\"https:\/\/instagram.com\/bright_whiz\/\",\"https:\/\/www.pinterest.com\/sobbayi\/\",\"https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\",\"name\":\"Michael Bright\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"caption\":\"Michael Bright\"},\"sameAs\":[\"https:\/\/sobbayi.com\"],\"url\":\"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Change PHP Version in Ubuntu 22.04 Linux Systems","description":"This guide shows how you can safely change PHP version in Ubuntu 22.04 or related Debian based Linux systems","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":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/","og_locale":"en_US","og_type":"article","og_title":"How to Change PHP Version in Ubuntu 22.04 Linux Systems","og_description":"This guide shows how you can safely change PHP version in Ubuntu 22.04 or related Debian based Linux systems","og_url":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/","og_site_name":"Brightwhiz.com","article_publisher":"https:\/\/www.facebook.com\/brightwhiz\/","article_published_time":"2023-11-01T20:36:11+00:00","article_modified_time":"2023-11-01T20:36:14+00:00","og_image":[{"width":1280,"height":680,"url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2023\/10\/Change-PHP-Version-Ubuntu-22.04.jpg","type":"image\/jpeg"}],"author":"Michael Bright","twitter_card":"summary_large_image","twitter_creator":"@brightwhizmag","twitter_site":"@brightwhizmag","twitter_misc":{"Written by":"Michael Bright","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#article","isPartOf":{"@id":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/"},"author":{"name":"Michael Bright","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32"},"headline":"How to Change PHP Version in Ubuntu 22.04","datePublished":"2023-11-01T20:36:11+00:00","dateModified":"2023-11-01T20:36:14+00:00","mainEntityOfPage":{"@id":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/"},"wordCount":456,"commentCount":0,"publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"image":{"@id":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2023\/10\/Change-PHP-Version-Ubuntu-22.04.jpg","keywords":["Linux","Open Source","Optimization","Performance","PHP","Security","Server","Tools","Ubuntu"],"articleSection":["Articles","Guides","How To","Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#respond"]}]},{"@type":"WebPage","@id":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/","url":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/","name":"How to Change PHP Version in Ubuntu 22.04 Linux Systems","isPartOf":{"@id":"http:\/\/local.brightwhiz\/#website"},"primaryImageOfPage":{"@id":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#primaryimage"},"image":{"@id":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2023\/10\/Change-PHP-Version-Ubuntu-22.04.jpg","datePublished":"2023-11-01T20:36:11+00:00","dateModified":"2023-11-01T20:36:14+00:00","description":"This guide shows how you can safely change PHP version in Ubuntu 22.04 or related Debian based Linux systems","breadcrumb":{"@id":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#primaryimage","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2023\/10\/Change-PHP-Version-Ubuntu-22.04.jpg","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2023\/10\/Change-PHP-Version-Ubuntu-22.04.jpg","width":1280,"height":680,"caption":"Change PHP Version Ubuntu 22.04"},{"@type":"BreadcrumbList","@id":"http:\/\/local.brightwhiz\/how-to-change-php-version-in-ubuntu-22-04\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/local.brightwhiz\/"},{"@type":"ListItem","position":2,"name":"How to Change PHP Version in Ubuntu 22.04"}]},{"@type":"WebSite","@id":"http:\/\/local.brightwhiz\/#website","url":"http:\/\/local.brightwhiz\/","name":"Brightwhiz.com","description":"Best Tech guides, Tutorials, and News","publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/local.brightwhiz\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/local.brightwhiz\/#organization","name":"Brightwhiz","url":"http:\/\/local.brightwhiz\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","width":706,"height":135,"caption":"Brightwhiz"},"image":{"@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/brightwhiz\/","https:\/\/x.com\/brightwhizmag","https:\/\/instagram.com\/bright_whiz\/","https:\/\/www.pinterest.com\/sobbayi\/","https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ"]},{"@type":"Person","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32","name":"Michael Bright","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","caption":"Michael Bright"},"sameAs":["https:\/\/sobbayi.com"],"url":"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/"}]}},"_links":{"self":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/13325"}],"collection":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/comments?post=13325"}],"version-history":[{"count":0,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/13325\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media\/13381"}],"wp:attachment":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media?parent=13325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/categories?post=13325"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/tags?post=13325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}