Cài đặt PHP 8.1 trên ubuntu 22.04

bởi | LPI, Ubuntu

Home » LPI » Ubuntu » Cài đặt PHP 8.1 trên ubuntu 22.04

Chuẩn bị

– Cấu hình mạng cho web server

root@localhost:~# cat /etc/netplan/01-netcfg.yaml
network:
  ethernets:
    ens33:
      dhcp4: false
      addresses: [192.168.64.6/24]
      routes:
        - to: default
          via: 192.168.64.2
          metric: 100
      nameservers:
        addresses: [8.8.8.8,1.1.1.1]
      dhcp6: false
  version: 2

network:
  ethernets:
    ens37:
      dhcp4: false
      addresses: [10.0.0.6/24]
      nameservers:
         addresses: [10.0.0.3]
      dhcp6: false
  version: 2

– Đổi hostname, time zone

root@localhost:~# hostnamectl set-hostname www.dinhducthanh.local
root@localhost:~# timedatectl set-timezone Asia/Ho_Chi_Minh
root@localhost:~# reboot

Install PHP 8.1

root@www:~# apt -y install php8.1 php8.1-mbstring php-pear

– Kiểm tra lại

root@www:~# php -v
PHP 8.1.2-1ubuntu2.17 (cli) (built: May  1 2024 10:10:07) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.17, Copyright (c), by Zend Technologies

– Xác minh cài đặt để tạo một test script

root@www:~# echo '' > php_test.php
root@www:~# php php_test.php | head
phpinfo()
PHP Version => 8.1.2-1ubuntu2.17

System => Linux www.dinhducthanh.local 5.15.0-105-generic #115-Ubuntu SMP Mon Apr 15 09:52:04 UTC 2024 x86_64
Build Date => May  1 2024 10:10:07
Build System => Linux
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc/php/8.1/cli
Loaded Configuration File => /etc/php/8.1/cli/php.ini

Tham khảo thêm

Cài đặt ban đầu Ubuntu 22.04: Enable root user

Cài đặt ban đầu Ubuntu 22.04: Network Settings

Cài đặt DNS Server trên Ubuntu 22.04: Internal Network