LoginSignup
4
4

More than 5 years have passed since last update.

PHP 7.0をVagrant上のCentOS 7にインストール

Last updated at Posted at 2015-05-15

Vagrant上のCentOS7でPHP 7.0をビルド&インストールする方法です。
なお、私はVagrantもPHP初心者なので、不適切or余分な部分は適宜読み替えて下さい。

VagrantをCentOS 7で起動

参考:http://qiita.com/ms2sato/items/1bcdf6ef37af51ae0fd6
Vagrantfileに以下を記述し、CentOS7を設定します。

config.vm.box = "centos7"
config.vm.box_url = "https://f0fff3908f081cb6461b407be80daf97f07ac418.googledrive.com/host/0BwtuV7VyVTSkUG1PM3pCeDJ4dVE/centos7.box"

仮想マシンを起動し、httpdをインストールします。
(後のphpのビルドで必要なため、apxsも入れます)

$ vagrant up
$ vagrant ssh
$ sudo yum install httpd-devel

httpで接続できるよう、firewalldの設定を変更しておきます。
(/etc/firewalld/zones/public.xmlに追記)

<service name="http"/>

PHP 7.0をビルド

基本的には、
http://linoxide.com/linux-how-to/install-php-7-centos-7-fedora-21/
http://maplesystems.co.jp/blog/all/programming/9640.html
のものと同じです。
ただ、./configure のオプションは少々変更を加えています。
まず、ソースコードをダウンロードします。

$ sudo yum install git autoconf gcc bison
$ git clone https://git.php.net/repository/php-src.git

必要なライブラリをダウンロードします(余分なものがあるかもしれません)。

$ sudo yum install libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel libXpm-devel freetype-devel t1lib-devel gmp-devel mysql-devel aspell-devel recode-devel
$ sudo rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/7/x86_64/e/epel-release-7-5.noarch.rpm $ epelレポジトリのインストール
$ sudo yum --enablerepo=epel install libmcrypt-devel

PHP 7.0をビルドします。
./configureのオプションに関しては、上のページのものから--prefix, --with-mysqlを削除し、--with-apxs2を追加しています(ここも余分なものがあるかもしれません)。
なお、私の環境ではmakeの段階でwarningがでましたが、phpは動きました。

$ ./buildconf
$ ./configure --with-config-file-path=$HOME/php7/usr/etc --enable-mbstring --enable-zip --enable-bcmath --enable-pcntl --enable-ftp --enable-exif --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-curl --with-mcrypt --with-iconv --with-gmp --with-pspell --with-gd --with-apxs2 --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-xpm-dir=/usr --with-freetype-dir=/usr --with-t1lib=/usr --enable-gd-native-ttf --enable-gd-jis-conv --with-openssl --with-mysql=/usr --with-pdo-mysql=/usr --with-gettext=/usr --with-zlib=/usr --with-bz2=/usr --with-recode=/usr --with-mysqli=/usr/bin/mysql_config
$ make
$ sudo make install

ここまでくれば、php -v

PHP 7.0.0-dev (cli)

などと出るはずです。
あとは/etc/httpd/conf.d/php.confあたりに設定を書けば終わりです。

4
4
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
4
4