在Nitrous.io上安装PHP扩展

Inspired by a comment on my previous article, I realized Nitrous was still a bit too complicated to customize properly. In this tutorial, we’ll glide through installing cURL and Phalcon on a Nitrous.io PHP box.

受到我对上一篇文章的评论的启发,我意识到Nitrous仍然有点太复杂,无法正确自定义。 在本教程中,我们将介绍如何在Nitrous.io PHP框上安装cURL和Phalcon。

cURL is a bundled PHP library that is often installed alongside PHP. It’s included in the PHP source, but during installation a flag needs to be passed to PHP in order for it to include and activate cURL. Phalcon is a high-performance C-based MVC framework. We’ve written about it before. Phalcon is a third party extension, and thus not bundled with PHP.

cURL是捆绑PHP库,通常与PHP一起安装。 它包含在PHP源代码中,但是在安装过程中,需要将一个标志传递给PHP,以使其包含和激活cURL。 Phalcon是基于C的高性能MVC框架。 我们之前已经写过 。 Phalcon是第三方扩展,因此未与PHP捆绑在一起。

入门 (Getting started)

To get started with a Nitrous.io PHP box, see my previous article. After the initial short procedure (you can skip the whole Composer and Laravel business), you’ll have PHP installed, but without the extensions we need. To verify cURL is missing, try adding the following content to your index.php file in the default www folder:

要开始使用Nitrous.io PHP框,请参阅我的上一篇文章 。 经过最初的简短过程(您可以跳过整个Composer和Laravel业务),您将安装PHP,但是没有我们需要的扩展。 要验证cURL是否丢失,请尝试将以下内容添加到默认www文件夹中的index.php文件中:

<?php
    echo "Curl is" . ((function_exists('curl_version')) ? "" : " not") . " installed";

Previewing in the browser on the default port 3000 will show that cURL is, obviously, not installed. It is, however, installed system-wide. You can verify this by just checking the version in the console, and getting the following output:

在浏览器中的默认端口3000上进行预览将明显显示未安装cURL。 但是,它是在系统范围内安装的。 您可以通过仅检查控制台中的版本并获得以下输出来验证这一点:

alt

Thus, we only need the PHP extension to be able to use it. Usually, PHP’s cURL extension is installed with PHP with the flag --with-curl[=DIR] while executing the configure command. In other scenarios, it’s easily installable by calling something as simple as sudo apt-get install php5-curl. However, in our case, neither of these appraches will work. The former cannot be achieved because PHP is already installed and the source code is no longer on the machine, and the latter is unavailable to us because we don’t have sudo access.

因此,我们只需要PHP扩展即可使用它。 通常,在执行configure命令时,PHP的cURL扩展名随带有--with-curl[=DIR]标志PHP一起安装。 在其他情况下,可以通过调用sudo apt-get install php5-curl简单sudo apt-get install php5-curl轻松安装。 但是,就我们而言,这两种方法都不起作用。 前者无法实现,因为已经安装了PHP,并且源代码不再在计算机上,而后者对我们不可用,因为我们没有sudo访问权限。

What we’ll be doing next is building cURL from PHP’s source code, and adding it into our configuration manually.

接下来,我们将从PHP的源代码构建cURL,并将其手动添加到我们的配置中。

下载PHP的源代码 (Downloading PHP’s source code)

If we check the PHP version on Nitrous.io at this moment, it’s 5.5.8. The latest PHP version is, however, 5.5.9. To avoid any potential incompatibility issues, we’ll clone the exact version we’re building the extension for.

如果我们现在在Nitrous.io上检查PHP版本,则为5.5.8。 但是,最新PHP版本是5.5.9。 为避免任何潜在的不兼容问题,我们将克隆为其构建扩展程序的确切版本。

Browse through the old archives and pick the appropriate version. When you find a link you like, do the following (Note that the tools directory should exist if you followed along with the last article; if not, create it):

浏览旧的档案并选择适当的版本。 当您找到喜欢的链接时,请执行以下操作(请注意,如果您紧跟着上一篇文章,则应该存在tools目录;否则,请创建它):

cd /home/action/.tools
wget http://at1.php.net/distributions/php-5.5.8.tar.bz2

Uncompress the archive by running tar -xjvf is you downloaded the .bz2 file, or tar -xzvf if you downloaded .gz. This will produce a folder with the same name as the archive. We now have PHP’s source code for version 5.5.8.

解压缩运行存档tar -xjvf是你下载的.bz2文件,或tar -xzvf如果下载.gz 。 这将产生一个与存档名称相同的文件夹。 现在,我们有了5.5.8版PHP源代码。

构建cURL扩展 (Building the cURL extension)

It’s important to note that this procedure can be applied to any extension bundled with PHP that hasn’t been installed by default. We’re using cURL in this article due to the comment on the previous one, and due to the fact that it’s a popular extension. Enter the extensions folder of the PHP source code.

重要的是要注意,此过程可以应用于默认情况下未安装的与PHP捆绑在一起的任何扩展。 由于对前一篇评论,并且由于它是一个受欢迎的扩展,因此我们在本文中使用cURL。 输入PHP源代码的扩展文件夹。

cd php-5.5.8/ext

All the available bundled extensions reside here, with their full source code. CD into the curl folder and run the procedure below:

所有可用的捆绑扩展程序及其完整源代码都位于此处。 将CD放入curl文件夹并运行以下步骤:

cd curl
/home/action/.parts/bin/phpize
./configure --with-curl
make
make install

This builds the extension from source, places the curl.so file into the modules subfolder, and copies it to the PHP extensions folder in /home/action/.parts/packages/php5/5.5.8/lib/extensions/no-debug-zts-20121212/.

这将从源代码构建扩展,将curl.so文件放入modules子文件夹,并将其复制到/home/action/.parts/packages/php5/5.5.8/lib/extensions/no-debug-zts-20121212/PHP扩展文件夹中/home/action/.parts/packages/php5/5.5.8/lib/extensions/no-debug-zts-20121212/

激活cURL扩展 (Activating the cURL extension)

To activate the extension, all we need to do is add a line to our php.ini and restart the web server. Activate showing hidden files in the file browser panel, and go to ~/.parts/etc/php5. There, edit the php.ini file: find the string “Module Settings”, then above it, add the line extension=curl.so:

要激活扩展,我们要做的就是在php.ini添加一行并重新启动Web服务器。 激活在文件浏览器面板中显示隐藏文件的功能,然后转到~/.parts/etc/php5 。 在那里,编辑php.ini文件:找到字符串“ Module Settings”,然后在其上方添加以下代码行extension=curl.so

alt

Save the file, and run parts restart apache2 in the console. You might get an error saying something like

保存文件,然后运行parts restart apache2 ,在控制台中parts restart apache2 。 您可能会收到类似以下内容的错误消息

(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:3000
no listening sockets available, shutting down
AH00015: Unable to open logs
parts: ERROR: "/home/action/.parts/packages/apache2/2.4.7/bin/apachectl start" failed                            
Aborting!

If you do, just run the same command again and it should work.

如果这样做,只需再次运行相同的命令即可。

Now try to preview the index.php file from before on port 3000 again, and if all went well, the message should say cURL is now installed.

现在,尝试再次从以前在端口3000上预览index.php文件,如果一切顺利,则消息应显示cURL已安装。

alt

You can make extra sure by changing the contents back to phpinfo() and looking for the cURL section:

您可以通过将内容改回phpinfo()并查找cURL部分来确保更多的确定:

alt

下载并构建Phalcon (Downloading and building Phalcon)

As per instructions on their website, we clone the repo and then build the extension.

按照他们网站说明,我们克隆存储库,然后构建扩展。

cd ~/.tools
git clone --depth=1 git://github.com/phalcon/cphalcon.git
cd cphalcon/build
./install

In the last step, we don’t need sudo because the action account Nitrous boxes use is quite elevated, having permissions beyond those of a typical user account.

在最后一步中,我们不需要sudo因为Nitrous框使用的action帐户已得到很大提升,其权限超出了典型用户帐户的权限。

As soon as the compilation completes, Phalcon’s build script automatically copies the phalcon.so file into the PHP extensions folder. You can then follow the same procedure as above to activate the extension. Enter php.ini and add extension=phalcon.so into the mix, as shown below:

编译完成后,Phalcon的构建脚本会自动将phalcon.so文件复制到PHP扩展文件夹中。 然后,您可以按照上述相同的步骤激活扩展程序。 输入php.ini并将extension=phalcon.so添加到混合中,如下所示:

alt

Re-checking the phpinfo() output from before after running parts restart apache2 should show Phalcon as installed:

在重新运行parts restart apache2后重新检查phpinfo()输出,然后parts restart apache2应该显示Phalcon已安装:

alt

结论 (Conclusion)

In this tutorial, we’ve demonstrated the ease of installing custom PHP extensions on Nitrous.io. This procedure can be applied to installing PHP extensions anywhere – you don’t need to rebuild the entire PHP source code just to add a bundled extension into the mix. In time, as popularity rises, Nitrous may add a simpler way to pull in extensions – perhaps even through “parts”, their package manager – but for now, we’re stuck with this manual process. While tedious, it certainly isn’t difficult.

在本教程中,我们演示了在Nitrous.io上安装自定义PHP扩展的简便性。 此过程可以应用于在任何地方安装PHP扩展-您无需重建整个PHP源代码,只需要将捆绑的扩展添加到组合中即可。 随着时间的推移,随着流行度的提高,Nitrous可能会添加一种更简单的引入扩展的方法-甚至可以通过其软件包管理器的“部件”进行扩展-但就目前而言,我们仍停留在此手动过程中。 尽管很乏味,但这当然并不困难。

Have you played around on Nitrous yet? If so, what have you built? If not, what’s stopping you? Let us know in the comments below!

你玩过Nitrous吗? 如果是这样,您建造了什么? 如果没有,那么阻止您的是什么? 在下面的评论中让我们知道!

翻译自: https://www.sitepoint.com/installing-php-extensions-nitrous-io/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值