Оглавление:
Карта сайта:
Оглавление:
Карта сайта:
Это старая версия документа!
PHP, возможно, является одним из наиболее широко используемых серверных языков программирования. Это предпочтительный язык при разработке динамических и адаптивных веб-сайтов. На самом деле популярные платформы CM, такие как WordPress, Drupal и Magento, основаны на PHP.
На момент написания этого руководства последней версией PHP была PHP 8.0. Он был выпущен 26 ноября 2020 года. Он может похвастаться новыми функциями и оптимизациями, такими как типы объединения, именованные аргументы, безопасный оператор null, выражение соответствия, JIT, а также улучшения в обработке ошибок и согласованности.
В этом руководстве вы узнаете, как установить PHP 8.0 на Ubuntu 20.04 / 18.04.
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
AD
Затем добавьте Ondrej PPA.
$ sudo add-apt-repository ppa:ondrej/php
При появлении запроса нажмите ENTER, чтобы продолжить добавление репозитория.
Next, update the system repositories to start using the PPA.
$ sudo apt update
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
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
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
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
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
To confirm the version of PHP installed, run the command:
$ php -v
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.
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
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.