centos7 安装php7

How to Install PHP 7 on CentOS 7 (Red Hat/Fedora family)

PHP 7 brings such profound improvements that the lucky 7 as a version number seems more than justified. The upgrade is easy, painless, and takes just a couple of quick steps. Here is how to do it.

#PHP 7.0.1 released, RPMs already available in #remirepo 4 #fedora #rhel & #centos via…

CLICK TO TWEET

ADVANCE WARNING: RedHat intends to transition theRHEL/Fedorafamily from the popular package manageryumto its next iteration,DNF(dnf), short fordandified yum. It supportsRPM,libsolv, andhawkeylibraries. DNF (which inherited some qualities from both yum and aptitude) has been released forFedorawithuser and admin guidesalready up to date, so feel free to get acquainted with it. Use it the way you would work with yum.Iforwhenthis change may impactCentOSorAmazon Linuxisn’t clear yet. You can enable DNF in Fedora 18 and later, then install the binary using good old-fashioned yum; for other distributions you have tocompile DNF from source.

To get your hands on a working installation of PHP 7, you can use either the old yum or dnf (when in doubt, consult thecommand reference).

In Remi’s RPM repository, PHP RPMs have been renamed php70 in order to allow installation alongside the default PHP of your CentOS/RHEL/Fedora (if there is one on your system). The FPM service (php70-php-fpm) listens on the default port 9000 so it may need adjusting should another version of PHP be already running.

Follow these steps to install PHP 7 on CentOS with php-fpm, the server API or SAPI of choice for NGINX, using the Remi repository, on x86_64. You must be root (sudo su, otherwise prepend the relevant commands withsudoto execute them as root).

Step 1. Get yourself the REMI repo

Install the Remi repository (#remirepo for #fedora, #rhel and #centos) with these commands (you must be root, see the paragraph above):

wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm

sudo rpm -Uvh remi-release-7*.rpm

Step 2. Install PHP 7

Install PHP 7 from the remi repository:

yum --enablerepo=remi-php70 install php70-php

Step 3. Install PHP extensions

Install PHP modules using the remi repository (the example is a recommended configuration):

yum --enablerepo=remi-php70 install php70-php-pear php70-php-bcmath php70-php-pecl-jsond-devel php70-php-mysqlnd php70-php-gd php70-php-common php70-php-fpm php70-php-intl php70-php-cli php70-php php70-php-xml php70-php-opcache php70-php-pecl-apcu php70-php-pecl-jsond php70-php-pdo php70-php-gmp php70-php-process php70-php-pecl-imagick php70-php-devel php70-php-mbstring php70-php-mcrypt

To find out which other extensions are available, use search with yum:

yum search php70

Speaking of extensions: ereg, mssql, sybase_ct and mysql have been removed from PHP.

In order to enable the remi repository only during software installation (that is: only when you need it), use the–enablerepo=remioption with yum. For example like this:

sudo yum --enablerepo=remi install php-tcpdf

To update your already installed packages using the Remi repository, you would enter this command:

yum --enablerepo=remi update remi-release

Step 4. Start PHP

To start PHP (once) use this command:

service php70-php-fpm start

or

systemctl start php70-php-fpm

Step 5. Enable automatic launch of PHP 7 on system startup

Enable automatic launch of the PHP interpreter on system startup on CentOS 7/Red Hat/Fedora, use this command:

systemctl enable php70-php-fpm

The output of this command should resemble this line:

ln -s '/usr/lib/systemd/system/php70-php-fpm.service' '/etc/systemd/system/multi-user.target.wants/php70-php-fpm.service'

You can verify the current status of PHP 7 using this command:

systemctl status php70-php-fpm

[root@ip-16-0-0-170 centos]# systemctl status php70-php-fpm

php70-php-fpm.service - The PHP FastCGI Process Manager

Loaded: loaded (/usr/lib/systemd/system/php70-php-fpm.service; enabled)

Active: active (running) since Thu 2015-12-10 05:29:25 UTC; 2s ago

Main PID: 2102 (php-fpm)

Status: "Ready to handle connections"

CGroup: /system.slice/php70-php-fpm.service

├─2102 php-fpm: master process (/etc/opt/remi/php70/php-fpm.conf)

├─2103 php-fpm: pool www

├─2104 php-fpm: pool www

├─2105 php-fpm: pool www

├─2106 php-fpm: pool www

└─2107 php-fpm: pool www

Dec 10 05:29:25 ip-12-3-4-170.ec2.internal systemd[1]: Started The PHP FastCGI Process Manager.

This output also shows you that php-fpm pools, while running, have not been configured yet.

If you also want to set up MySQL/MariaDB, you may want to read this post:High-Stakes, High-Security LEMP Setup: Nginx with MariaDB/MySQL, and PHP 7.x on CentOS 7 (RHEL/Fedora) with SELinux

Subscribe to our newsletter and we will keep you up to date.

来源:https://www.cloudinsidr.com/content/how-to-install-php-7-on-centos-7-red-hat-rhel-7-fedora/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,524评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,869评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,813评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,210评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,085评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,117评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,533评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,219评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,487评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,582评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,362评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,218评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,589评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,899评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,176评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,503评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,707评论 2 335

推荐阅读更多精彩内容