Question

How to update the php to 7.4?

I need to update the PHP of my website to 7.4., nowadays it is 7.2 and don’t support many plugins, like Element. My site is build on Wordpress


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
February 27, 2024

Heya @atelierdelamusique,

I’ll recommend you to have it even above, like at least PHP 8.

Anyway, If you are using an older OS like Ubuntu 20.04 or 22.04 you can try something like this:

Heya @7aa9f68ad93048a792ee1efa1e1566,

Yes, you can install any PHP version you want. Here is a general guide on how to do it: ### 1. Install specific PHP version To install the desired version of PHP. First, you might need to add a repository that contains the older version of PHP, as the default repositories might not have it.

For example, on Ubuntu, you can use the Ondřej Surý PPA, which maintains multiple PHP versions:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

Then, install the desired PHP version, for example, PHP 7.2:

sudo apt-get install php7.4 php7.4-cli php7.4-common php7.4-mbstring php7.4-gd php7.4-intl php7.4-xml php7.4-mysql php7.4-zip php7.4-curl

Adjust the package names based on the specific modules your application requires.

### 2. Configure Apache to Use the New PHP Version

If you’re using Apache, you need to configure it to use the new version of PHP. This typically involves disabling the old PHP module and enabling the new one:

sudo a2dismod php[old-version]
sudo a2enmod php7.4
sudo service apache2 restart

Yes, you can downgrade the PHP version on a LAMP (Linux, Apache, MySQL, PHP) server, but you should proceed with caution. Downgrading software can sometimes lead to compatibility issues with your web applications or other server components. Here’s a general guide on how to downgrade PHP on a LAMP stack:

### 1. Backup Your Data

Before making any changes, backup your website data, databases, and current PHP configurations. This ensures that you can restore your system in case something goes wrong.

### 2. Remove Current PHP Version

You’ll need to remove the current PHP version. Use your package manager to uninstall it. For Debian-based systems like Ubuntu, you can use apt-get:

sudo apt-get remove php*

This command removes all PHP-related packages. Be careful with this step, as it might remove packages that you might want to keep.

### 3. Install the Desired PHP Version

After removing the current version, install the desired version of PHP. First, you might need to add a repository that contains the older version of PHP, as the default repositories might not have it.

For example, on Ubuntu, you can use the Ondřej Surý PPA, which maintains multiple PHP versions:

sudo add-apt-repository ppa:ondrej/php sudo apt-get update

Then, install the desired PHP version, for example, PHP 7.2:

sudo apt-get install php7.4 php7.4-cli php7.4-common php7.4-mbstring php7.4-gd php7.4-intl php7.4-xml php7.4-mysql php7.4-zip php7.4-curl

Adjust the package names based on the specific modules your application requires.

### 4. Configure Apache to Use the New PHP Version

If you’re using Apache, you need to configure it to use the new version of PHP. This typically involves disabling the old PHP module and enabling the new one:

 a2dismod php[old-version]
 sudo a2enmod php7.4 sudo service apache2 restart

Replace [old-version] with the version number you’re moving away from.

### Considerations

  • Compatibility: Ensure that your applications are compatible with the older PHP version. Some applications might require features available only in newer versions.

  • Security: Older versions of PHP may not receive security updates. Always consider the security implications of downgrading.

  • Dependencies: Some PHP modules or dependencies might not be available for older versions.

  • Support: Check the PHP version’s support status. Using unsupported versions in a production environment is generally not recommended.

This guide is quite general. The specific steps may vary depending on the Linux distribution you are using and the configuration of your server. Always make sure to tailor the process to your specific server environment.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.