1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UbuntuでPHPをインストールできない

Last updated at Posted at 2020-05-11

やりたいこと

デフォルトでインストールされているPHPが7.0なので、7.4に上げたい

$ php -v
The program 'php' can be found in the following packages:
 * php7.0-cli
 * hhvm
Ask your administrator to install one of them

事象

PHPのパッケージがaptのリストにないためアップデートできない

$ sudo apt -y install php7.4
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php7.4
E: Couldn't find any package by glob 'php7.4'
E: Couldn't find any package by regex 'php7.4'

解決方法

add-apt-repositoryする

$ sudo add-apt-repository ppa:ondrej/php
 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

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:


Creating config file /etc/php/7.4/mods-available/iconv.ini with new version

Creating config file /etc/php/7.4/mods-available/pdo.ini with new version

Creating config file /etc/php/7.4/mods-available/phar.ini with new version

Creating config file /etc/php/7.4/mods-available/posix.ini with new version

Creating config file /etc/php/7.4/mods-available/shmop.ini with new version

Creating config file /etc/php/7.4/mods-available/sockets.ini with new version

Creating config file /etc/php/7.4/mods-available/sysvmsg.ini with new version

Creating config file /etc/php/7.4/mods-available/sysvsem.ini with new version

Creating config file /etc/php/7.4/mods-available/sysvshm.ini with new version

Creating config file /etc/php/7.4/mods-available/tokenizer.ini with new version
Setting up php7.4-json (7.4.5-1+ubuntu16.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/mods-available/json.ini with new version
Setting up php7.4-opcache (7.4.5-1+ubuntu16.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/mods-available/opcache.ini with new version
Setting up php7.4-readline (7.4.5-1+ubuntu16.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/mods-available/readline.ini with new version
Setting up libargon2-0:amd64 (0~20161029-1+ubuntu16.04.1+deb.sury.org+1) ...
Setting up libpcre2-8-0:amd64 (10.34-7+ubuntu16.04.1+deb.sury.org+1) ...
Setting up libsodium23:amd64 (1.0.18-1+ubuntu16.04.1+deb.sury.org+1) ...
Setting up php7.4-cli (7.4.5-1+ubuntu16.04.1+deb.sury.org+1) ...
update-alternatives: using /usr/bin/php7.4 to provide /usr/bin/php (php) in auto mode
update-alternatives: using /usr/bin/phar7.4 to provide /usr/bin/phar (phar) in auto mode
update-alternatives: using /usr/bin/phar.phar7.4 to provide /usr/bin/phar.phar (phar.phar) in auto mode

Creating config file /etc/php/7.4/cli/php.ini with new version
Setting up libapache2-mod-php7.4 (7.4.5-1+ubuntu16.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/apache2/php.ini with new version
Module mpm_event disabled.
Enabling module mpm_prefork.
apache2_switch_mpm Switch to prefork
apache2_invoke: Enable module php7.4
Setting up php7.4 (7.4.5-1+ubuntu16.04.1+deb.sury.org+1) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for php7.4-cli (7.4.5-1+ubuntu16.04.1+deb.sury.org+1) ...
Processing triggers for libapache2-mod-php7.4 (7.4.5-1+ubuntu16.04.1+deb.sury.org+1) ...

確認

$ php -v
PHP 7.4.5 (cli) (built: Apr 19 2020 07:36:13) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies

参考: Unable to locate package php7.3-gd

1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?