LoginSignup
16
20

More than 5 years have passed since last update.

PHP5.6をソースからインストール

Last updated at Posted at 2015-09-06

今回の記事では、LAMP環境構築のため、前回の記事のApacheに加えて、PHPをソースからインストールする手順を説明していきます。

1. 各種ツール

PHPをソースからインストールするためには、事前に libxml2 というものが必要になるため、今回の説明では libxml2 のインストール、PHPのインストール、Apacheの設定、動作確認の順で進めていきます。

2. libxml2のインストール

まず、libxml2の公式ページからlibxml2のソースファイルをダウンロードして、インストールします。

# wget ftp://xmlsoft.org/libxml2/libxml2-2.9.2.tar.gz
# tar xzvf libxml2-2.9.2.tar.gz
# cd libxml2-2.9.2
# ./configure --prefix=/opt/libxml2-2.9.2
# make
# porg -lD "make install"

3. PHPのインストール

次に、先程と同様にPHPのインストールを行います。

# wget http://jp2.php.net/get/php-5.6.13.tar.gz/from/this/mirror/ -O php-5.6.13.tar.gz
# tar xzvf php-5.6.13.tar.gz
# cd php-5.6.13
# ./configure --with-openssl=/usr/local/ssl --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/opt/libxml2-2.9.2
# make
# porg -lD "make install"

4. PHPを利用するためのApacheの設定

続いて、ApacheでPHPを利用するために httpd.confに以下の内容を追加します。

# emacs /usr/local/apache2/conf/httpd.conf
httpd.conf
147行目あたり LoadModule php5_module modules/libphp5.so

376行目あたり AddType application/x-httpd-php .php
377行目 AddType application/x-httpd-php-source .phps

505行目あたり PHPIniDir "/usr/local/lib/php/php.ini"

httpd.conf に内容を追加したらApacheを再起動します。

# /usr/local/apache2/bin/apachectl restart

or

# service httpd restart

5. 動作確認

最後にApacheでPHPを利用可能か確認するために以下のように phpinfo.php というファイルを作成します。

# emacs /usr/local/apache2/htdocs/phpinfo.php 
phpinfo.php
<?
    phpinfo();
?>

ファイル作成後、localhost/phpinfo.php にアクセスして以下のようなページが出力されればPHPのインストール作業は完了です。

# curl localhost/phpinfo.php | head
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<style type="text/css">
body {background-color: #fff; color: #222; font-family: sans-serif;}
pre {margin: 0; font-family: monospace;}
a:link {color: #009; text-decoration: none; background-color: #fff;}
a:hover {text-decoration: underline;}
table {border-collapse: collapse; border: 0; width: 934px; box-shadow: 1px 2px 3px #ccc;}
.center {text-align: center;}
.center table {margin: 1em auto; text-align: left;}
100 65338    0 65338    0     0  6494k      0 --:--:-- --:--:-- --:--:-- 7089k
curl: (23) Failed writing body (198 != 1372)

phpinfo_sample.png

参考文献

  1. The XML C parser and toolkit of Gnome, http://www.xmlsoft.org/, Online; accessed 6-September-2015.
  2. PHP_ Hypertext Preprocessor, http://php.net/, Online; accessed 6-September-2015.
  3. CentOS6.x - CentOS6.3でPHP5.5をソースからインストール - Qiita, http://qiita.com/nobu_blast/items/930f23ac3a6aea9509ee, Online; accessed 6-September-2015.
16
20
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
16
20