heroku cli 安装_如何在Heroku上安装自定义PHP扩展

heroku cli 安装

In this tutorial, we’ll learn how to install custom extensions on Heroku. Specifically, we’ll be installing Phalcon.

在本教程中,我们将学习如何在Heroku上安装自定义扩展。 具体来说,我们将安装Phalcon

注册并设置 (Sign-up and Set up)

In order to use Heroku, you must sign up for a Heroku account. Heroku generally works with a command-line interface. To use that interface, you need to install the Heroku toolbelt package for your operating system. If you are using Linux, open up terminal and type the following command.

为了使用Heroku,您必须注册一个Heroku帐户。 Heroku通常使用命令行界面。 要使用该界面,您需要为您的操作系统安装Heroku工具带包。 如果您使用的是Linux,请打开终端并输入以下命令。

wget -qO- https://toolbelt.heroku.com/install.sh | sh

After installing the toolbelt, you’ll have access to the heroku command from your command shell. Authenticate using the email address and password you used when creating your Heroku account:

安装工具带之后,您将可以从命令外壳访问heroku命令。 使用创建Heroku帐户时使用的电子邮件地址和密码进行身份验证:

heroku login


Enter your Heroku credentials.
Email: fcopensuse@gmail.com
Password:
Could not find an existing public key.
Would you like to generate one? [Yn]
Generating new SSH public key.
Uploading ssh public key /home/duythien/.ssh/id_rsa.pub

Press enter at the prompt to upload your existing ssh key or create a new one, used for pushing code later on.

在提示符下按Enter键,以上传您现有的ssh密钥或创建一个新密钥,用于以后推送代码。

Phalcon is a third party extension, and thus not bundled with PHP. Phalcon requires the following components:

Phalcon是第三方扩展,因此未与PHP捆绑在一起。 Phalcon需要以下组件:

mbstring
mcrypt
openssl
PDO
PDO/Mysql
PDO/Postgresql
PDO/Sqlite
PDO/Oracle

mbstring and mcrypt are the main ones – mbstring is used by the templating engine (Volt), as well as some validators, the escaper and the filter, while mcrypt is used in the security component (generating secure hashes etc.)

mbstring和mcrypt是主要的-mbstring由模板引擎(Volt)以及某些验证器,转义符和过滤器使用,而mcrypt在安全组件中使用(生成安全哈希等)。

In order to install the elements above, we will use the PHP buildpack tool. Let’s explain what that means.

为了安装上述元素,我们将使用PHP buildpack工具。 让我们解释一下这是什么意思。

According to the official Heroku documentation, buildpacks provide the magic and flexibility that make running your apps on Heroku so easy. When you push your code, the buildpack is the component that handles the setting up of your environment so that your application can run. The buildpack can install dependencies, customize software, manipulate assets, and do anything else required to run your application. Heroku didn’t always have buildpacks, they are a new component that came with the Cedar stack.

根据Heroku的官方文档,buildpack提供的魔力和灵活性使在Heroku上运行应用程序变得如此容易。 当您推送代码时,buildpack是处理环境设置的组件,以便您的应用程序可以运行。 该构建包可以安装依赖项,自定义软件,操纵资产以及执行运行应用程序所需的其他任何事情。 Heroku并不总是具有buildpack,它们是Cedar堆栈附带的新组件。

You can get more information on these three steps and more through the buildpack documentation.

您可以通过buildpack 文档获取有关这三个步骤的更多信息,以及更多信息

To get started, we fork this code on github. Click the “Fork” button in the repository. To be able to work on the project, you will need to clone it to your local machine.

首先,我们将这段代码放在github上 。 单击存储库中的“ Fork”按钮。 为了能够处理该项目,您需要将其克隆到本地计算机上。

Run the following code:

运行以下代码:

git clone https://github.com/duythien/heroku-buildpack-php.git buildpack-php
cd buildpack-php

Create the phalcon.sh file in your $HOME/buildpack-php/bin directory with the following content:

使用以下内容在$HOME/buildpack-php/bin目录中创建phalcon.sh文件:

#!/bin/bash
# Build Path: /app/.heroku/php/
dep_url=git://github.com/phalcon/cphalcon.git
phalcon_dir=cphalcon
echo "-----> Building Phalcon..."

### Phalcon
echo "[LOG] Downloading PhalconPHP"
git clone $dep_url -q
if [ ! -d "$phalcon_dir" ]; then
  echo "[ERROR] Failed to find phalconphp directory $phalcon_dir"
  exit
fi
cd $phalcon_dir/build

# /app/php/bin/phpize
# ./configure --enable-phalcon --with-php-config=$PHP_ROOT/bin/php-config
# make
# make install
BUILD_DIR=$1
ln -s $BUILD_DIR/.heroku /app/.heroku
export PATH=/app/.heroku/php/bin:$PATH
bash ./install
cd
echo "important extension phalcon into php.ini"
echo "extension=phalcon.so" >> /app/.heroku/php/etc/php/php.ini

This file will install Phalcon, but Heroku must be instructed to execute it. To do that, you will have to edit the bin/compile file and add the following line somewhere in there:

该文件将安装Phalcon,但必须指示Heroku执行它。 为此,您将必须编辑bin / compile文件,并在其中添加以下行:

[...]
source $BP_DIR/bin/phalcon
[...]

In addition, you need to add the text extension=phalcon.so to the file “conf/php/php.ini“:

另外,您需要将文本extension=phalcon.so添加到文件“ conf / php / php.ini ”中:

[....]
extension=phalcon.so
; Local Variables:
; tab-width: 4
; End:

Now we can push our new buildpack up:

现在我们可以增加新的构建包:

git add -A
git commit -m "edit php.ini and create phalcon file"
git push origin master

在Heroku上创建一个新的应用程序 (Create a new application on Heroku)

Create a directory for your app and change to it:

为您的应用创建目录并更改为:

mkdir phalcon-dev
cd phalcon-dev

In addition, you need to give Heroku an indication that this application is a PHP application. To do this, create an empty file called composer.json. On a Unix system, you can create this file like so:

另外,您需要给Heroku一个表明该应用程序是PHP应用程序的指示。 为此,请创建一个名为composer.json的空文件。 在Unix系统上,您可以这样创建此文件:

touch composer.json

Then, execute the following to initalize the repo for our app:

然后,执行以下命令为我们的应用初始化存储库:

git init
git add -A
git commit -m" first commit"

To create a new Heroku application that you can push to, use the CLI’s create command:

要创建可以推送到的新的Heroku应用程序,请使用CLI的create命令:

heroku create phalcon-dev

Creating phalcon-dev... done, stack is cedar
http://phalcon-dev.herokuapp.com/ | git@heroku.com:phalcon-dev.git
Git remote heroku added

This creates the application on Heroku ready and waiting for our code, and also attaches a git remote to our local codebase. You are now ready to deploy the application, but there is no code yet. Follow the next section to add some content to your application.

这将在Heroku上准备就绪并等待我们的代码的应用程序,并将git远程附加到我们的本地代码库。 现在您可以部署应用程序了,但是还没有代码。 请遵循下一部分,向您的应用程序添加一些内容。

Your composer.json file should be made to look like this:

您的composer.json文件应如下所示:

{
  "require": {
    "php": "5.5.12"
  }
}

It will automatically install extensions such as mcrypt, mbstring, etc on Heroku. If you need mongodb, memcached, etc, modify the file further:

它将在Heroku上自动安装扩展名,例如mcrypt,mbstring等。 如果您需要mongodb,memcached等,请进一步修改文件:

{
  "require": {
    "php": "5.5.12",
    "ext-memcached": "*",
    "ext-mongo": "*"
  }
}

Now Heroku will enable the corresponding PHP extensions and put them into the support/build/extensions/no-debug-non-zts-20121212 folder. Next, create a test.php file with the following content:

现在,Heroku将启用相应PHP扩展并将其放入support / build / extensions / no-debug-non-zts-20121212文件夹。 接下来,创建一个具有以下内容的test.php文件:

<?php phpinfo() ; ?>

Finally, let’s deploy the Phalcon installation:

最后,让我们部署Phalcon安装:

heroku config:set BUILDPACK_URL=https://github.com/duythien/heroku-buildpack-php
git add -A
git commit -am "installl phalcon"
git push heroku master

The first command means override the Heroku default buildpack by specifying a custom buildpack in the BUILDPACK_URL config var. After a few minutes, the results are as follows:

第一个命令意味着通过在BUILDPACK_URL config var中指定一个自定义buildpack来覆盖Heroku的默认buildpack。 几分钟后,结果如下:

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /app/.heroku/php/lib/php/extensions/no-debug-non-zts-20121212/

Thanks for compiling Phalcon!
Build succeed: Please restart your web server to complete the installation
important extension phalcon into php.ini
-----> Discovering process types
       Procfile declares types -> (none)
       Default types for PHP   -> web

-----> Compressing... done, 124.0MB
-----> Launching... done, v8
       http://phalcon-dev.herokuapp.com/ deployed to Heroku

To git@heroku.com:phalcon-dev1.git
   4f1d993..e0936a5  master -> master

This has taken our code, pushed it to Heroku, identified it, and run a build process against it, making it ready for deployment. Now our application is live on the Internet! To verify this, open it now:

这已经占用了我们的代码,将其推送到Heroku,对其进行了识别,并针对它运行了构建过程,使其可以进行部署。 现在我们的应用程序可以在Internet上运行了! 要验证这一点,请立即打开它:

heroku open test.php

If everything goes fine, you should see the following screen in your browser:

如果一切正常,您应该在浏览器中看到以下屏幕:

phpinfo

配置Web根并部署示例站点 (Configure the web root and deploy the sample site)

Now comes the tricky part that is specifying the web root. Specifying the web root needs a little bit more work and background information. The Phalcon website application’s root in the git tree is /app/phalcon-website/public. For Heroku, by default, the web root is the root of the git-tree. That directory is internally mapped to /app. To change this, we need to create a so called Procfile that starts a sh-script each time the Heroku app web-node starts. That script then modifies the server configuration and includes your own config which is setting the web root to /app/phalcon-website/public. Create a Procfile file with the following content (if you’re using Apache):

现在是指定Web根目录的棘手部分。 指定Web根目录需要更多的工作和背景信息。 Phalcon网站应用程序在git树中的根目录是/app/phalcon-website/public 。 对于Heroku,默认情况下,Web根目录是git-tree的根目录。 该目录在内部映射到/app 。 要更改此设置,我们需要创建一个称为Procfile的文件,该文件在每次Heroku应用程序Web节点启动时都会启动sh脚本。 然后,该脚本修改服务器配置,并包含您自己的配置,该配置将Web根目录设置为/app/phalcon-website/public 。 创建具有以下内容的Procfile文件(如果使用的是Apache):

web: vendor/bin/heroku-php-apache2 phalcon-website/public

Clone the Phalcon website into the repo folder, and when it’s done, the git push command sends all of the commits on your local master to the central repository.

Phalcon网站克隆到repo文件夹中,完成后,git push命令会将本地主服务器上的所有提交发送到中央存储库。

cd && cd phalcon-dev
git clone --depth=1 http://github.com/phalcon/website phalcon-website
git add Procfile phalcon-websiste/
git commit -am " test phalcon website"
git push heroku master

Visit the app’s public URL and voila, you have a running Phalconphp.com clone on Heroku here.

访问应用程序的公共URL,瞧,你有一个运行Phalconphp.com克隆在Heroku 这里

Phalcon website

结论 (In conclusion)

Installing Phalcon (or any other PHP extension) on Heroku is obviously neither easy nor simple but if you use buildpacks, it becomes much more approachable.

在Heroku上安装Phalcon(或任何其他PHP扩展)显然既不容易也不简单,但是如果使用buildpacks,它将变得更加容易实现。

Leave your feedback in the comments below and, as always, please share this article if you liked it!

将您的反馈留在下面的评论中,和往常一样,如果您喜欢它,请分享这篇文章!

翻译自: https://www.sitepoint.com/install-custom-php-extensions-heroku/

heroku cli 安装

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值