cloud部署到linux_如何将您的第一个应用程序部署到PHP Cloud

cloud部署到linux

There are an increasing number of Platform as a Service options available for developers, so it’s no surprise that Zend have joined the party. PHP Cloud is a public preview at the moment, but it already offers key features such as: MySQL access, source code management via Git, deployment to other cloud services, and SFTP access.

开发人员可以使用越来越多的“ 平台即服务”选项,因此Zend加入该聚会也就不足为奇了。 目前,PHP Cloud是一个公开预览版,但它已经提供了一些关键功能,例如:MySQL访问,通过Git进行源代码管理,部署到其他云服务以及SFTP访问。

In this article, I’ll show you how to set up a CakePHP installation in an application container within PHP Cloud. Along the way, you’ll see how to access MySQL, deploy code, and use SFTP from your FTP client to access the application container.

在本文中,我将向您展示如何在PHP Cloud的应用程序容器中设置CakePHP安装。 在此过程中,您将了解如何访问MySQL,部署代码以及如何从FTP客户端使用SFTP来访问应用程序容器。

首先,获得一个zend.com帐户和一个phpcloud.com邀请 (First, get a zend.com account and a phpcloud.com invite)

You will need to create a zend.com account (it’s free) if you don’t have one already. Then you will need to request an invite. Usually, Zend will send you an invite within 24 hours.

如果您还没有zend.com帐户,则需要创建一个帐户 (免费)。 然后,您将需要邀请 。 通常,Zend会在24小时内向您发送邀请。

存取键 (Access Keys)

Once you have received your invite and created an account, the first thing to do is set up the access keys (from the menu on the left after you have logged in). If you have an RSA pair already, you can upload your existing public key. If not, or if you want to create one just for PHP Cloud, you can use the option to generate a new key pair:

收到邀请并创建帐户后,首先要做的是设置访问键(登录后从左侧菜单中选择)。 如果已经有RSA对,则可以上传现有的公共密钥。 如果不是,或者您只想为PHP Cloud创建一个,则可以使用该选项来生成新的密钥对:

generate a key pair

You can then download the .pem file (the private key) and store it safely on your machine.

然后,您可以下载.pem文件(私钥)并将其安全地存储在计算机上。

创建一个容器 (Create a container)

To create a container, click on my containers from the menu on the left after you have logged in. You will be presented with a form asking for basic information about the container you want to set up:

要创建一个容器,请在登录后从左侧菜单中单击我的容器。将显示一个表格,询问您要设置的容器的基本信息:

creating a container

Notice that you can also set up the container to be able to send emails too. You will then be asked to wait for a moment while your container is provisioned:

请注意,您还可以将容器设置为也能够发送电子邮件。 然后,在配置容器时,将要求您等待片刻:

provisioning

That’s all there is to creating a container.

这就是创建容器的全部内容。

关于SSH / Shell访问的一句话 (A word about SSH/Shell access)

There is no provision for shell access at the time of writing. There is some limited SSH access. You can access your MySQL instance, or Zend Studio for remote debugging. There does seem to be a problem with it though, I ran into a lot of problems connecting over SSH, mostly to do with the:

在编写本文时,没有提供shell访问的规定。 SSH访问受限。 您可以访问MySQL实例或Zend Studio进行远程调试。 但是似乎确实存在问题,我在通过SSH进行连接时遇到了很多问题,主要与以下问题有关:

Connection timed out during banner exchange

Bear in mind that this is a preview build at the moment, so there are bound to be teething problems. We can work around that issue for now.

请记住,这是目前的预览版本,因此肯定会出现一些问题。 我们现在可以解决该问题。

数据库访问 (Database Access)

The other way we can get access is via the phpMyAdmin installation that has been made available. From the application container, click on management -> database management:

我们可以访问的另一种方法是通过已可用的phpMyAdmin安装。 在应用程序容器中,单击管理->数据库管理:

database management

That will provide a link to phpMyAdmin:

这将提供一个指向phpMyAdmin的链接:

database management

Now you can work as normal with MySQL, importing data, creating tables and so on. To be able to connect to your database via your code, you will need the following:

现在,您可以正常使用MySQL,导入数据,创建表等。 为了能够通过您的代码连接到数据库,您将需要以下内容:

  • Database host: mycontainer-db.my.phpcloud.com

    数据库主机:mycontainer-db.my.phpcloud.com
  • Database port: 3306

    数据库端口:3306
  • Database schema name: mycontainer

    数据库模式名称:mycontainer
  • Database user: mycontainer

    数据库用户:mycontainer
  • Database password: your container password

    数据库密码:您的容器密码

Git访问 (Git Access)

Git

You can work with your source directly via Git: The button will provide a url to the repository that you can clone:

您可以直接通过Git使用源代码:该按钮将提供可克隆的存储库的URL:

cd ~/sites
git clone https://mycontainer@mycontainer.my.phpcloud.com/git/container-root.git myproject

Obviously you will need to change your directory to where you want to store your code, and also add the container name that you have used in place of mycontainer.

显然,您需要将目录更改为要存储代码的目录,还需要添加您用来代替mycontainer的容器名称。

SFTP访问 (SFTP Access)

If you use an FTP client that supports STFP, then you can access your container that way too. You will need the following information:

如果使用支持STFP的FTP客户端,则也可以通过这种方式访问​​容器。 您将需要以下信息:

  • User name: mycontainer

    用户名:mycontainer
  • Host name: mycontainer.my.phpcloud.com

    主机名:mycontainer.my.phpcloud.com
  • Port: 22 (this is the default SFTP port and usually there is no need to specify this)

    端口:22(这是默认的SFTP端口,通常无需指定此端口)
  • RSA Private Key: the path to your private key file

    RSA私钥:私钥文件的路径

The private key path should point to the .pem file you created earlier, or your exisitng private key.

私钥路径应指向您之前创建的.pem文件或现有的私钥。

Once you have connected, you will be presented with a file structure like this:

连接后,将为您提供如下文件结构:

SFTP

Your code is intended to go in the public folder. You will see that I have added the files and folders that belong to a CakePHP installation.

您的代码旨在放入公用文件夹中。 您将看到我添加了属于CakePHP安装的文件和文件夹。

You can work via Git, or you can work by uploading via SFTP, the choice is yours.

您可以通过Git进行工作,也可以通过SFTP上载进行工作,这是您的选择。

尝试一下–一个简单的CakePHP应用程序 (Trying it out – a simple CakePHP Application)

We’ll install CakePHP, and build a simple blog application, just so that we can prove things work on the Zend Cloud.

我们将安装CakePHP,并构建一个简单的博客应用程序,以便我们可以证明在Zend Cloud上一切正常。

The normal installation of CakePHP requires that you change permissions on certain folders and files. Since PHPCloud has no shell access, you will have to access the installation via SFTP.

CakePHP的常规安装要求您更改某些文件夹和文件的权限。 由于PHPCloud没有外壳程序访问权限,因此您将必须通过SFTP访问安装。

Download a fresh copy of the stable version of CakePHP unzip it, and then upoad it to your container using the SFTP method described above. Ensure that you upload all files; CakePHP has some hidden files that you will need to be sure to upload too.

下载CakePHP稳定版本的新副本,将其解压缩,然后使用上述SFTP方法将其升级到您的容器中。 确保您上传了所有文件; CakePHP有一些隐藏文件,您也需要确保它们也要上传。

1.更改权限– app / tmp (1. Change permissions – app/tmp)

Next, change the permissions on the app/tmp folder to 777 (read and write) using your preferred (S)FTP client. Cake uses this folder to store session data, logs, cache, and test results.

接下来,使用您的首选(S)FTP客户端将app / tmp文件夹的权限更改为777(读和写)。 Cake使用此文件夹存储会话数据,日志,缓存和测试结果。

2.更新app / config / core.php (2. Update app/config/core.php)

Scroll down to around line 182, and change the security salt to one of your own. Also, change the cipherSeed value to a random numeric string.

向下滚动到第182行,然后将安全盐更改为您自己的安全盐。 另外,将cipherSeed值更改为随机数字字符串。

3.添加您的数据库设置 (3. Add your database settings)

The database settings that you used for phpMyAdmin, should be added to app/config/database.php (you’ll need to re-name the file from database.php.default).

您用于phpMyAdmin的数据库设置应添加到app / config / database.php中(您需要从database.php.default重命名该文件)。

4.测试您的网站 (4. Test your site)

Access your site from the by clicking the link in your application container:

通过单击您的应用程序容器中的链接,从访问您的网站:

CakePHP installed

And with any luck, you will see something like the screenshot above.

运气好的话,您会看到类似上面的屏幕截图。

4.将表添加到数据库 (4. Add a table to the database)

Log into your phpMyAdmin instance in the container, click on the database name on the left of the window, and then copy and paste the following SQL code into the text-box in the SQL tab. Click the “Go” button, and your table will be created:

登录到容器中的phpMyAdmin实例,单击窗口左侧的数据库名称,然后将以下SQL代码复制并粘贴到“ SQL”选项卡的文本框中。 单击“开始”按钮,将创建您的表:

/* First, create our posts table: */
CREATE TABLE posts (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(50),
    body TEXT,
    created DATETIME DEFAULT NULL,
    modified DATETIME DEFAULT NULL
);

/* Then insert some posts for testing: */
INSERT INTO posts (title,body,created)
    VALUES ('The title', 'This is the post body.', NOW());
INSERT INTO posts (title,body,created)
    VALUES ('A title once again', 'And the post body follows.', NOW());
INSERT INTO posts (title,body,created)
    VALUES ('Title strikes back', 'This is really exciting! Not.', NOW());
create a table

At this stage, you can revert to using Git now, since the file permissions issues have been resolved.

由于文件权限问题已解决,因此在此阶段,您可以立即恢复使用Git。

克隆您的存储库 (Clone your repository)

I’m going to assume that you have Git installed, and a working knowledge of how to use it. Back in your container, you can find the clone url here:

我将假设您已经安装了Git,并具有如何使用它的实用知识。 回到容器中,您可以在此处找到克隆网址:

Git clone url

Open up your terminal/console and change directory to where you would like to store your project. Then clone the repository:

打开终端/控制台,然后将目录更改为要存储项目的目录。 然后克隆存储库:

git clone https://your_container.my.phpcloud.com/git/container-root.git myproject

时间到一些代码 (Time for some code)

We’ll start by creating code to handle blog posts.

我们将从创建用于处理博客文章的代码开始。

1.创建一个帖子模型 (1. Create a post model)

Create a new file in app/Model called Post.php and add the following code:

在app / Model中创建一个名为Post.php的新文件,并添加以下代码:

<?php
class Post extends AppModel {
    public $name = 'Post';
}

2.创建一个帖子控制器 (2. Create a Posts Controller)

We’ll create the common outline for our controller:

我们将为控制器创建通用轮廓:

<?php
class PostsController extends AppController {
    public $name = 'Posts';
    public $helpers = array('Html', 'Form');
}

You’ll notice that we have loaded some common helpers too. Next, we’ll add an action to fetch all of the entries in our posts table:

您会注意到我们也加载了一些常见的帮助器。 接下来,我们将添加一个操作来获取posts表中的所有条目:

public function index() {
        $this->set('posts', $this->Post->find('all'));
    }

3.添加视图文件 (3. Add a view file)

Create a new file in app/views/Posts named index.ctp and add the following code:

在app / views / Posts中创建一个名为index.ctp的新文件,并添加以下代码:

<!-- File: /app/View/Posts/index.ctp -->

<h1>Blog posts</h1>
<table>
    <tr>
        <th>Id</th>
        <th>Title</th>
        <th>Created</th>
    </tr>

    <!-- Here is where we loop through our $posts array, printing out post info -->

    <?php foreach ($posts as $post): ?>
    <tr>
        <td><?php echo $post['Post']['id']; ?></td>
        <td>
            <?php 
                echo $this->Html->link($post['Post']['title'],
                    array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); 
            ?>
        </td>
        <td><?php echo $post['Post']['created']; ?></td>
    </tr>
    <?php endforeach; ?>

</table>

4.检查进度 (4. Checking progress)

The seems to be an issue with the way that PHP Cloud handles .htaccess files at the moment. To get things working, go to app/config/core.php and do as advised here:

目前,PHP Cloud处理.htaccess文件的方式似乎存在问题。 要使工作正常,请转到app / config / core.php并按照此处的建议进行操作:

/**
 * To configure CakePHP *not* to use mod_rewrite and to
 * use CakePHP pretty URLs, remove these .htaccess
 * files:
 *
 * /.htaccess
 * /app/.htaccess
 * /app/webroot/.htaccess
 *
 * And uncomment the App.baseUrl below:
 */
    Configure::write('App.baseUrl', env('SCRIPT_NAME'));

You can now visit your site at: http://my-container.my.phpcloud.com/index.php/posts/index:

您现在可以在以下位置访问您的网站:http://my-container.my.phpcloud.com/index.php/posts/index:

CakePHP up and running

5.添加视图动作 (5. Adding a view action)

You will notice that clicking the links causes an error. That’s because we don’t have a view action in the posts controller, and an associated view file.

您会发现单击链接会导致错误。 这是因为我们在posts控制器中没有视图操作,也没有关联的视图文件。

So in app/Controller/PostsController.php add the required action:

因此,在app / Controller / PostsController.php中添加所需的操作:

public function view($id = null) {
        $this->Post->id = $id;
        $this->set('post', $this->Post->read());
}

Then, in app/View/Posts add view.ctp:

然后,在app / View / Posts中添加view.ctp:

<!-- File: /app/View/Posts/view.ctp -->
<h1><?php echo $post['Post']['title']?></h1>
<p><small>Created: <?php echo $post['Post']['created']?></small></p>
<p><?php echo $post['Post']['body']?></p>

Now you can click the links to view the individual posts.

现在,您可以单击链接来查看各个帖子。

最后… (Finally…)

So you have seen how to get a simple application up and running on PHP Cloud. There are still some issues, but once they are resolved, this will undoubtably be a strong cloud hosting solution.

因此,您已经了解了如何在PHP Cloud上启动并运行一个简单的应用程序。 仍然存在一些问题,但是一旦解决,毫无疑问,这将是一个强大的云托管解决方案。

The ability to log in via SFTP is important, but the missing shell access is unfortunate. However, with phpMyAdmin, Git, and the ability to deploy to other cloud services, PHP Cloud already has a lot to offer.

通过SFTP登录的能力很重要,但是不幸的是,缺少对Shell的访问。 但是,借助phpMyAdmin,Git和部署到其他云服务的功能,PHP Cloud已经提供了很多功能。

翻译自: https://www.sitepoint.com/how-to-deploy-your-first-app-to-phpcloud/

cloud部署到linux

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值