LoginSignup
7
4

More than 3 years have passed since last update.

Ubuntu(WSL2)にPHP8をインストールする

Posted at

はじめに

こんにちは。GutHubで管理している職務経歴書が定期的にcloneされている筆者です:thinking:

新しいPCのセットアップをしてまして、PHPをインストールしたいのですが、せっかくなので最新のPHP8をインストールしていこうと思います :muscle:

手順

1. software-properties-commonをインストール

外部リポジトリを使用するため、リポジトリ管理に必要なsoftware-properties-commonをインストールします。

$ sudo apt install software-properties-common

2. リポジトリ追加

ppa:ondrej/phpリポジトリをaptに登録します。

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

↓ こんなの出てきますが、続けるならEnter押してと言われているのでEnter押してください。

 Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.

Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa

You can get more information about the packages at https://deb.sury.org

IMPORTANT: The <foo>-backports is now required on older Ubuntu releases.

BUGS&FEATURES: This PPA now has a issue tracker:
https://deb.sury.org/#bug-reporting

CAVEATS:
1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
2. If you are using apache2, you are advised to add ppa:ondrej/apache2
3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline
   or ppa:ondrej/nginx

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/

WARNING: add-apt-repository is broken with non-UTF-8 locales, see
https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:

# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
 More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Press [ENTER] to continue or Ctrl-c to cancel adding it.

3. apt update

リポジトリ追加したときは、apt updateしましょう!

$ sudo apt update

4. 念のためPHP8があるか確認

$ sudo apt show php8.0

↓こんなの出れば大丈夫です:ok_hand:

Package: php8.0
Version: 8.0.3-1+ubuntu20.04.1+deb.sury.org+1
Priority: optional
Section: php
Maintainer: Debian PHP Maintainers <team+pkg-php@tracker.debian.org>
Installed-Size: 59.4 kB
Provides: php
Depends: libapache2-mod-php8.0 | php8.0-fpm | php8.0-cgi, php8.0-common
Download-Size: 24.3 kB
APT-Sources: http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 Packages
Description: server-side, HTML-embedded scripting language (metapackage)
 This package is a metapackage that, when installed, guarantees that you
 have at least one of the four server-side versions of the PHP interpreter
 installed. Removing this package won't remove PHP from your system, however
 it may remove other packages that depend on this one.
 .
 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.

5. いざインストール

$ sudo apt install php8.0 -y

6. バージョン確認

$ php -v

↓ちゃんとPHP8がインストールできました:ok_hand:

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

おわりに

新卒で入った会社では、ソースからビルドしてってすごい言われてましたが、aptとかyum(もう使われてないんでしたっけ..)で入れられるって便利ですよね:smile:

あー、早くPHP8のNullsafe Operatorの恩恵を受けたい!!

それでは!

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4