By synthoidzeta
I have a client that wants to utilize a theme for their Wordpress but said theme does not yet support PHP 8 yet. Is there a way for me to downgrade or switch to PHP 7.4.x
Thank you! (or Tenki if you’re from Sierra Leon!)
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!
Hi @synthoidzeta,
The first thing I want to mention is, you can’t directly upgrade or downgrade a PHP version from let’s say 7.1 to 7.4 or 8 to 7.4. Having said that you can install a new one and start using it.
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 is the required extensions for a WordPress installation that’s why I’m posting them. 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 your new PHP version installed.
Now we need to make it a default for your Droplet and Application.
sudo nano /etc/php/7.4/fpm/php.ini
Find: cgi.fix_pathinfo. Remove semi-colon and set 0
cgi.fix_pathinfo=0
Save the file, exit, and execute
sudo systemctl restart php7.4-fpm
Next, configure Nginx to use the new PHP we installed
sudo nano /etc/nginx/sites-available/default
Find the block
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;
}
Save the file, exit, and execute
sudo nginx -t
sudo systemctl reload nginx
You can now test php by using phpinfo() function or use php -v command into the terminal.
Now, to add it to your Website. In your Website’s Nginx config file, can you find the PHP block and update it as it follows.
location ~* \.php$ {
# With php-fpm unix sockets
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
Hope this helps!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
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
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.