Dependencies required for installation
First, we first install some dependent packages for later installation processing:
sudo apt install ca-certificates apt-transport-https software-properties-common
First, we execute the following command to install PPA:
sudo add-apt-repository ppa:ondrej/php
There is a note here, that is, half of the execution, the following text needs a carriage return to continue execution.
Press [ENTER] to continue or Ctrl-c to cancel adding it.
After the execution is complete, let's see how much the current default version of PHP has become
$ sudo apt show php
Package: php
Version: 2:8.0+82+ubuntu20.04.1+deb.sury.org+1
Priority: optional
Section: php
Source: php-defaults (82+ubuntu20.04.1+deb.sury.org+1)
Maintainer: Debian PHP Maintainers <team+pkg-php@tracker.debian.org>
Installed-Size: 13.3 kB
Depends: php8.0
Download-Size: 6,960 B
APT-Sources: http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
open source general-purpose scripting language that is especially suited
for web development and can be embedded into HTML.
.
This package is a dependency package, which depends on latest stable
PHP version (currently 8.0).
N: 有 1 条附加记录。请加上 ‘-a’ 参数来查看它们
You can see that the default PHP version has changed from 7.4 that comes with the system to 8.0.
Install PHP
Execute the following command to install PHP 8.0:
sudo apt install php-fpm
Also install other versions of PHP as follows:
sudo apt install php7.4-fpm
5.6.* ~ 8.0.*
, the PPA currently supports 0614fdb31d998a series.
After the installation is successful, you can execute the command to view the current version:
$ php -v
PHP 8.0.3 (cli) (built: Mar 5 2021 07:54:13) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies
with Zend OPcache v8.0.3, Copyright (c), by Zend Technologies
Executable command
The following commands are commonly used:
- php
- php-fpm
- pecl
- phpize
- php-config
- pear
- and many more
path
Log path:
$ ls /var/log/php*
/var/log/php7.4-fpm.log /var/log/php8.0-fpm.log
Management commands
start up:
sudo systemctl start php8.0-fpm
stop:
sudo systemctl stop php8.0-fpm
Restart:
sudo systemctl restart php8.0-fpm
Set boot up:
sudo systemctl enable php8.0-fpm
Cancel startup
sudo systemctl disable php8.0-fpm
Check running status
sudo systemctl status php8.0-fpm
apt install extension
To install the extension, you can execute the following command:
sudo apt install php-mbstring php-dom php-mysql
Some extensions can be installed in this way.
We can check which extensions can be installed by executing the following command:
sudo apt search php-*
Manually install the extension
First of all, we first install the compilation dependency package of PHP
sudo apt install php-dev
Here is still a reminder, if you want to install a compilation dependency package that is not the default version, you need to execute the version. For example, php7.4-dev
.
For example, to install a package that does not exist in apt, you can execute the following command:
sudo pecl install seaslog
This completes the installation.
Configuration file
Here is an introduction to the installation of extensions. Because PHP has two operating modes, one is FPM and the other is CLI. So it can control the way that an extension is only loaded in FPM and not in CLI.
First look at its catalog
$ ls /etc/php/8.0/
cli fpm mods-available
First of all, our extended management is stored in mods-available
.
Then if we want to control FPM to load this certain configuration, then we must create a soft link.
We can understand by looking at the following command:
$ ll /etc/php/8.0/fpm/conf.d/20-mbstring.ini
lrwxrwxrwx 1 root root 40 7月 16 22:34 /etc/php/8.0/fpm/conf.d/20-mbstring.ini -> /etc/php/8.0/mods-available/mbstring.ini
All right. Basically the introduction is like this.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。