0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

phpenvでphpをインストール

Posted at

環境

CentOS release 6.8 (Final)

やったこと

git clone git://github.com/phpenv/phpenv.git ~/.phpenv
echo 'export PATH="$HOME/.phpenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(phpenv init -)"' >> ~/.bash_profile
exec $SHELL -l
exit

git clone https://github.com/php-build/php-build $(phpenv root)/plugins/php-build
cd .phpenv/plugins/php-build/share/php-build/definitions
vi 7.2.15
  • apache用のモジュール作成のため、以下を1行目に追加(apxsの場所は要確認)
configure_option "--with-apxs2" "/usr/sbin/apxs"
  • その他、必要なモジュールがあれば
configure_option "--enable-calendar"
configure_option "--with-pear"
configure_option "--enable-sysvmsg"
configure_option "--enable-wddx"
configure_option "--with-gettext"

# mhashは下記では有効になりませんでした
configure_option "--with-mhash"
yum install re2c libxml2 libxml2-devel openssl-devel bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng-devel libicu-devel readline-devel libtidy-devel libxslt-devel httpd-devel
phpenv install 7.2.15
  • 切り替える場合
phpenv global 7.2.15
phpenv rehash
  • imagickなど、peclを入れる場合(切り替え後に実行)
cd .phpenv/plugins/
git clone https://github.com/felipecwb/pecl-build.git
phpenv pecl imagick
phpenv pecl apcu
phpenv pecl mcrypt

# imagickのtestでエラーが出てインストールできなかったので、無理やりテストを飛ばして入れた(どうやら新し目のImageMagickだとなる模様。最新で確認)
cd ~/.phpenv/plugins/pecl-build/bin
./pecl-build imagick -p ~/.phpenv/versions/7.2.15/bin/phpize -i ~/.phpenv/versions/7.2.15/bin/php-config --skip-test
  • php.iniを修正
date.timezone = "Asia/Tokyo"

など

  • Apache再起動

phpenvで5系と7系を使用する場合
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/php.conf
を確認する。
参考:https://qiita.com/aat00000/items/23df738116bf724cadc4

よければ

service httpd restart
  • すぐに切り替えない場合
[abrt] httpd: httpd killed by SIGSEGV

というメールが来るので、/etc/httpd/conf/httpd.confの

LoadModule php7_module        /usr/lib64/httpd/modules/libphp7.so

をコメントアウトする。

各ユーザのcliでphpのバージョンが古い問題

上記のやり方だと、rootでやってしまっているため、rootのみしかcliのphpはバージョンが変わらない。

# 移動
mv /root/.phpenv /usr/local/phpenv

# 各ユーザ(deployerのためにbashrcに書いたほうがいいです)
vi ~/.bashrc
export PATH="$HOME/.phpenv/bin:$PATH"
↓
export PATH="/usr/local/phpenv/bin:$PATH"

# phpenv pecl imagickで入れたものが反映されないので、シンボリックリンクはる
ln -s /usr/local/phpenv/ /root/.phpenv

systemctl restart httpd
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?