How to 1) find out what version of php I'm using and 2) upgrade to the most current version

Posted November 23, 2021 67 views

I’ve been trying to tackle this issue, but I’m a hopeless non-developer. Is it possible for someone to detail how to do both of these tasks I’ve mentioned in the title in great, tedious detail for me, in language that a four year old (wait; THREE year old) might be able to understand? Good golly, I’d desperately appreciate the help. Thank you.

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.

Submit an Answer
1 answer

Hi @teresamwyss,

First, to check your php version, you just need to SSH to your droplet and type in

php -v

As for upgrading the PHP version, You can’t upgrade it, you can just install a new one.

To be able to install a certain PHP version, in this case, 7.4 you’ll need to add a certain repository to your system

sudo apt-add-repository ppa:ondrej/php

Update the repository index.

sudo apt update

Install PHP 7.4 with the below command.

sudo apt install -y php7.4 php7.4-cli php7.4-common php7.4-fpm

To install extensions run

sudo apt install -y php7.4-mysql php7.4-dom php7.4-simplexml php7.4-ssh2 php7.4-xml php7.4-xmlreader php7.4-curl  php7.4-exif  php7.4-ftp php7.4-gd  php7.4-iconv php7.4-imagick php7.4-json  php7.4-mbstring php7.4-posix php7.4-sockets php7.4-tokenizer

The above are the required extensions for a simple WordPRess installation. Having said that it’s good to have these extensions as well.

sudo apt install -y php7.4-mysqli php7.4-pdo  php7.4-sqlite3 php7.4-ctype php7.4-fileinfo php7.4-zip php7.4-exif

That’s it, you now have the latest PHP version installed.

  • Almost forgot to mention.

    If you have nginx, here is how you can activate it:

    To activate PHP 7.4 on the server:
    Configure the PHP Processor

    sudo nano /etc/php/7.4/fpm/php.ini

    Find: cgi.fix_pathinfo
    Remove semi-colon and set 0

    sudo systemctl restart php7.4-fpm

    Configure Nginx to Use the PHP Processor

    sudo nano /etc/nginx/sites-available/default

    Find out

    location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.0-fpm.sock; ---- Remove this line by commenting '#'
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    sudo nginx -t
    sudo systemctl reload nginx

    You can now test php by using phpinfo() function or use php -v command into the terminal.