DEV Community

Cover image for CentOS 7 裝 PHP 7
Leon
Leon

Posted on • Originally published at editor.leonh.space

1

CentOS 7 裝 PHP 7

參考 CentOS wiki 文章〈Using PHP 7.x on CentOS 7.4〉的前半部份。

預設的軟體庫只有 PHP 5,要啟用 CentOS Software Collections 這個庫才會有 PHP 7。

設定 Software Collections 庫:

> sudo yum install centos-release-scl
Enter fullscreen mode Exit fullscreen mode

然後就可以裝 PHP 7 了:

> sudo yum install rh-php72
Enter fullscreen mode Exit fullscreen mode

一些有依賴到的套件也都會一併裝上。

裝上是裝上,是裝到那去呢?看這篇:〈What Files Are In a RPM Package?〉。

路徑在 /opt/rh/rh-php72/ 內。用 scl 把 PHP 啟用

> sudo scl enable rh-php72 bash
Enter fullscreen mode Exit fullscreen mode

這樣會執行一個新的 bash session,並且把那 PHP 7 引入 path 內,可是重開機就失效了…。

再參考一下〈PHP 7.0 or 7.1 on RHEL or CentOS〉這篇的作法,在 /etc/profile.d/rh-php72.sh 建一個小 shell script 讓它在登入時自動執行,把那 PHP 7 自動加入 path 內:

#!/bin/bash
source scl_source enable rh-php72
Enter fullscreen mode Exit fullscreen mode

把這支 script 設為可執行以便日後手動使用:

> sudo chmod a+x /etc/profile.d/scl.sh
Enter fullscreen mode Exit fullscreen mode

設定 nginx * PHP 見下篇。

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️