PHP 8.3.4 Released!

Debian GNU/Linux へのインストール

このセクションでは、» Debian GNU/Linux に PHP をインストールする際の注意事項とヒントについて説明します。

警告

サードパーティが作った非公式のビルドについてはここではサポートしていません。 何かバグを見つけた場合は、 » ダウンロードページ から取得した最新のビルドでそれが再現するかを確認し、 再現しない場合は Debian チームにバグ報告をお願いします。

Unix 上で PHP をビルドする方法は Debian でもそのまま使えます。 しかし、このページではもうひとつの方法として Debian 固有の情報を扱います。 aptaptitude といったコマンドの使い方です。 このマニュアルページでの説明は、これらふたつのコマンドのどちらを使っても実行できます。

APT の使用

まず、Apache 2 と統合する場合は libapache2-mod-php、PEAR を使う場合は php-pear などの関連パッケージが必要となることを知っておきましょう。

次に、パッケージをインストールする前にはパッケージ一覧を最新に更新しておくようにしましょう。 これは、apt update コマンドで行います。

例1 Debian で Apache 2 と組み合わせるインストール例

# apt install php-common libapache2-mod-php php-cli

APT により、Apache 2 用の PHP モジュールとその依存モジュールが自動的にインストールされます。 インストール中に Apache を再起動する旨が表示されなかった場合は、手動で再起動する必要があります。

例2 PHP インストール後に Apache を停止・起動させる

# /etc/init.d/apache2 stop
# /etc/init.d/apache2 start

よりよい設定の管理

ここまでのセクションでは、PHP のコアモジュールだけをインストールしました。 おそらく、さらに MySQLcURLGD などの追加モジュールもインストールしたくなることでしょう。 これらも apt コマンドでインストールすることができます。

例3 追加の PHP パッケージを探す方法

# apt-cache search php
# apt search php | grep -i mysql
# aptitude search php

上記の出力を見てわかるとおり、(php-cgi や php-cli, php-dev といった 特別なパッケージのほかにも) さまざまなパッケージがあり、インストールすることが可能です。 必要なものを見定めて、aptaptitude でインストールしましょう。 Debian は依存性のチェックを行うので、たとえば MySQL と cURL をインストールする場合はこのようになります。

例4 PHP と MySQL、cURL のインストール

# apt install php-mysql php-curl

APT は自動的に、 /etc/php/7.4/php.ini/etc/php/7.4/conf.d/*.ini などの php.ini に適切な行を追加し、extension=foo.so といった内容が書き込まれます。しかし、これらの変更を有効にするにはウェブサーバー (Apache など) を再起動しなければなりません。

よく起きる問題

  • PHP スクリプトがウェブサーバーで実行されない場合は、 おそらく PHP がウェブサーバーの設定ファイルに追加されていないのでしょう。 Debian の場合、設定ファイルは /etc/apache2/apache2.conf のようになります。詳細は Debian のマニュアルを参照ください。
  • 拡張モジュールをインストールしたのに関数が未定義だと言われたら、 適切な ini ファイルが読み込まれているかどうかと インストール後にウェブサーバーを再起動したかどうかを確認しましょう。
  • Debian (およびその派生物) でパッケージをインストールする基本的なコマンドは aptaptitude のふたつです。 しかし、これらのコマンドの微妙な違いについての説明は、このマニュアルでは行いません。
add a note

User Contributed Notes 6 notes

up
67
thumbs at apache dot org
10 years ago
To refresh this document, perhaps it would be worth mentioning more modern methods to serve php content under apache httpd.

Specifically, the preferred method is now fastcgi, using either of those recipes:

(mod_fastcgi, httpd 2.2)
http://wiki.apache.org/httpd/php-fastcgi

(mod_fcgid, httpd 2.2)
http://wiki.apache.org/httpd/php-fcgid

(mod_proxy_fcgi, httpd 2.4)
http://wiki.apache.org/httpd/PHP-FPM

While the legacy mod_php approach is still applicable for some older installations, the fastcgi method is much faster, and require much less RAM to operate, based on similar traffic patterns.

Thank you!
up
41
kearney dot taaffe at gmail dot com
6 years ago
Compiling PHP on Ubuntu boxes.

If you would like to compile PHP from source as opposed to relying on package maintainers, here's a list of packages, and commands you can run

STEP 1:
sudo apt-get install autoconf build-essential curl libtool \
libssl-dev libcurl4-openssl-dev libxml2-dev libreadline7 \
libreadline-dev libzip-dev libzip4 nginx openssl \
pkg-config zlib1g-dev

So you don't overwrite any existing PHP installs on your system, install PHP in your home directory. Create a directory for the PHP binaries to live

mkdir -p ~/bin/php7-latest/

STEP 2:
# download the latest PHP tarball, decompress it, then cd to the new directory.

STEP 3:
Configure PHP. Remove any options you don't need (like MySQL or Postgres (--with-pdo-pgsql))

./configure --prefix=$HOME/bin/php-latest \
--enable-mysqlnd \
--with-pdo-mysql \
--with-pdo-mysql=mysqlnd \
--with-pdo-pgsql=/usr/bin/pg_config \
--enable-bcmath \
--enable-fpm \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--enable-mbstring \
--enable-phpdbg \
--enable-shmop \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-zip \
--with-libzip=/usr/lib/x86_64-linux-gnu \
--with-zlib \
--with-curl \
--with-pear \
--with-openssl \
--enable-pcntl \
--with-readline

STEP 4:
compile the binaries by typing: make

If no errors, install by typing: make install

STEP 5:
Copy the PHP.ini file to the install directory

cp php.ini-development ~/bin/php-latest/lib/

STEP 6:

cd ~/bin/php-latest/etc;
mv php-fpm.conf.default php-fpm.conf
mv php-fpm.d/www.conf.default php-fpm.d/www.conf

STEP 7:
create symbolic links for your for your binary files

cd ~/bin
ln -s php-latest/bin/php php
ln -s php-latest/bin/php-cgi php-cgi
ln -s php-latest/bin/php-config php-config
ln -s php-latest/bin/phpize phpize
ln -s php-latest/bin/phar.phar phar
ln -s php-latest/bin/pear pear
ln -s php-latest/bin/phpdbg phpdbg
ln -s php-latest/sbin/php-fpm php-fpm

STEP 8: link your local PHP to the php command. You will need to logout then log back in for php to switch to the local version instead of the installed version

# add this to .bashrc
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi

STEP 9: Start PHP-FPM

sudo ~/bin/php7/sbin/php-fpm
up
-17
marin at sagovac dot com
9 years ago
To install LAMP stack on Ubuntu (+Server) from 10.04 you need first install taskel and then lamp-server for example:

Install taskel, follow terminal guides:
sudo apt-get install tasksel

Install LAMP stack package from Ubuntu repository:
sudo tasksel install lamp-server
up
-22
John Fisher
17 years ago
With Apache2 and Php4 under Debian Sarge there is an extra configuration file : /etc/apache2/sites-available/default
This file is not clearly documented, at least not for noobs, in Apache docs.

It overrides the conf file in the way you expect the /etc/apache2/conf.d/apache2-doc to do according to the README.

Add ExecCGI to it to get rid of "Options ExecCGI is off in this directory" errors.
up
-25
juraj at jurajsplayground dot com
14 years ago
On Ubuntu (since 7.04), rather do:
sudo tasksel install lamp-server

Details:
https://help.ubuntu.com/community/ApacheMySQLPHP
up
-40
tranzbit at yahoo dot com
14 years ago
On Ubuntu:

sudo apt-get install apache2 php5 mysql-client-5.0 mysql-server-5.0 phpmyadmin libapache2-mod-php5 libapache2-mod-auth-mysql php5-mysql

then restart the computer/start mysql manually
From:
http://ubuntuforums.org/showthread.php?t=186492
To Top