| // |
| // 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. |
| // |
| |
| = NetBeans IDE PHP 快速入门教程 |
| :jbake-type: tutorial |
| :jbake-tags: tutorials |
| :jbake-status: published |
| :icons: font |
| :syntax: true |
| :source-highlighter: pygments |
| :toc: left |
| :toc-title: |
| :description: NetBeans IDE PHP 快速入门教程 - Apache NetBeans |
| :keywords: Apache NetBeans, Tutorials, NetBeans IDE PHP 快速入门教程 |
| |
| 本文档为在适用于 PHP 的 NetBeans IDE 中准备 PHP 开发环境、设置 PHP 项目以及开发并运行首个 PHP 应用程序提供了一般性指导。 |
| |
| *要学习本教程,您需要具备以下软件和资源。* |
| |
| |=== |
| |软件或资源 |要求的版本 |
| |
| |link:https://netbeans.org/downloads/index.html[+NetBeans IDE+] |PHP 下载包 |
| |
| |PHP 引擎 |版本 5 |
| |
| |Web 服务器 |推荐使用 link:http://httpd.apache.org/download.cgi[+Apache HTTP Server 2.2+]。 |
| |
| |
| |PHP 调试器 |link:http://www.xdebug.org[+XDebug 2.0 或更高版本+] |
| |=== |
| |
| 您既可以单独安装 PHP 引擎、Web 服务器和数据库,也可以使用 AMP (*A*pache, *M*ySQL, *P*HP) 包进行安装。 |
| |
| |
| == 安装和配置 |
| |
| 下面的文档包含在操作系统上设置 PHP Web 堆栈的一种或两种方法的说明。这些说明并不具有权威性。Web 堆栈由第三方软件组成,而且由于您的环境可能不同,因此您可能希望使用其他 AMP 包或其他方法设置 PHP。您可能需要通过自己的研究来补充我们的说明。 |
| |
| * link:configure-php-environment-windows.html[+在 Windows 中配置 PHP 开发环境+] |
| * link:configure-php-environment-ubuntu.html[+在 Ubuntu Linux 发行版中配置 PHP 开发环境+] |
| * link:configure-php-environment-mac-os.html[+在 Mac 操作系统 (Mac OS X) 中配置 PHP 开发环境+] |
| |
| |
| == 在适用于 PHP 的 NetBeans IDE 中设置 PHP 项目 |
| |
| 有关安装并启动 NetBeans IDE 的帮助信息,请参见link:https://netbeans.org/community/releases/73/install.html[+安装文档+]。 |
| |
| 要在适用于 PHP 的 NetBeans IDE 中着手开发 PHP 应用程序,首先需要创建一个项目。该项目包含有关项目文件位置以及应用程序的运行和调试方式(运行配置)的信息。 |
| |
| 1. 启动 IDE,切换至 "Projects"(项目)窗口,然后选择 "File"(文件)> "New Project"(新建项目)。"Choose Project"(选择项目)面板打开。 |
| 2. 在 "Categories"(类别)列表中,选择 "PHP"。 |
| 3. 在 "Projects"(项目)区域中,选择 "PHP Application"(PHP 应用程序),然后单击 "Next"(下一步)。"New PHP Project"(新建 PHP 项目)的 "Name and Location"(名称和位置)面板打开。 |
| |
| image::images/new-project-name-location.png[title="新建 PHP 项目向导的 "Name and Location"(名称和位置)面板,其中 "Source Folder"(源文件夹)位置作为 XAmpp 文档根目录。"] |
| |
| |
| [start=4] |
| . 在 "Project Name"(项目名称)文本字段中,输入 ``NewPHPProject`` 。 |
| |
| [start=5] |
| . 在 "Sources Folder"(源文件夹)字段中,浏览到您的 PHP 文档根目录并在此处创建一个名为 ``NewPHPProject`` 的子目录。Web 服务器会从文档根目录文件夹中查找要在浏览器中打开的文件。文档根目录是在 Web 服务器link:../../trails/php.html#configuration[+配置文件+]中指定的。例如,对于 Xampp,文档根目录为 XAMPP_HOME/htdocs。 |
| |
| [start=6] |
| . 将所有其他字段保留为其默认值。单击 "Next"(下一步)。"Run Configuration"(运行配置)窗口打开。 |
| |
| image::images/new-project-run-config.png[] |
| |
| |
| [start=7] |
| . 在 "Run As"(运行方式)下拉列表中,选择 "Local Web Site"(本地 Web 站点)。该项目将在本地 Apache 服务器中运行。其他选项将通过 FTP 远程运行项目,以及在命令行中运行。 |
| |
| [start=8] |
| . 将 "Project URL"(项目 URL)保留为默认值。 |
| |
| [start=9] |
| . 单击 "Finish"(完成)。IDE 将创建该项目。 |
| |
| 了解有关link:project-setup.html[+在 NetBeans 中设置 PHP 项目+]的更多信息。 |
| |
| |
| == 运行首个 PHP 项目 |
| |
| 1. 启动 IDE,选择 "File"(文件)> "Open Project"(打开项目)。"Open Project"(打开项目)对话框打开。 |
| 2. 选择 ``NewPHPProject`` ,然后单击 "Open Project"(打开项目)。在 "Projects"(项目)窗口中显示 NewPHPProject 树,并在编辑器和 "Navigator"(导航器)窗口中打开该项目的 ``index.php`` 文件。 |
| |
| image::images/getting-started-open-new-project.png[] |
| |
| |
| [start=3] |
| . 在 ``<?php ?>`` 块内输入以下代码: |
| |
| [source,php] |
| ---- |
| |
| echo "Hello, world! This is my first PHP project!"; |
| ---- |
| |
| [start=4] |
| . 要运行该项目,请将光标置于 "NewPHPProject" 节点上,然后从上下文菜单中选择 "Run"(运行)。下图显示了应在浏览器窗口中看到的内容: |
| |
| image::images/getting-started-browser-hello-world.png[] |
| |
| 恭喜!您的程序可以正常运行! |
| |
| |
| == 在适用于 PHP 的 NetBeans IDE 中使用数据库服务器 |
| |
| 您可以在适用于 PHP 的 NetBeans IDE 中使用各种数据库服务器,但最常用的是 MySQL 服务器。可以从link:http://dev.mysql.com/downloads/mysql/5.1.html[+此处+]进行下载。 |
| |
| NOTE: 该产品的推荐版本为 MySQL Server 5.0。 |
| |
| 另请参见: |
| |
| * link:../ide/install-and-configure-mysql-server.html[+在 Windows 操作系统中设置 MySQL 数据库服务器+] |
| * link:wish-list-lesson1.html[+使用测试数据创建样例数据库+] |
| * link:../../articles/mysql.html[+MySQL 和 NetBeans IDE+] |
| * link:../ide/mysql.html[+连接 MySQL 数据库+] |
| |
| |
| == 后续步骤 |
| |
| 同时,要查找特定于您正在开发的应用程序类型的信息,请使用该类型应用程序的 NetBeans IDE 学习资源。每个学习资源都包含一系列教程和指南,范围从初级到高级。可用的学习资源如下: |
| |
| |=== |
| |* link:../../trails/php.html[+PHP 编程+] |
| * link:../../trails/java-se.html[+基本 Java 编程+] |
| * link:../../trails/matisse.html[+Java GUI 应用程序+] |
| * link:../../trails/web.html[+Web 服务应用程序+] |
| * link:../../trails/java-ee.html[+Java EE 和 Java Web 应用程序+] |
| | |
| |
| * link:../../trails/mobility.html[+Mobile 应用程序+] |
| * link:../../trails/platform.html[+NetBeans 插件和富客户端应用程序+] |
| * link:../../trails/cnd.html[+C/C++ 应用程序+] |
| |
| |=== |
| |
| |
| link:/about/contact_form.html?to=3&subject=Feedback:%20PHP%20Quickstart[+发送有关此教程的反馈意见+] |
| |
| |
| 要发送意见和建议、获得支持以及随时了解 NetBeans IDE PHP 开发功能的最新开发情况,请link:../../../community/lists/top.html[+加入 users@php.netbeans.org 邮件列表+]。 |
| |