How to Change PHP Version in Ubuntu Server?

Posted by

Introduction

Hey there! Are you struggling with changing the PHP version on your Ubuntu server? Don’t worry, I’ve got you covered! In this blog post, I’m going to walk you through the step-by-step process of changing the PHP version on your Ubuntu server, and I’ll even provide live examples to make it easier for you. So, let’s dive right in!

Why Change PHP Version?

Before we get into the nitty-gritty of changing the PHP version, let’s quickly discuss why you might want to do this. Upgrading or downgrading your PHP version can be necessary for various reasons:

  1. Compatibility: Some applications or frameworks require specific PHP versions to function properly. Changing the PHP version allows you to make sure your applications are compatible.
  2. Performance: Newer PHP versions often come with performance improvements and optimizations. Upgrading your PHP version can help boost the performance of your server and applications.
  3. Security: Older PHP versions may have security vulnerabilities that have been patched in newer versions. By upgrading to a newer PHP version, you can ensure the security of your server and applications.

Now that you understand the importance of changing the PHP version, let’s get into the steps!

Method 1: Change PHP Version

Change php version by following command:

sudo update-alternatives --config php

you have to choose from the list below:

let’s restart server:

sudo service apache2 restart

Method 2: Change PHP Version

you need to a2dismod old version and a2enmod new php version so let’s run following command:

sudo a2dismod php7.3
sudo a2enmod php7.4

let’s restart server:

sudo service apache2 restart

Method 3: Change PHP Version

You can direct change php version by following command:

sudo update-alternatives --set php /usr/bin/php7.4

restart server:

sudo service apache2 restart

I hope it will help you ..!!!

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x