blob: 745fb302977bb0a6cd94743d82ee7acf757660a5 [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= 使用 PHP 创建数据库驱动的应用程序
:jbake-type: tutorial
:jbake-tags: tutorials
:jbake-status: published
:icons: font
:syntax: true
:source-highlighter: pygments
:toc: left
:toc-title:
:description: 使用 PHP 创建数据库驱动的应用程序 - Apache NetBeans
:keywords: Apache NetBeans, Tutorials, 使用 PHP 创建数据库驱动的应用程序
= 9 课:将应用程序部署到远程 Web 服务器
:jbake-type: tutorial
:jbake-tags: tutorials
:jbake-status: published
:icons: font
:syntax: true
:source-highlighter: pygments
:toc: left
:toc-title:
:description: 9 课:将应用程序部署到远程 Web 服务器 - Apache NetBeans
:keywords: Apache NetBeans, Tutorials, 9 课:将应用程序部署到远程 Web 服务器
通常,PHP 应用程序实际上在远程服务器上运行,并通过文件传输协议 (FTP) 进行访问。要在远程服务器上部署 CRUD 应用程序,您将需要向托管提供商注册一个普通帐户、注册一个 FTP 帐户并创建一个远程数据库。
您可以使用您喜欢的任何托管。当前文档介绍 X10HOSTING 免费托管中的部署过程。此托管包括 MySQL,但不包括 Oracle 数据库服务器。
所有的用户名、口令和电子邮件地址都是虚构的,仅用作示例。如果用户未登录论坛的时间超过了一个星期,则托管管理会阻止该用户的帐户。因此您可能无法再使用与本教程中完全相同的用户名、口令、电子邮件地址和其他凭证。
在本课程中,您将了解如何执行以下操作:
* 更改数据库连接设置以使用远程数据库
当前文档是“在适用于 PHP NetBeans IDE 中创建 CRUD 应用程序”教程的一部分。
== 来自上一课的应用程序源代码
MySQL 用户:单击link:https://netbeans.org/files/documents/4/1934/lesson8.zip[+此处+]以下载源代码,该代码反映了在完成上一课之后的项目状态。
== 注册电子邮件帐户
如果之前尚未创建电子邮件帐户,则创建一个。在此示例中,电子邮件地址为 phpuser65@googlemail.com
== 注册托管帐户
要在 link:http://x10hosting.com/[+X10HOSTING+] 免费托管中创建托管帐户,请执行向导中的步骤,同时输入以下设置。您将在任何其他托管站点中输入类似信息。
|===
|帐户设置 |值
|电子邮件地址 |phpuser65@gmail.com
|域名 |link:http://x10hosting.com/[+x10Hosting.com+]
|子域 |phpuser
|托管帐户用户名(也用于登录到 cPanel |phpuser
|托管帐户口令(也用于登录到 cPanel |qwerty1234
|论坛用户名 |phpuser
|论坛口令 |qwerty
|FTP 帐户名称 |uploader
|FTP 用户名 |uploader@phpuser.x10hosting.com
|FTP 服务器 |ftp.phpuser.x10hosting.com
|远程数据库主机名 |phpuser
|远程数据库 |wishlist
|远程数据库用户名 |phpuser
|远程数据库用户口令 |phpuserpw
|===
== 注册 FTP 帐户
现在,您已有一个托管帐户,还需要一个 FTP 帐户,用来传输 PHP 源代码和其他相关文件,以便于在服务器上执行。对于 x10Hosting,打开 cPanel 并选择 "New FTP Account",然后按向导的指示操作。
== 创建远程数据库
由于 CRUD 应用程序使用数据库,因此,您还将需要在具有<<registerHostingAccount,托管帐户>>的远程服务器上部署 `wishlist` MySQL 数据库。
== 使用现有源代码和远程 Web 站点运行配置设置 PHP 项目
1. <<previousLessonSourceCode,下载源文件>>,这些文件与完成上一课后的应用程序状态相对应。解压缩文件。
2. `htdocs` 文件夹中保存源文件。
3. 创建link:project-setup.html#importSources[+基于现有源代码的 PHP 项目+]:
* 指定下载的源代码在“源”文件夹中的位置
* 选择link:project-setup.html#remiteWebSite[+远程 Web 站点+]运行配置并配置 FTP 连接
[start=4]
. 完成项目创建。
== 更新 WishDB
到目前为止,您已在本地 Web 服务器上开发并运行“愿望列表”应用程序,并使用了本地的 MySQL Oracle 数据库服务器。为使应用程序使用远程 MySQL 数据库,您需要更新通过 `WishDB` 类的变量指定的连接设置。
1. 打开文件 `db.php`
2. 更改 `WishDB` 类的变量:
[source,php]
----
private $user = "<the name of the remote database user>";
private $pass = "<the password of the remote database user>";
private $dbName = "<the name of the remote database>";
private $dbHost = "<the account username specified during the hosting account creation>";
----
在此示例中,变量将进行如下更新:
[source,php]
----
private $user = "phpuser";
private $pass = "phpuserpw";
private $dbName = "wishlist";
private $dbHost = "localhost";
----
== 后续步骤
link:wish-list-lesson8.html[+<< 上一课+]
link:wish-list-tutorial-main-page.html[+返回到教程主页+]
link:/about/contact_form.html?to=3&subject=Feedback:%20PHP%20Wish%20List%20CRUD%200:%20Using%20and%20CSS[+发送有关此教程的反馈意见+]
要发送意见和建议、获得支持以及随时了解 NetBeans IDE PHP 开发功能的最新开发情况,请link:../../../community/lists/top.html[+加入 users@php.netbeans.org 邮件列表+]。
link:../../trails/php.html[+返回至 PHP 学习资源+]