azure上创建项目_Windows Azure上的Phalcon

azure上创建项目

In my last Windows Azure with PHP article, we went through the detailed process of deploying a PHP+MySQL app on Windows Azure; but every PHP dev knows it makes no sense not to use a framework. Reinventing the wheel is never a good option, not when you have so many excellent wheels to choose from.

在上一篇使用PHP的Windows Azure中 ,我们详细介绍了在Windows Azure上部署PHP + MySQL应用程序的过程。 但是每个PHP开发人员都知道不使用框架是没有意义的。 重塑轮子从来都不是一个好选择,当您有这么多出色的轮子可供选择时,这并不是一个好选择。

In this article we'll install Phalcon, my personal framework of choice. You might be thinking "But isn't a framework just a collection of classes? Isn't just uploading them enough?". That's not the case with Phalcon. Phalcon is a PHP extension written in C that needs to be installed into PHP much like any other extension (mcrypt, xdebug, etc) – this makes it unavailable on various shared hosting environments, but this complication also makes sure the people using it are mostly dedicated professionals.

在本文中,我们将安装我个人选择的框架Phalcon。 您可能会想:“但是框架不只是一个类的集合吗?仅仅上传它们就不够了吗?”。 Phalcon并非如此。 Phalcon是一个用C编写PHP扩展,需要像安装其他任何扩展(mcrypt,xdebug等)一样安装到PHP中–这使其在各种共享主机环境中均不可用,但是这种复杂性也确保了使用它的人们大多敬业的专业人员。

To get introduced to Phalcon, feel free to look at some of our previous articles on the topic: – Phalcon introGoogle App Engine and a plea for PhalconZephir – build PHP extensions without knowing C

要了解Phalcon,请随时阅读我们之前有关该主题的文章:– Phalcon简介Google App Engine和Phalcon的请求Zephir –在不了解C的情况下构建PHP扩展

准备中 (Preparing)

Use the guidance of the previous article to set up a new empty PHP web app. Alternatively, use the application from the last article, if you're not too attached to it.

使用一篇文章的指导来设置一个新的空PHP Web应用程序。 或者,如果您不太喜欢它,请使用上一篇文章中的应用程序。

Seeing as Windows Azure is a Windows environment, the PHP extensions for it are .dll files. Download Phalcon.dll. Make sure you grab the 32bit version (x86), because Free Trial Azure accounts don't support 64 bit environments. Also, grab the file that has the latest PHP version in the name, and which is NTS (non-thread-safe).

由于Windows Azure是Windows环境,因此它PHP扩展名是.dll文件。 下载Phalcon.dll 。 确保获得32位版本(x86),因为免费试用Azure帐户不支持64位环境。 另外,获取名称中具有最新PHP版本的文件,该文件为NTS(非线程安全)。

Regardless of the system you're currently on, also make sure you have Phalcon installed in your local environment. We'll need a place to test our app before deploying it, after all.

无论您当前使用的是哪种系统,也请确保在本地环境中安装了Phalcon。 毕竟,我们需要在部署应用程序之前先对其进行测试。

Clone the sample app, put it into your web root and see if it works. If everything goes fine, you should see the following screen in your browser:

克隆示例应用程序 ,将其放入您的Web根目录,然后查看其是否有效。 如果一切正常,您应该在浏览器中看到以下屏幕:

alt

If you get lost configuring it, the Phalcon docs have pretty good tutorials on setting the app up on every popular web server: http://docs.phalconphp.com/en/latest/reference/install.html#installation-notes

如果您在配置它时迷路,Phalcon文档提供了有关在每个流行的Web服务器上设置该应用程序的很好的教程: http : //docs.phalconphp.com/en/latest/reference/install.html#installation-notes

It doesn't matter which OS or server you use at this time – I'm almost certain you aren't using IIS – so all that matters is getting the app to work. If you get to the above screen, and the Sign Up Here link works and redirects you to the proper url without any "index.php" artifacts in the browser's address bar, we're good to go. If the app doesn't work like it should, try following along with their tutorial: http://docs.phalconphp.com/en/latest/reference/tutorial.html#creating-a-project

您现在使用的是哪个操作系统或服务器都没关系-我几乎可以肯定您没有使用IIS-因此,最重要的是使该应用程序正常运行。 如果您转到上面的屏幕,并且“在此处注册”链接可以正常工作,并将您重定向到正确的URL,而浏览器的地址栏中没有任何“ index.php”构件,我们很好。 如果该应用无法正常运行,请尝试遵循其教程: http : //docs.phalconphp.com/en/latest/reference/tutorial.html#creating-a-project

安装Phalcon扩展 (Installing the Phalcon extension)

IIS is the server which Azure uses to deploy PHP web apps. Seeing as the Phalcon docs don't cover setting up the framework on that server, we'll need to improvise slightly. For now, if you've set up an FTP account and your Azure app is up and running, we're good to go.

IIS是Azure用来部署PHP Web应用程序的服务器。 鉴于Phalcon文档未涵盖在该服务器上设置框架的问题,因此我们需要做一些即兴的工作。 目前,如果您已经设置了FTP帐户并且您的Azure应用已启动并正在运行,那么我们很好。

First, connect to the app's FTP server, and change the content of index.php to

首先,连接到应用程序的FTP服务器,并将index.php的内容更改为

<?php
phpinfo();

If you visit your app's URL in the browser now, you should see the familiar PHP info output, listing installed extensions, environment details, and so on.

如果现在在浏览器中访问应用程序的URL,应该会看到熟悉PHP信息输出,列出已安装的扩展名,环境详细信息,等等。

alt

Now let's install Phalcon. First create a bin directory in the root of your app. On Azure, that's two folders above the one containing index.php – the one that contains the folders LogFiles and site. Upload the previously downloaded Phalcon.dll file into that bin folder, so that your directory structure now looks like this:

现在让我们安装Phalcon。 首先在应用程序的根目录中创建一个bin目录。 在Azure上,该文件夹上方是两个文件夹,其中包含index.php –一个包含文件夹LogFilessite 。 将以前下载的Phalcon.dll文件上传到该bin文件夹中,以便您的目录结构现在如下所示:

alt

Next, we need to tell Azure where to look for the extension (and to look for it at all, for that matter). Go into the "Configure" section of your Azure app, and scroll down to the "App Settings" section. Under KEY, put "PHP_EXTENSIONS" and under VALUE, put ..\..\bin\php_phalcon.dll.Mind the backslashes in the path! Remember, we're using Windows!

接下来,我们需要告诉Azure在哪里寻找扩展(并就此寻找它)。 进入Azure应用程序的“配置”部分,然后向下滚动到“应用程序设置”部分。 在KEY下,将“ PHP_EXTENSIONS”放在VALUE下,将..\..\bin\php_phalcon.dll放入。在路径中注意反斜杠! 记住,我们正在使用Windows!

alt

Finalize by clicking Save at the bottom of the screen, and reload your app's URL. If you search for the string "Phalcon" on the displayed page, you should get an output not unlike the following:

通过单击屏幕底部的“保存”完成操作,然后重新加载应用程序的URL。 如果在显示的页面上搜索字符串“ Phalcon”,则应获得与以下内容相似的输出:

alt

Phalcon has been installed. But we're far from done.

已安装Phalcon。 但是我们还远远没有完成。

上载和测试 (Uploading and testing)

Next, let's upload our code to Azure. We don't want all of our app's code in the wwwroot folder, because that folder is public on the web – everyone can access it, so there are some security implications to consider. Instead, upload the contents of the sample app's public folder into wwwroot, and upload the sample app's app folder into the site folder, one level above.

接下来,让我们将代码上传到Azure。 我们不希望将应用程序的所有代码都放在wwwroot文件夹中,因为该文件夹在网络上是公共的-每个人都可以访问它,因此需要考虑一些安全性。 取而代之的是,上传的示例应用程序的内容public文件夹放到wwwroot ,并上传示例应用程序的app文件夹放到site的文件夹,上面的一个水平。

alt

Refreshing the app's URL should now give you this:

现在,刷新应用程序的URL应该可以为您提供:

alt

If this page loaded, this means Phalcon was installed. However, if you try accessing the "Sign Up Here" link, you'll get the "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." error message. This happens because we haven't defined URL rewriting. Seeing as we're on IIS now, Apache's .htaccess files won't work. What we need is a Web.config file – the IIS equivalent.

如果加载了此页面,则表示已安装Phalcon。 但是,如果尝试访问“在这里注册”链接,则会得到“正在寻找的资源已被删除,名称已更改或暂时不可用”。 错误信息。 发生这种情况是因为我们尚未定义URL重写。 看到我们现在在IIS上,Apache的.htaccess文件将无法工作。 我们需要一个Web.config文件-IIS等效文件。

In the root of your app's public folder (public locally, wwwroot on Azure), create the file Web.config and give it the following content:

在应用程序公用文件夹的根目录(本地public ,Azure上为wwwroot )中,创建文件Web.config并为其提供以下内容:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Main Rule" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php?_url=/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

The above can (and should) be tweaked on a per-app basis, but in essence, this is all it takes for a Web.config file to behave just like a .htaccess file and redirect all requests to index.php with the _url GET parameter, as per Phalcon's instructions.

以上内容可以(并且应该)针对每个应用程序进行调整,但是从本质上讲,这就是Web.config文件的行为就像.htaccess文件一样,并使用_url将所有请求重定向到index.php全部操作GET参数,按照Phalcon的说明进行。

Try visiting the "Sign Up Here" link now. The page should open successfully, displaying a sign-up form.

现在尝试访问“在这里注册”链接。 该页面应成功打开,并显示一个注册表单。

结论 (Conclusion)

Azure is an incredibly versatile environment, allowing for deployment of custom PHP runtimes, extensions, and tweaks of all types. Armed with the knowledge of installing the fastest PHP framework (which should significantly reduce the running costs of your Azure app!), why not go ahead and enter the Push The Web Forward contest with an awesome Phalcon app? There's still time!

Azure是一个极其通用的环境,允许部署所有类型的自定义PHP运行时,扩展和调整。 具备安装最快PHP框架的知识(这将大大降低Azure应用程序的运行成本!),为什么不继续使用出色的Phalcon应用程序参加Push the Web Forward竞赛? 还有时间!

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

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

翻译自: https://www.sitepoint.com/phalcon-windows-azure/

azure上创建项目

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值