To install PHP 8 as an Apache module, enter the following command on Ubuntu 20.04: sudo apt install php8.1 libapache2-mod-php8.1 If you run an Apache HTTP server, you can run PHP as an Apache module or PHP-FPM. Installing PHP 8.1 for Apache on Ubuntu 20.04 Then, update and upgrade your local package index with the command below: sudo apt update & sudo apt upgrade Set up PHP 8.1 on Ubuntu 20.04Īt this point, you can install PHP 8.1 with an Apache option and Nginx. To install Ondřej Surý PPA and the required packages on Ubuntu 20.04, run the following command: sudo apt install software-properties-common & sudo add-apt-repository ppa:ondrej/php -y To successfully install PHP 8.1, you will need to import the good renowned PPA from Ondřej Surý, the lead developer on PHP and Debian, and maintain Ubuntu and Debian packages. Import Ondřej Surý PHP PPA on Ubuntu 20.04 Now you can follow the steps below to complete this guide. To do this, you can follow our article the Initial Server Setup with Ubuntu 20.04. To use PHP version 7.Steps To Install PHP 8.1 LTS on Ubuntu 20.04īefore you start to install PHP 8.1, you need to log in to your server as a non-root user with sudo privileges. Save and close the file when you are finished. ![]() To do so, create a info.php file in your Nginx web root directory: # nano /var/www/html/info.php Next, you will need to test which PHP version is used by your Nginx server. You can switch between multiple PHP versions easily by configuring the Nginx virtual host and PHP-FPM.įirst, install the Nginx server package with the following command: # apt-get install nginx -y With Zend OPcache v7.4.18, Copyright (c), by Zend Technologies Switch Between Multiple PHP Versions with Nginx ![]() Zend Engine v3.4.0, Copyright (c) Zend Technologies You should see the following output: PHP 7.4.18 (cli) (built: 11:27:06) ( NTS ) Now, verify your default PHP version using the following command: # php -version Select your desired PHP version and hit "Enter" to set it to the default version. Update-alternatives: using /usr/bin/php7.4 to provide /usr/bin/php (php) in manual mode Press "enter" to keep the current choice, or type selection number: 2 You will be asked to set the default PHP version as shown below: There are 3 choices for the alternative php (providing /usr/bin/php). Now, set the default command line PHP version to PHP 7.4 using the following command: # update-alternatives -config php With Zend OPcache v8.0.5, Copyright (c), by Zend TechnologiesĪs you can see, PHP 8.0 is the default PHP command line version. Zend Engine v4.0.5, Copyright (c) Zend Technologies You should see the following output: PHP 8.0.5 (cli) (built: 11:30:57) ( NTS ) Set the Default PHP Version for the Command Lineįirst, check the current version of command-line PHP running the following command: # php -version To install the PHP version 8.1 with PHP-FPM support, run the following command: # apt-get install php8.1 php8.1-fpm php8.1-cli -yĪt this point, all PHP versions are installed in your system. To install the PHP version 8.0 with PHP-FPM support, run the following command: # apt-get install php8.0 php8.0-fpm php8.0-cli -y To install the PHP version 7.4 with PHP-FPM support, run the following command: # apt-get install php7.4 php7.4-fpm php7.4-cli -y To install the PHP version 7.2 with PHP-FPM support, run the following command: # apt-get install php7.2 php7.2-fpm php7.2-cli -y Install Multiple Versions of PHP (7.2, 7.4, 8.0 and 8.1) ![]() Once the repository is up-to-date, you can proceed to install multiple PHP versions. Next, update the repository with the following command: # apt-get update -y Once all the dependencies are installed, add the PHP repository using the following command: # add-apt-repository ppa:ondrej/php So you'll need to add the PHP repository in your system to install the multiple PHP versions.įirst, install the required dependencies with the following command: # apt-get install software-properties-common gnupg2 -y A root password is configured on the server.īy default, Ubuntu 20.04 ships with the PHP version 7.4.In this article, we'll show you how to install PHP 7.2, 7.4, 8.0 and 8.1 on Ubuntu 20.04. In this case, you can configure NGINX to define your desired PHP version. This is very useful when you have multiple PHP applications on your server and each application is compatible with the different PHP versions. If you are a system or web server administrator, it's very important for you to know how to install and use multiple PHP versions on a single server.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |