{"id":8658,"date":"2025-05-13T21:51:55","date_gmt":"2025-05-13T16:21:55","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=8658"},"modified":"2026-11-03T13:03:29","modified_gmt":"2026-11-03T07:33:29","slug":"managing-multiple-php-versions-on-ubuntu-using-apt","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/managing-multiple-php-versions-on-ubuntu-using-apt\/","title":{"rendered":"Managing Multiple PHP Versions on Ubuntu Using APT"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Post Date:<\/strong> May 13, 2025<br><strong>Last Updated:<\/strong> November 02, 2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Managing <strong>multiple PHP versions on Ubuntu<\/strong> is essential for developers and system administrators who work with applications that require different PHP versions. Ubuntu allows you to install PHP packages through APT and switch the default command-line PHP version using the <code>update-alternatives<\/code> command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we will explain how to check available PHP packages, install multiple PHP versions, identify the active version, and switch between them. For additional information about PHP releases and supported versions, refer to the official <a href=\"https:\/\/www.php.net\/supported-versions.php\" target=\"_blank\" rel=\"noopener\">PHP documentation<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this implementation, we will configure multiple PHP versions on Ubuntu using the APT package manager. We will install the required PHP versions, check the versions available on the system, and use <code>update-alternatives<\/code> to switch the default PHP CLI version. Finally, we will verify the active version using the <code>php -v<\/code> command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Managing multiple PHP versions on Ubuntu allows developers to maintain applications with different PHP requirements on the same server. Instead of removing an existing PHP installation, you can install another supported version and select the required PHP CLI version for your development tasks. This approach is useful when testing application compatibility, maintaining legacy projects, or preparing applications for PHP upgrades.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/05\/Managing-Multiple-PHP-Versions-on-Ubuntu.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/05\/Managing-Multiple-PHP-Versions-on-Ubuntu-1024x683.png\" alt=\"\" class=\"wp-image-12777\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/05\/Managing-Multiple-PHP-Versions-on-Ubuntu-1024x683.png 1024w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/05\/Managing-Multiple-PHP-Versions-on-Ubuntu-300x200.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/05\/Managing-Multiple-PHP-Versions-on-Ubuntu-768x512.png 768w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/05\/Managing-Multiple-PHP-Versions-on-Ubuntu-272x182.png 272w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/05\/Managing-Multiple-PHP-Versions-on-Ubuntu.png 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">1. Listing Available PHP Versions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To check the PHP versions available in your configured APT repositories, run:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt update\napt-cache search '^php[0-9]\\.[0-9]$'<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command searches for PHP version-specific packages available through APT. The available versions depend on your Ubuntu release and configured repositories.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the required version is available, you can install it using:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install php8.3 php8.3-cli -y<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>8.3<\/code> with the PHP version you want to install. You can install multiple PHP versions by specifying their package names.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install php8.2 php8.2-cli php8.3 php8.3-cli -y<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Listing PHP Versions Configured with Update Alternatives<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When multiple PHP versions are installed, you can check which versions are registered with the update-alternatives system by running:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo update-alternatives --list php<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command displays the PHP executable paths available for selection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If a PHP version is installed but not registered with update-alternatives, you can configure it manually using:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo update-alternatives --install \/usr\/bin\/php php \/usr\/bin\/php8.3 83<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>8.3<\/code> with the installed PHP version. The priority value <code>83<\/code> is an example; you can assign an appropriate priority when registering the alternative.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After registering it, run the following command to select the required version:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo update-alternatives --config php<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Managing multiple PHP versions on Ubuntu this way makes it easier to test applications with different PHP CLI environments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Checking Installed PHP Versions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If multiple PHP versions are already installed, you can check the PHP alternatives configuration by running:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo update-alternatives --display php<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command displays the configured PHP alternatives, including the current selection and available executable paths.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example Output<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">[Insert the existing example output image here]<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Switching Between PHP Versions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To change the active PHP CLI version, use the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo update-alternatives --config php<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The command displays the available PHP versions registered with update-alternatives. Select the number corresponding to the version you want to use.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alternatively, you can directly set a specific version using:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo update-alternatives --set php \/usr\/bin\/php8.3<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command sets PHP 8.3 as the default PHP CLI version, provided that the executable is installed and registered with update-alternatives.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. Verifying the Active PHP Version<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After switching PHP versions, confirm the currently active PHP CLI version by running:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php -v<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command displays the PHP version currently selected for command-line operations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also verify the executable path using:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">which php<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The output should point to the PHP executable managed through the alternatives configuration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Important Note: PHP CLI and Web Server Versions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>update-alternatives<\/code> command changes the default PHP CLI version. It does not automatically change the PHP version used by Apache or PHP-FPM.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If your application runs through Apache with PHP-FPM or Nginx with PHP-FPM, you must configure the appropriate PHP-FPM service and web server integration separately. Make sure the required PHP extensions are also installed for each version.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, PHP-FPM packages can be installed using:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install php8.2-fpm php8.3-fpm -y<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The correct web server configuration depends on whether you use Apache or Nginx and how PHP is integrated with it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Can I install multiple PHP versions on Ubuntu?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. You can install multiple PHP versions on Ubuntu using APT. Each PHP version can have its own CLI, configuration files, extensions, and PHP-FPM service.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. How do I check all installed PHP versions on Ubuntu?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can list installed PHP packages using:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">dpkg -l | grep -E 'php[0-9]\\.[0-9]'<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. How do I switch between PHP versions in Ubuntu?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use the <code>update-alternatives<\/code> command to change the default PHP CLI version:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo update-alternatives --config php<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Select the PHP version you want to use from the displayed list.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Does switching PHP versions affect Apache and Nginx?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. The <code>update-alternatives<\/code> command changes the default PHP CLI version. Apache and Nginx may use separate PHP modules or PHP-FPM services, which must be configured independently.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. How do I verify the currently active PHP version?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php -v<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It displays the PHP version currently selected for command-line operations.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. How do I install a specific PHP version on Ubuntu?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If the required package is available in your configured APT repositories, install it using:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt update\nsudo apt install php8.3 php8.3-cli -y<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>8.3<\/code> with the PHP version you need and verify package availability for your Ubuntu release.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. How do I check available PHP versions in APT?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following command to search for available PHP packages:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apt-cache search '^php[0-9]\\.[0-9]$'<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The available versions depend on your Ubuntu release and configured package repositories.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Article<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/install-nginx-on-cpanel-using-engintron\/\">Install Nginx on cPanel Using Engintron (Step-by-Step Guide)<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-install-and-configure-php-with-nginx-on-centos7\/\">How to install and configure PHP with Nginx on centos7 \u2013 Pheonix Solutions<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Running multiple PHP projects on one Ubuntu server and struggling with version conflicts? Our team can help you configure your servers, manage PHP environments, and keep your deployments stable with our <a href=\"https:\/\/pheonixsolutions.com\/devops-cloud\/\">DevOps and Cloud Services<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/contact\">Connect with our technology experts.<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: May 13, 2025Last Updated: November 02, 2026 Introduction Managing multiple PHP versions on Ubuntu is essential for developers [&hellip;]<\/p>\n","protected":false},"author":508,"featured_media":12864,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022,1049,1050],"tags":[],"class_list":["post-8658","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-architecture","category-php","category-ubuntu","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-2fE","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/05\/Managing-PHP-Versions-on-Ubuntu.png","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/508"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=8658"}],"version-history":[{"count":3,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8658\/revisions"}],"predecessor-version":[{"id":12865,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8658\/revisions\/12865"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media\/12864"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}