您的位置:首页 > 编程语言 > ASP

Raspberry Pi 3 Installing PHP 7

2018-01-26 14:59 561 查看


Installing PHP 7

While the Raspberry Pi has heaps of literature and technology revolving around JavaScript, Python, and other programming languages; PHP has consumed a lot of my time these days. A year ago, I would have snubbed the idea of using PHP in lieu of JavaScript as
my go to language but I’m now seeing a lot of influences, if not mergers between the two languages: PHP has obtained a beautiful dependency/package manager (composer/packagist) that is not unlike what’s available for JavaScript via NodeJS. Programming libraries
and projects such as ReactPHP mirror their JavaScript equivalent and now we’ve seen an incredible speed boost via the release of PHP 7. According to APIPlug.com, PHP 7 has been found to be a
lot faster than its predecessor (I’m still waiting for their PHP vs NodeJS speed comparison). What better way to compliment our new Raspberry Pi 3’s quad core capabilities than with the cutting edge performance found in PHP 7? So let’s get started installing
the cutting edge PHP 7 on the new Raspberry Pi 3.

To install PHP 7, we’ll need to gain access to the testing branch of Raspberry Pi’s Raspbian OS (aka under the codename: “stretch”). Start by editing the sources.list file used by apt-get by typing the following on the command line:
sudo nano /etc/apt/sources.list


The nano editor will open and you should be able to append the following line to the file, followed by pressing ctrl+x to exit and ‘y’ to save changes and press enter to confirm.
deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi


However, this will cause all updates and installs to come from “stretch” which isn’t considered stable. To avoid this, create a preferences file that will tell apt-get to obtain all packages from the current “jessie” release of Raspian first and fallback to
“stretch” to accessing the missing PHP 7 components:
sudo nano /etc/apt/preferences


Again, the nano editor will open and you can paste the following content to prioritize where packages come from. Pressing ctrl+x exit and ‘y’ to save changes and enter to confirm.
Package: *
Pin: release n=jessie
Pin-Priority: 600


Next, run update to download the latest package lists and get information on the newest versions of packages.
sudo apt-get update


Lastly, we can install PHP 7 with the following command (press ‘Y’ when prompted).
sudo apt-get install -t stretch php7.0


You can now check that PHP is install and it’s version by running:
php -v


You have the latest PHP 7 installed and running on Raspberry Pi!

测试PHP页面在Apache中能否被正常解析

sudo nano /var/www/html/phpinfo.php

<?php phpinfo(); ?>

如果无法正常显示,尝试安装

sudo apt-get install php7.0 libapache2-mod-php7.0 -y
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: