Nvidia Unveils Futuristic Gaming Experience at Computex 2023
News

Nvidia Unveils Futuristic Gaming Experience at Computex 2023, Blending Gaming and AI

by Isabel
May 29, 2023
0

At Computex 2023, Nvidia displays a futuristic gaming experience that...

Read more
Adobe Introduces Powerful Generative AI Tools in Photoshop

Adobe Introduces Powerful Generative AI Tools in Photoshop Beta

May 29, 2023
Adobe Photoshop's Generative Fill Feature

Exploring the Power of Adobe Photoshop’s Generative Fill Feature

May 27, 2023
NVIDIA and Microsoft Partner to Accelerate AI

NVIDIA and Microsoft Partner to Accelerate AI

May 25, 2023
google photos security and privacy

Exploring the Top 5 Privacy and Security Risks of using Google Photos

May 24, 2023
Microsoft Launches Bing with AI Powered ChatGPT

Microsoft Launches Bing with AI Powered ChatGPT

February 8, 2023
How to install AutoGPT plugins

How to install AutoGPT Plugin

May 4, 2023
ChatGPT Error

ChatGPT Errors: How to Resolve Common Issues

May 11, 2023
Fairseq A Powerful Tool for Sequence Modeling

Fairseq: A Powerful Tool for Sequence Modeling

May 25, 2023
Dute AI for Google Workspace

Revolutionizing Collaboration: How Duet AI for Google Workspace is Changing the Game

May 12, 2023
How to use Autogpt in web browser

How to use AutoGPT in web browser

May 4, 2023
Cloudbooklet
  • News
  • Artificial Intelligence
  • Linux
  • Google Cloud
  • AWS
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Linux
  • Google Cloud
  • AWS
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Google Cloud

How to Install or Upgrade PHP 8.1 on Ubuntu 22.04

by Cloudbooklet
May 23, 2023
in Google Cloud, Linux
Reading Time: 8 mins read
How to Install or Upgrade PHP 8.1 on Ubuntu 22.04
Share on FacebookShare on TwitterShare on WhatsAppShare on Telegram

PHP 8.1 is the current latest PHP version released on 2021. In this guide you are going to learn how to install the latest PHP version which is currently 8.1 on your Ubuntu 22.04 system or server and configure it with Apache and Nginx. By default Ubuntu 22.04 ships with PHP 8.1, you can install it easily. You will also learn how to install a different version of PHP and downgrade or upgrade your PHP version to latest or a previous one.

This tutorial also guides you to configure PHP INI settings, FPM settings, Pools, etc which is more useful for your application to run smooth.

You might also like

How to Setup SSH Keys on Ubuntu

How to Setup SSH Keys on Ubuntu 20.04

May 31, 2023
DragGAN AI editing Tool Install and Use DragGAN Photo Editor

DragGAN AI editing Tool Install and Use DragGAN Photo Editor

May 27, 2023

This installation is tested on Google Cloud Platform with a Compute Compute Engine VM Instance with Ubuntu 22.04 OS. This set up will work on all Linux servers.

Prerequisites

Basic knowledge of using SSH Terminal on Linux.

Getting Started

Make sure your Ubuntu server is having the latest packages by running the following command.

sudo apt update
sudo apt upgrade

This will update the package index and update the installed packages to the latest version.

Add PHP PPA

This is an optional setup if you wish to install PHP 8.1. But you are about to install any lower versions of PHP versions like 7.4 you need to add this PPA.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Only add this if you are about to install a PHP version other than version 8.1.

Install PHP 8.1 for Apache

Execute the following command to install PHP 8.1.

sudo apt install php8.1

After the installation has completed, you can confirm the installation using the following command

php -v

Install PHP 8.1 FPM for Nginx

For Nginx you need to install FPM. Execute the following command to install PHP 8.1 FPM

sudo apt install php8.1-fpm

After the installation has completed, confirm that PHP 8.1 FPM has installed correctly with this command

php-fpm8.1 -v

Install PHP 8.1 Extensions

Installing PHP extensions are simple with the following syntax.

sudo apt install php8.1-extension_name

Now, install some commonly used php-extensions with the following command.

sudo apt install php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-redis php8.1-intl -y

Verify PHP Version

You can easily verify PHP version using the below command.

php -v
Output
PHP 8.1.5 (cli) (built: Apr 21 2022 10:32:13) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies

Configure PHP 8.1

Now we configure PHP for Web Applications by changing some values in php.ini file.

For PHP 8.1 with Apache the php.ini location will be in following directory.

sudo nano /etc/php/8.1/apache2/php.ini

For PHP 8.1 FPM with Nginx the php.ini location will be in following directory.

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

Hit F6 for search inside the editor and update the following values for better performance.

upload_max_filesize = 32M 
post_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000

Once you have modified your PHP settings you need to restart your Apache for the changes to take effect.

For users with Nginx to who use PHP-FPM, you need to restart PHP-FPM.

sudo service php8.1-fpm restart

Configure PHP 8.1 FPM Pools

PHP-FPM allows you to configure the user and group that the service will run under. You can modify these with these commands

sudo nano /etc/php/8.1/fpm/pool.d/www.conf

If you want to change the username name you can change the following lines by replacing the www-data with your username.

user = username 
group = username 
listen.owner = username
listen.group = username

Hit CTRL+X and Y to save the configuration and check if the configuration is correct and restart PHP.

Restart PHP 8.1 FPM

Once you have updated your PHP FPM settings you need to restart it to apply the changes.

sudo php-fpm8.1 -t 
sudo service php8.1-fpm restart

Now you are having PHP 8.1 Installed and configured.

Prepare yourself for a role working as an Information Technology Professional with Linux operating system

Upgrade/Downgrade PHP in CLI

As you are switching PHP version for your web applications you will also need to change the PHP version in your CLI (Command Line Interface).

Execute the below command to change PHP version on your CLI. You will be prompted with an interactive mode to choose your PHP version.

sudo update-alternatives --config php
There are 3 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php8.1   81        auto mode
  1            /usr/bin/php7.4   74        manual mode
  2            /usr/bin/php8.0   80        manual mode
  3            /usr/bin/php8.1   81        manual mode

Press <enter> to keep the current choice[*], or type selection number:

Enter you choice and hit ENTER.

Upgrade/Downgrade PHP for Apache

If you want to use a different PHP version you can upgrade or downgrade to the other PHP version as shown below..

You need to tell Apache to use the correct PHP version you installed right now. Disable the old PHP module (below I have mentioned php 8.1, you need to use your other php version used by Apache) and enable the new PHP module using the following command.

Replace the current enabled PHP version with your version.

sudo a2dismod php8.1
sudo a2enmod php7.4

Restart Apache for the changes to take effect.

sudo service apache2 restart

Upgrade/Downgrade PHP for Nginx

For Nginx you need to update or downgrade the PHP-FPM socket in your Nginx configration located inside the sites-available directory. This will be located inside the location block location ~ .php$

Edit your configuration…

sudo nano /etc/nginx/sites-available/your.conf

The line you need to modify will look like this…

fastcgi_pass unix:/run/php/php8.1-fpm.sock; 

You need to replace the old PHP version with the new version.

fastcgi_pass unix:/run/php/php7.4-fpm.sock; 

Test your configration.

sudo nginx -t

Save the file and exit the editor and restart Nginx for the changes to take effect.

sudo service nginx restart

Conclusion

Now you have learned how to install PHP 8.1 on your Ubuntu 22.04 server for Apache and Nginx and also how to upgrade or downgrade to a different PHP version.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Tags: ApacheNginxPHP
Share5Tweet3SendShare
Cloudbooklet

Cloudbooklet

Help us grow and support our blog! Your contribution can make a real difference in providing valuable content to our readers. Join us in our journey by supporting our blog today!
Buy me a Coffee

Related Posts

How to Use ChatGPT in Linux Terminal

How to Use ChatGPT in Linux Terminal

May 19, 2023
Install WordPress with Docker Compose, Nginx, Apache with SSL

WordPress Deployment Made Easy: Docker Compose, Nginx, Apache, SSL Setup Guide

May 20, 2023
How to Install WordPress on Docker

How to Install WordPress on Docker for Windows, macOS, and Linux

May 20, 2023
How to install python on Ubuntu

How to Install Python on Ubuntu 22.04?

May 31, 2023

Comments 1

  1. Jake says:
    7 months ago

    Fantastic easy to follow guide.

    One thing, you are missing the command in the Upgrade/Downgrade CLI step.

    I believe it should be:

    sudo update-alternatives –config php

    Cheers!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

I agree to the Terms & Conditions and Privacy Policy.

  • Trending
  • Comments
  • Latest
DragGAN The AI-Powered Image Editing Tool

DragGAN: The AI-Powered Image Editing Tool That Makes Editing Images Easy

May 30, 2023
DragGAN AI editing Tool Install and Use DragGAN Photo Editor

DragGAN AI editing Tool Install and Use DragGAN Photo Editor

May 27, 2023
Bard API key

Everything You Need to Know About Google’s Bard API Key

May 20, 2023
Install PHP 8.1 on Ubuntu

How to Install or Upgrade PHP 8.1 on Ubuntu 20.04

May 17, 2023
DragGAN The AI-Powered Image Editing Tool

DragGAN: The AI-Powered Image Editing Tool That Makes Editing Images Easy

75
Upgrade PHP version to PHP 7.4 on Ubuntu

Upgrade PHP version to PHP 7.4 on Ubuntu

28
Install Odoo 13 on Ubuntu 18.04 with Nginx - Google Cloud

Install Odoo 13 on Ubuntu 18.04 with Nginx – Google Cloud

25
Best Performance WordPress with Google Cloud CDN and Load Balancing

Best Performance WordPress with Google Cloud CDN and Load Balancing

23
How to Setup SSH Keys on Ubuntu

How to Setup SSH Keys on Ubuntu 20.04

May 31, 2023
ChatGPT app

The Easiest Way to Download ChatGPT App Free

May 31, 2023
LLM Connected with APIs

Gorilla: LLM Connected with APIs

May 31, 2023
Soundstorm-Pytorch

Soundstorm-Pytorch: A Powerful Tool for Audio Generation

May 30, 2023

Popular Articles

  • DragGAN The AI-Powered Image Editing Tool

    DragGAN: The AI-Powered Image Editing Tool That Makes Editing Images Easy

    1437 shares
    Share 575 Tweet 359
  • DragGAN AI editing Tool Install and Use DragGAN Photo Editor

    333 shares
    Share 133 Tweet 83
  • Auto-Photoshop-Stable Diffusion-Plugin: A New Way to Create AI-Generated Images in Photoshop

    70 shares
    Share 28 Tweet 18
  • InternGPT: A New Way to Interact with ChatGPT

    54 shares
    Share 22 Tweet 14
  • Midjourney vs Adobe Firefly: A Comparison of Two AI Image Generation Tools

    10 shares
    Share 4 Tweet 3
Cloudbooklet

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Linux
  • Google Cloud
  • AWS

Cloudbooklet © 2023 All rights reserved.

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.