php 7 のインストール
Scientific Linux 7 の環境に、PHP をソースからインストールします。最新版は公式サイトで確認してください。
PHP をインストールする前に、まず必要なライブラリ類をインストールしておきます。
$ yum -y install \ libxml2-devel \ bzip2-devel \ libcurl-devel \ libjpeg-devel \ libpng-devel \ freetype-devel
libmcrypt, libmcrypt-devel のインストール
epel レポジトリからインストールします。epel レポジトリは以下の手順でインストールします。
$ rpm -Uvh http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/epel-release-latest-7.noarch.rpm
/etc/yum.repos.d/epel.repo を編集し、普段は epel を参照しないようにしておきます。
[epel] name=Extra Packages for Enterprise Linux 6 - $basearch #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch failovermethod=priority enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
epel から libmcrypt をインストールします。
$ yum --enablerepo=epel -y install libmcrypt-devel
php のインストール
php のソースコードをダウンロードして解凍します。
$ wget --trust-server-name http://jp2.php.net/get/php-7.0.3.tar.gz/from/this/mirror $ tar -zxvf php-7.0.3.tar.gz -C /usr/src
$ cd /usr/src/php-7.0.3 $ ./configure \ --with-apxs2=/usr/local/httpd/bin/apxs \ --with-openssl=/usr/local/openssl \ --enable-mbstring \ --enable-mbregex \ --enable-bcmath \ --enable-sockets \ --enable-libxml \ --enable-xml \ --with-curl \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-zlib \ --with-bz2 \ --with-mysqli=mysqlnd \ --with-gettext \ --with-mcrypt \ --enable-calendar \ --enable-pdo \ --with-pdo-mysql=mysqlnd
問題無ければ make してみる。また、make test して問題無いことを確認します。
$ make $ make test
何行か警告がでましたが、一応テストにはパスしているということなのでそのまま続行します。
Temporary leak on exception [Zend/tests/temporary_cleaning_001.phpt ] (warn: XFAIL section but test passes)
インストール
$ make install Wrote PEAR system config file at: /usr/local/etc/pear.conf You may want to add: /usr/local/lib/php to your php.ini include_pat h /usr/src/php-7.0.3/build/shtool install -c ext/phar/phar.phar /usr/ local/bin ln -s -f phar.phar /usr/local/bin/phar Installing PDO headers: /usr/local/include/php/ext/pdo/
指示通り /usr/local/lib に PHP の設定ファイルである php.ini を置きます。
$ cp /usr/src/php-7.0.3/php.ini-development /usr/local/lib/php.ini
必要最低限だけ修正しておきましょう。
<?=$_variable; ?> みたいな記述を許可する
short_open_tag = on
実行エラーを表示させる(php.ini-development では「on」)
サイト公開する際は「off」にした方がいいかも
display_errors = On
php を介したファイルアップロードを行う必要が無ければ「off」
最大アップロードサイズはお好みで。
;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; ; Whether to allow HTTP file uploads. ; http://php.net/file-uploads file_uploads = On ; Temporary directory for HTTP uploaded files (will use system default if not ; specified). ; http://php.net/upload-tmp-dir ;upload_tmp_dir = ; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 8M 802 ; Maximum number of files that can be uploaded via a single request 803 max_file_uploads = 20 804
他のサイトからページを読込みことがある場合は「on」
セキュリティ的には許容したくない感じ…。
(悪意ある外部サイトを include されたりすると大変なことになります。マヂで。)
; Whether to allow the treatment of URLs (like http:// or ftp://) as files. ; http://php.net/allow-url-fopen allow_url_fopen = On ; Whether to allow include/require to open URLs (like http:// or ftp://) as files. ; http://php.net/allow-url-include allow_url_include = Off
mbstring 周り。文字コードは UTF-8 に統一しておいた方がいいでしょう。
[mbstring] ; language for internal character representation. ; http://php.net/mbstring.language mbstring.language = Japanese ; internal/script encoding. ; Some encoding cannot work as internal encoding. ; (e.g. SJIS, BIG5, ISO-2022-*) ; http://php.net/mbstring.internal-encoding mbstring.internal_encoding = UTF-8 ; http input encoding. ; http://php.net/mbstring.http-input mbstring.http_input = auto ; http output encoding. mb_output_handler must be ; registered as output buffer to function ; http://php.net/mbstring.http-output mbstring.http_output = UTF-8
タイムゾーンの設定。
[[Date]] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = Asia/Tokyo
apache の 設定ファイル(httd.conf)を編集します。
LoadModule php7_module modules/libphp7.so # 以下を追加 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
インデックスページの設定。
<IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
apache を再起動します。
/etc/rc.d/init.d/httpd restart
簡単なテストページを作成して php の動作を確認します。
<!--?php phpinfo(); ?-->
http://サーバのアドレス/test.php を開いて以下のように phpinfoページが表示されればOK