LoginSignup
3
1

More than 5 years have passed since last update.

CentOS 7 PHP 7.2.4のソースファイルからのインストール

Last updated at Posted at 2018-03-29

動作確認環境

  • 仮想環境 VMware Workstation Player 14.1.1
  • OS Windows 10 Pro 64bit

仮想環境

  • OS CentOS 7.4 (1708) minimalインストール
  • メモリ 2GB
  • HDD 250GB

前提条件

  • gcc 7.3.0
  • cmake 3.11.0
  • MySQL 5.7.21
  • OpenSSL 1.1.0.h
  • Apache 2.4.33

依存するパッケージをインストール

yumでパッケージをインストールすると2つのパッケージが「利用できません」と表示されるので、事前にインストールする。

パッケージ libmcrypt-devel は利用できません。
パッケージ libtidy-devel は利用できません。

2つのパッケージは通常のyumのインストールではできないのでepel-releaseを利用する。epel-releaseをインストールしてから、それぞれのパッケージをインストールする。

yum -y install epel-release
yum -y --enablerepo=epel install libmcrypt-devel
yum -y --enablerepo=epel install libtidy-devel

PHPで必要なパッケージをインストールする。

yum -y install libxml2-devel openssl-devel freetype-devel libcurl-devel net-snmp-devel libpng-devel libjpeg-turbo-devel openldap-devel readline-devel gd-devel bzip2-devel libicu-devel libwebp-devel gmp-devel libxslt-devel

ダウンロード・展開

最新バージョンの確認
PHP: Downloads

/usr/local/srcディレクトリを移動する。

cd /usr/local/src

ソースファイルをダウンロードする。

wget http://jp2.php.net/get/php-7.2.4.tar.gz/from/this/mirror

ファイル名がmirrorになっているので、変更する。

mv mirror php-7.2.4.tar.gz

ダウンロードしたファイルを展開する。

tar zxvf php-7.2.4.tar.gz

コンパイル・インストール

展開したディレクトリに移動します。

cd php-7.2.4

コンパイル・インストール

./buildconf --force
./configure --with-libdir=lib64 --with-pic --with-bz2 --with-freetype-dir --with-png-dir --with-xpm-dir --with-gettext --with-gmp --with-iconv --with-jpeg-dir --with-curl --with-webp-dir --with-png-dir --with-openssl --with-pcre-regex --with-zlib --with-layout=GNU --enable-exif --enable-ftp --enable-sockets --with-kerberos --enable-shmop --enable-calendar --with-libxml-dir --with-mhash --with-ldap --with-readline --with-snmp --with-tidy --with-xsl --with-gnu-ld --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --enable-mbstring --with-gd --with-apxs2=/usr/local/apache2/bin/apxs
make
make install

./configureにてエラーで停止する。

configure: error: Cannot find libtidy

libtidy関連のパッケージをインストールする。

yum -y install libtidy libtidy-devel
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/Packages/l/libwebp-0.4.3-3.el6.x86_64.rpm
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/Packages/l/libwebp-devel-0.4.3-3.el6.x86_64.rpm

この後、./configureが実行できる。

設定

初期設定

設定ファイルphp.iniをソースファイルからコピーする。

cp php.ini-development /usr/local/etc/php.ini

エラーログの出力先を作成、オーナーの変更、パーミッションを変更する。

mkdir /var/log/php
chown daemon /var/log/php
chmod 755 /var/log/php

php.iniの設定

php.iniを編集する。

vi /usr/local/etc/php.ini

変更内容

php.ini
error_log = "/var/log/php/php_errors.log"

expose_php = Off

date.timezone = 'Asia/Tokyo'

post_max_size = 100M

upload_max_filesize = 100M

Apacheの設定

httpd.confを編集する。

vi /usr/local/apache2/conf/httpd.conf

libphp7.soが記入されていることを確認する。

httpd.conf
LoadModule php7_module        modules/libphp7.so

以下の項目をLoadModuleの下に追記する。(場所の指定はありませんが、わかりやすくするため)

httpd.conf
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

以上で、apacheを再起動しエラーが表示されず、apacheで設定したhtml及びphpの初期ディレクトリ(標準では/usr/local/apache2/htdocs)にindex.phpを作成phpinfo()コマンドを保存し、ブラウザでPHPの設定内容が表示されればWebサーバ、PHP共に起動が成功です。
この状態ではHTTP2及びHTTPS(SSL)にはなっていません。

index.php
<?php
    phpinfo();
?>

参考

CentOS7.1 64bitのyumリポジトリにEPELを追加 | kakiro-web カキローウェブ
PHP compile errors – CentOS WebPanel Wiki


目次

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