Инструменты пользователя

Инструменты сайта


linux:php:install_php_8.0_on_ubuntu

Это старая версия документа!


How to Install PHP 8.0 on Ubuntu 20.04 / 18.04

PHP, возможно, является одним из наиболее широко используемых серверных языков программирования. Это предпочтительный язык при разработке динамических и адаптивных веб-сайтов. На самом деле популярные платформы CM, такие как WordPress, Drupal и Magento, основаны на PHP.

На момент написания этого руководства последней версией PHP была PHP 8.0. Он был выпущен 26 ноября 2020 года. Он может похвастаться новыми функциями и оптимизациями, такими как типы объединения, именованные аргументы, безопасный оператор null, выражение соответствия, JIT, а также улучшения в обработке ошибок и согласованности.

В этом руководстве вы узнаете, как установить PHP 8.0 на Ubuntu 20.04 / 18.04.

Step 1: Добавьте репозиторий Ondrej Surý PPA

PHP 7.4 — это версия PHP по умолчанию в репозиториях Ubuntu 20.04 на момент написания этого руководства. Чтобы установить последнюю версию PHP, мы будем использовать репозитории Ondrej PPA. Этот репозиторий содержит несколько версий PHP и расширений PHP.

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

Затем добавьте Ondrej PPA.

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

При появлении запроса нажмите ENTER, чтобы продолжить добавление репозитория.

Add Ondrej PPA Add Ondrej PPA

Step 2: Установите PHP 8.0 с Apache на Ubuntu

Затем обновите системные репозитории, чтобы начать использовать PPA.

$ sudo apt update

Если вы используете веб-сервер Apache, установите PHP 8.0 с Apache модуль, как показано.

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

Install PHP 8 in Ubuntu Install PHP 8 in Ubuntu
Установите PHP 8 в Ubuntu

Затем перезапустите веб-сервер Apache, чтобы включить модуль.

$ sudo systemctl restart apache2

Если вы хотите использовать веб-сервер Apache с PHP-FPM, выполните приведенную ниже команду, чтобы установить необходимые пакеты:

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

Поскольку PHP-FPM не включен по умолчанию, включите его, выполнив следующие команды:

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

Затем перезапустите веб-сервер Apache, чтобы изменения вступили в силу.

$ sudo systemctl restart apache2

Enable PHP-FPM in Apache Enable PHP-FPM in Apache


Включить PHP-FPM в 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 Verify PHP-FPM in Nginx Verify PHP-FPM in Nginx

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

server {

   # ... some other code

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
    }
}

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

$ sudo systemctl restart nginx

Step 5: Verify PHP 8 Installation in Ubuntu

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

$ php -v

Verify PHP in Ubuntu Verify PHP in Ubuntu 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.

<?php

phpinfo();

?>

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

http://server-ip/info.php

You should get the webpage shown.

Check PHP 8 Info in Ubuntu Check PHP 8 Info in Ubuntu 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.

Tags PHP Tips, Ubuntu Tips

Post navigation

How to Boot into Rescue Mode Or Emergency Mode In Ubuntu 20.04 / 18.04

How to Install PHP 8 on CentOS/RHEL 8/7

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

AD

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support UsWe are thankful for your never ending support.

linux/php/install_php_8.0_on_ubuntu.1654156024.txt.gz · Последние изменения: 2023/01/12 12:16 (внешнее изменение)