Nginx,PHP5.5和Phalcon在OpenShift上

It seems like cloud deployment environments are all the rage these years – from AWS to Google App Engine, Windows Azure to DigitalOcean, and more popping up every month. With all these environments, it's important to be able to deploy the software you need.

这些年来,似乎云部署环境风靡一时-从AWS到Google App Engine,从Windows Azure到DigitalOcean,每个月都有更多的出现。 在所有这些环境中,重要的是能够部署所需的软件。

In this tutorial, adapted from the step by step trial and error procedure of duythien, and with his full blessing, we'll cover the installation procedure of Phaclon on yet another environment: OpenShift. The procedure is bloody – OpenShift does not make it easy for us to deploy custom environments – but the rewards are well worth it.

在本教程中,根据duythien的逐步试验和错误程序改编而来,并在他的全力支持下,我们将介绍Phaclon在另一个环境上的安装过程: OpenShift 。 该过程很繁琐– OpenShift不能使我们轻松地部署自定义环境–但是值得付出的回报是值得的。

Note: The repo used in this example was originally cloned from Boekkooi. He keeps his Openshift starter repo up-to-date, so if you need to get a custom PHP+Nginx Openshift environment up and running fast, use his original, then just plug the Phalcon procedure into the mix.

注意:此示例中使用的存储库最初是从Boekkooi克隆的。 他保持最新的Openshift初学者回购,因此,如果您需要启动自定义PHP + Nginx Openshift环境并快速运行,请使用其原始版本,然后将Phalcon过程插入混合。

起步 (Starting out)

Make an account on OpenShift. They offer a free tier we'll be taking advantage of.

OpenShift上注册一个帐户。 他们提供了我们将要利用的免费套餐

As is usually the case with cloud environments, OpenShift has their own tools too. Follow the RHC tools installation procedure. I chose "spphalcon" as the namespace during the final part of the rhc setup step.

与云环境一样,OpenShift也拥有自己的工具。 请遵循RHC工具的安装过程 。 在rhc setup步骤的最后部分中,我选择了“ spphalcon”作为名称空间。

Under https://openshift.redhat.com/app/console/applications select "Create your first application now" and choose "Do It Yourself" – the option should be at the bottom of the screen.

https://openshift.redhat.com/app/console/applications下,选择“立即创建您的第一个应用程序”,然后选择“自己动手做” –该选项应位于屏幕底部。

alt

Give the app a name – at this point you'll notice the namespace you previously defined in the rhc setup is reflected in the public URL of your app.

给应用程序起个名字-此时,您会注意到先前在rhc设置中定义的名称空间反映在应用程序的公共URL中。

Note: a "server" on OpenShift is called a cartridge.

注意:OpenShift上的“服务器”称为盒带。

创建和克隆应用程序 (Creating and cloning an application)

After you click "Create Application" and wait a few minutes, the next screen will show you instructions on how to download and modify the code for your app.

单击“创建应用程序”并等待几分钟后,下一个屏幕将向您显示有关如何下载和修改应用程序代码的说明。

alt

Clone the code using these instructions now.

立即按照这些说明克隆代码。

辅助仓库 (A helper repo)

When the cloning is done, enter the folder with cd phalcon and clone another repository inside the first one:

克隆完成后,进入带有cd phalcon的文件夹,并在第一个仓库cd phalcon另一个仓库:

git clone https://github.com/duythien/openshift-diy-nginx-php

Enter this newly created folder, and copy the .openshift folder to the parent folder – the folder which contains your main application code you previously cloned. You might be asked to overwrite some files – accept all overwrites.

输入此新创建的文件夹,然后将.openshift文件夹复制到父文件夹–包含先前克隆的主要应用程序代码的文件夹。 可能会要求您覆盖某些文件-接受所有覆盖。

cd openshift-diy-nginx-php
cp -R .openshift ../

We also need to refresh permissions, as per instructions on the original helper repo:

我们还需要按照原始帮助程序仓库上的说明刷新权限:

git update-index --chmod=+x -- $(git ls-files .openshift/action_hooks/*)

You can remove the openshift-diy-nginx-php directory, we no longer need it. We only needed its .openshift subfolder.

您可以删除openshift-diy-nginx-php目录,我们不再需要它。 我们只需要它的.openshift子文件夹。

Now add the changes, commit, and push:

现在添加更改,提交并推送:

git add -A
git commit -am 'Added .openshift folder'
git push

What gets initiated after this step is called a build process, and your DIY app will be stopped in order to read the contents of the .openshift folder and react accordingly. In our case, it's about to construct an nginx server environment. This build process can take a while, with some people reporting over an hour long wait. This is because all the software we're installing is being built from source rather than by package managers.

在此步骤之后启动的过程称为构建过程,您的DIY应用程序将被停止以读取.openshift文件夹的内容并做出相应的React。 在我们的例子中,将要构建一个nginx服务器环境。 此构建过程可能需要一段时间,有些人报告的等待时间超过一个小时。 这是因为我们正在安装的所有软件都是从源代码而非软件包管理器构建的。

There have also been reports of OpenShift disconnecting during the build due to a timeout. If this happens, simply make an arbitrary change to a README file or something equally insignificant, commit, and push again.

也有报告称OpenShift在构建期间由于超时而断开连接。 如果发生这种情况,只需对README文件或类似无关紧要的内容进行任意更改,然后提交并再次推送。

When the build is complete, you can make sure everything works by creating a web folder in your app's root (locally), and an index.php file inside it with the contents:

构建完成后,您可以通过在应用程序的根目录(本地)中创建一个web文件夹,并在其中包含内容的index.php文件来确保一切正常:

<?php
phpinfo();

Commit, push, and you should be able to open your app's URL in the browser and see the PHP info screen.

提交,推送,您应该能够在浏览器中打开应用程序的URL,并看到PHP信息屏幕。

alt

hal (Phalcon)

Now comes the hard part, some hardcore hackery follows to get Phalcon up and running.

现在来了困难的部分,一些铁杆骇客随之而来,以启动并运行Phalcon。

SSH into your cartridge by following the steps on your application's dashboard, or by finding out the SSH URL with rhc domain show.

遵循应用程序仪表板上的步骤,或通过查找带有rhc domain show的SSH URL,将SSH rhc domain show

alt

Then enter app-root/runtime/repo and clone the cphalcon repository in that folder.

然后输入app-root/runtime/repo并在该文件夹中克隆cphalcon存储库。

cd app-root/runtime/repo
git clone http://github.com/phalcon/cphalcon.git
alt

Find the location of the PHP bin directory. It's usually in $OPENSHIFT_RUNTIME_DIR/php5/bin. Try cd-ing into it to see if it works. If everything is fine, enter the build directory of the previously cloned cphalcon.

查找PHP bin目录的位置。 通常在$OPENSHIFT_RUNTIME_DIR/php5/bin 。 尝试对其进行cd-ing检查是否可行。 如果一切正常,请输入先前克隆的cphalcon的build目录。

cd && cd app-root/runtime/repo/cphalcon/build

Open the install file with a text editor like vi or vim, and replace all references to phpize with $OPENSHIFT_RUNTIME_DIR/php5/bin/phpize or whichever location you found for your own app, if not identical to mine. The phpize references should be at the bottom of the file. Also, add the option --with-php-config=$OPENSHIFT_RUNTIME_DIR/php5/bin/php-config to the configure line. Basically, you should be replacing this block:

用文本编辑器(如vi或vim)打开install文件,并用$OPENSHIFT_RUNTIME_DIR/php5/bin/phpize或为自己的应用找到的任何位置替换所有对phpize引用(如果与我的不相同)。 phpize引用应位于文件的底部。 另外,将选项--with-php-config=$OPENSHIFT_RUNTIME_DIR/php5/bin/php-config到配置行。 基本上,您应该替换此块:

#Clean current compilation
if [ -f Makefile ]; then
        make clean
        phpize --clean
fi

#Perform the compilation
phpize && ./configure --enable-phalcon && make && make install && echo -e "\nThanks for compiling Phalcon!\nBuild succeed: Please restart your web server to complete the installation"

with this

有了这个

#Clean current compilation
if [ -f Makefile ]; then
        make clean
        $OPENSHIFT_RUNTIME_DIR/php5/bin/phpize --clean
fi

#Perform the compilation
$OPENSHIFT_RUNTIME_DIR/php5/bin/phpize && ./configure --enable-phalcon --with-php-config=$OPENSHIFT_RUNTIME_DIR/php5/bin/php-config && make && make install && echo -e "\nThanks for compiling Phalcon!\nBuild succeed: Please restart your web server to complete the installation"

What we're doing here is making sure the phpize from the freshly installed php5.5 is being run by explicitly stating we want that one. This way, cphalcon gets built for our version of PHP, with our PHP configuration.

我们在这里所做的是确保在phpize通过明确指出我们要的是一个由新安装php5.5正在运行。 这样,就可以使用我们PHP配置为我们PHP版本构建cphalcon。

After that, just run ./install. Sudo is not permitted on OpenShift cartridges, but the user you SSH with is about as close to root as you can get.

之后,只需运行./install 。 OpenShift盒式磁带上不允许使用Sudo,但与SSH进行连接的用户应尽可能接近root。

Let's add it to the php.ini file now.

现在将其添加到php.ini文件中。

cd $OPENSHIFT_RUNTIME_DIR
vim etc/php5/php.ini

Find the block where extensions are listed. Use vim's pattern finder: press forward slash (/) and type "extension=" and Enter, this will take you to the block in the screenshot below. Add "extension=phalcon.so" to the end of the block, and while you're there, scroll a bit further down and add your timezone as well.

查找列出扩展名的块。 使用vim的模式查找器:按正斜杠(/)并输入“ extension =“,然后按Enter,这将带您进入下面的屏幕截图中的代码块。 将“ extension = phalcon.so”添加到该块的末尾,然后在那儿向下滚动一点并添加时区。

alt

We need to restart our cartridge now to reload these changes. You do this by punching in ctl_app restart while SSHed to the box.

我们需要立即重新启动盒带以重新加载这些更改。 您可以通过在ctl_app restart连到该框的同时打入ctl_app restart来完成此操作。

Edit: you might encounter a problem after this saying something like

编辑:您可能会在这样说之后遇到问题

"PHP Warning: PHP Startup: Unable to load dynamic library '/path/to/extensions/phalcon.so' - /path/to/extensions/phalcon.so: undefined symbol: output_globals in Unknown on line 0".

.

To fix it, recompile Phalcon following the instructions provided here, or in other words, do the following:

要修复此问题,请按照此处提供的说明重新编译Phalcon,或者执行以下操作:

cd cphalcon/build/64bits
make clean
phpize --clean
/path-to-php/bin/phpize
./configure --with-php-config=/path-to-php/bin/php-config
make && make install

Thanks to Alexey Bakulin for this tip!

感谢Alexey Bakulin提供的提示!

Re-check your app's URL, and you should see Phalcon in the PHP info screen now.

重新检查应用程序的URL,现在您应该在PHP信息屏幕中看到Phalcon。

alt

配置Nginx (Configuring Nginx)

The last step is configuring Nginx for URL rewrites, so we can deploy a Phalcon app. We'll be deploying the Phalconphp.com site, but feel free to modify these settings to apply to your own app.

最后一步是配置Nginx进行URL重写,因此我们可以部署Phalcon应用程序。 我们将部署Phalconphp.com网站,但随时可以修改这些设置以应用于您自己的应用程序。

vim $OPENSHIFT_RUNTIME_DIR/nginx/conf/nginx.conf

Find the server block with the pattern finder (the pattern to search for is "server {"). Under root, change the //web part to be //website/public. Under index, put index.php as the first option, instead of the last. Scroll down a bit, and as per Nginx installation instructions under location @rewrites replace

使用模式查找器查找服务器块(要搜索的模式是“服务器{”)。 在根目录下,将//web部件更改为//website/public 。 在index ,将index.php作为第一个选项,而不是最后一个。 向下滚动一点,并按照Nginx安装说明 ( location @rewrites替换

location @rewrites {
    rewrite ^(.*)$ /index.php/$1 last;
}

with

location @rewrites {
    rewrite ^/(.*)$ /index.php?_url=/$1;
}

Clone the Phalconphp.com website into the repo folder, and when it's done, restart the cartridge again:

将Phalconphp.com网站克隆到repo文件夹中,完成后,再次重新启动墨盒:

cd && cd app-root/runtime/repo
git clone http://github.com/phalcon/website
ctl_app restart

Visit the app's public URL and voila, you have a running Phalconphp.com clone on OpenShift.

访问应用程序的公共URL,瞧,您在OpenShift上具有正在运行的Phalconphp.com克隆。

alt

结论 (Conclusion)

Installing Phalcon (or any other PHP extension) on OpenShift is obviously neither easy nor fun – but seeing as their DIY apps are only version 0.1, the process is bound to become much easier. For now, I hope this introduction to custom OpenShift environments whetted your appetite enough to play around on your own. Open the .openshift folder and dissect the action hooks – there's lots to learn, and if you manage to automate the process we just went through with a hook, do let me know and I'll update the article with full credit.

在OpenShift上安装Phalcon(或任何其他PHP扩展)显然既不容易也不有趣–但是由于他们的DIY应用程序仅为0.1版,因此该过程必定会变得更加容易。 现在,我希望对自定义OpenShift环境的介绍能激发您的胃口,让您自己玩一玩。 打开.openshift文件夹并剖析动作挂钩–有很多东西要学习,并且如果您设法自动化我们刚刚通过挂钩完成的过程,请告诉我,我将以充分的信誉更新本文。

Leave your feedback in the comments below!

在下面的评论中留下您的反馈!

翻译自: https://www.sitepoint.com/nginx-php5-5-phalcon-openshift/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值