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 見下篇。

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more