<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: sirimhrzn</title>
    <description>The latest articles on DEV Community by sirimhrzn (@sirimhrzn).</description>
    <link>https://dev.to/sirimhrzn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1134760%2F9dd2ed21-d4de-4190-b86a-ad8e5485d948.jpg</url>
      <title>DEV Community: sirimhrzn</title>
      <link>https://dev.to/sirimhrzn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sirimhrzn"/>
    <language>en</language>
    <item>
      <title>PHP: Installing,Switching between Multiple PHP versions on Linux</title>
      <dc:creator>sirimhrzn</dc:creator>
      <pubDate>Mon, 07 Aug 2023 15:36:56 +0000</pubDate>
      <link>https://dev.to/sirimhrzn/php-installingswitching-between-multiple-php-versions-on-linux-4h85</link>
      <guid>https://dev.to/sirimhrzn/php-installingswitching-between-multiple-php-versions-on-linux-4h85</guid>
      <description>&lt;p&gt;As a beginner working in production, you will be facing many problems that you were unaware of while you were doing personal projects, one of them being having to deal with older projects which used an older version of PHP but also work with latest PHP version at the same time. It is not just PHP but happens with every programming language so I decided to write this article for those who are starting out and have this problem.&lt;br&gt;
The most easiest way would be running it on docker but that is not the topic for now , so let's begin.&lt;/p&gt;

&lt;p&gt;This tutorial uses Ubuntu but &lt;strong&gt;it works on any other distro.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Installing multiple version
&lt;/h2&gt;

&lt;p&gt;On Ubuntu LTS you need to add ondrej repository to install older versions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo add-apt-repository ppa:ondrej/php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this example i'll be installing php7.3&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install php7.3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't specify PHP version then, the latest version of PHP will be installed from the Ubuntu default repository&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now on terminal , if you check your PHP version, by default it will be from Ubuntu's default repository&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php -v
PHP 8.2.8 (cli) (built: Jul  8 2023 07:10:21) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.8, Copyright (c), by Zend Technologies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to use older PHP version we will create a symbolic link, so lets move the default PHP version into a folder with it's version name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mv /usr/bin/php /usr/bin/php8.2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if you try to use &lt;code&gt;php -v&lt;/code&gt; , it won't work because now it has been changed to &lt;code&gt;php8.2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To use older version as PHP command, you will now create a symbolic link, which calls your desired PHP version when &lt;code&gt;php&lt;/code&gt; is called.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ln -s /usr/bin/php7.3 /usr/bin/php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if you try &lt;code&gt;php -v&lt;/code&gt; , the version of PHP which you specified when creating symbolic link should run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php -v
PHP 7.3.33-11+ubuntu22.04.1+deb.sury.org+1 (cli) (built: Jun  8 2023 15:22:14) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.33, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.33-11+ubuntu22.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to switch back to any other php version you have to unlink to in order to create another symbolic link,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo unlink /usr/bin/php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And just repeat the linking and unlinking to switch and forth between multiple versions of PHP&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ln -s /usr/bin/php8.2 /usr/bin/php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you for making it up to here , please feel free to share your thoughts and problems&lt;/p&gt;

</description>
      <category>backend</category>
      <category>php</category>
      <category>laravel</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
