Ubuntu php install with extensions

How to Install PHP 8.0 on Ubuntu 20.04 / 18.04

PHP is arguably one of the most widely used server-side programming languages. It’s the language of choice when developing dynamic and responsive websites. In fact, popular CM platforms such as WordPress, Drupal, and Magento are based on PHP.

At the time of penning down this guide, the latest version of PHP is PHP 8.0. It was released on November 26, 2020. It boasts of new features and optimizations such as union types, named arguments, null safe operator, match expression, JIT, and improvements in error handling and consistency.

This tutorial walks you through the installation of PHP 8.0 on Ubuntu 20.04 / 18.04.

Читайте также:  If class exist css

On this page

Step 1: Add the Ondřej Surý PPA Repository

PHP 7.4 is the default PHP version in Ubuntu 20.04 repositories at the time of writing this tutorial. To install the latest version of PHP, we are going to use the Ondrej PPA repositories. This repository contains multiple PHP versions and PHP extensions.

But first, let’s update your Ubuntu system packages and install some dependencies as shown.

$ sudo apt update $ sudo apt upgrade $ sudo apt install ca-certificates apt-transport-https software-properties-common

Next, add the Ondrej PPA.

$ sudo add-apt-repository ppa:ondrej/php

When prompted, press ENTER to proceed with adding the repository.

Add Ondrej PPA

Step 2: Install PHP 8.0 with Apache on Ubuntu

Next, update the system repositories to start using the PPA.

If you are running the Apache web server, install PHP 8.0 with the Apache module as shown.

$ sudo apt install php8.0 libapache2-mod-php8.0

Install PHP 8 in Ubuntu

Next, restart the Apache webserver to enable the module.

$ sudo systemctl restart apache2

If you want to use Apache webserver with PHP-FPM, run the command below to install the required packages:

$ sudo apt install php8.0-fpm libapache2-mod-fcgid

Since PHP-FPM is not enabled by default, enable it by invoking the following commands:

$ sudo a2enmod proxy_fcgi setenvif $ sudo a2enconf php8.0-fpm

Then restart the Apache webserver for the changes to come into effect.

$ sudo systemctl restart apache2

Enable PHP-FPM in Apache

Step 2: Install PHP 8.0 with Nginx on Ubuntu

If you choose to use PHP 8.0 with Nginx installation, the most recommended step to take is to install PHP-FPM to process PHP files.

Therefore, install PHP and PHP-FPM using the following command:

$ sudo apt install php8.0-fpm

The PHP-FPM service should start automatically. You can verify this as shown:

$ sudo systemctl status php8.0-fpm

Verify PHP-FPM in Nginx

For Nginx to process PHP files, configure your Nginx server block by updating the server section as shown:

Finally, restart the Nginx web server for the changes to come into effect.

$ sudo systemctl restart nginx

Step 4: Install PHP 8 Extensions in Ubuntu

PHP extensions are libraries that extend the functionality of PHP. These extensions exist as packages and can be installed as follows:

$ sudo apt install php8.0-[extension-name]

For instance, the example below installs the SNMP, Memcached, and MySQL extensions.

$ sudo apt install php8.0-snmp php-memcached php8.0-mysql

Step 5: Verify PHP 8 Installation in Ubuntu

To confirm the version of PHP installed, run the command:

Verify PHP in Ubuntu

Additionally, you can create a sample php file at /var/www/html as shown:

$ sudo vim /var/www/html/info.php

Paste the following lines and save the file.

Finally, head over to your browser and browse the server’s IP address as shown.

You should get the webpage shown.

Check PHP 8 Info in Ubuntu

Conclusion

It’s our hope that you can now install PHP 8.0 and comfortably integrate it with either Apache or Nginx web servers. Your feedback is most welcome.

Источник

How to Install or Upgrade PHP 8.2 on Ubuntu 22.04

How To Install Or Upgrade Php 8.2 On Ubuntu 22.04

The most recent version of PHP, 8.2, was published in 2022. You will learn how to install the most recent PHP version, which is 8.2, on your Ubuntu 22.04 machine or server and configure it with Apache and Nginx in this tutorial.

Table of Contents

Additionally, you’ll discover how to set up an alternative PHP version and downgrade or upgrade to an earlier or newer version.

This guide also shows you how to configure PHP INI settings, FPM settings, pools, and other things that are more effective for an effective execution of your application.

On the Google Cloud Platform, a Compute Compute Engine VM Instance running the Ubuntu 22.04 operating system is used to test this installation. All Linux distributions will support this setup.

You might also like

Reset your Forgotten Ubuntu Password in 2 Minutes

Install PHP 8.2 on Ubuntu 22.04

PHP is an excellent programming language that is used to create web-based applications. There are several ways to install PHP on Ubuntu 22.04. This section outlines the best ways to install PHP 8.2 on Ubuntu 22.04.

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 installed packages up to date as well as the package index.

Add PHP PPA

If you want to instal PHP 8.1, you can skip this setup. However, if you intend to install any older or newer versions of PHP, such as 7.4 or 8.2, you must 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.2 for Apache

Execute the following command to install PHP 8.2.

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

Install PHP 8.2 FPM for Nginx

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

sudo apt install php8.2-fpm

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

Install PHP 8.2 Extensions

Installing PHP extensions are simple with the following syntax.

sudo apt install php8.2-extension_name

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

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

Verify PHP Version

You can easily verify PHP version using the below command.

Output PHP 8.2.0 (cli) (built: Jan 04 2023 09:13:42) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.0, Copyright (c) Zend Technologies with Zend OPcache v8.2.0, Copyright (c), by Zend Technologies

Configure PHP 8.2

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

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

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

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

sudo nano /etc/php/8.2/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.2-fpm restart

Configure PHP 8.2 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.2/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.2 FPM

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

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

Now you are having PHP 8.2 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.2 82 auto mode 1 /usr/bin/php8.1 81 manual mode 2 /usr/bin/php7.4 74 manual mode 2 /usr/bin/php8.0 80 manual mode 4 /usr/bin/php8.2 82 manual mode Press 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.2, 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 php7.4 sudo a2enmod php8.2

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 configuration located inside the sites-available directory. This will be located inside the location block location ~ .php$

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

The line you need to modify will look like this…

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

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

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

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

sudo service nginx restart

Conclusion

You now know how to install PHP 8.2 for Apache and Nginx on your Ubuntu 22.04 server, as well as how to upgrade or downgrade to a different PHP version. I hope that by reading this article, you get a complete guide on how to install PHP 8.2 on Ubuntu 22.02.

I appreciate your time. Please leave a comment below if you run into any issues or have any suggestions.

Источник

Оцените статью