使用NeatBeans,wamp编写PHP程序入门

corner image corner image
Features Plugins Docs & Support Community Partners

Setting Up a PHP Project

This tutorial shows you how to set up a PHP project in NetBeans IDE.

Contents

Content on this page applies to NetBeans IDE 6.5

To follow this tutorial, you need the following software and resources.

Software or ResourceVersion Required
NetBeans IDEPHP download bundle 6.5
A PHP engineVersion 5
A web serverApache HTTP Server 2.2 is recommended.
A PHP debuggerXDebug 2.0 or later

Getting Ready

Before creating a PHP project, you need to download and install the NetBeans IDE for PHP and prepare your environment for PHP development.

 

To set up a PHP project:

To change the settings of an existing project, position the cursor on the project node and choose Properties from the popup menu. Proceed as described in section Customizing the Project Setup.

Specifying the Project Name and Location of the Source Files

  1. Start the IDE and switch to the Projects window.
  2. Choose File > New Project. The Choose Project panel opens.
  3. In the Categories list, choose PHP.

Depending on your needs, you can create a completely new PHP project without any previously developed source files or import an existing PHP application into a new project.

Project without Previously Developed Source Files

  1. In the Projects area, choose PHP Application and click Next. The New PHP Project > Name and Location panel opens.
  2. In the Project Name text field, enter the name of the project.
  3. configuration file. After installation, the New Project wizard locates the document root and by default specifies the following path: <Document Root>/<New PHP Project>.

    A copy of the source files must be kept in a subfolder of the document root. However, you can have your Sources Folder in a different location than the document root and copy source files from this location to the document root. See Specifying the Run Configuration.

  4. From the Default Encoding dropdown list, choose the default encoding for your project.
  5. If you want to store NetBeans metadata in a different location than your source files, select "Put NetBeans metadata into a separate directory." For example, you might want to store your sources in your document root but the NetBeans metadata in your NetBeansProjects directory. 
    New PHP Project Panel with the fields filled in
  6. Click Next. The Run Configuration panel opens.

Importing Existing Source Files into a Project

  1. In the Projects area, choose PHP Application with Existing Sources and click Next. The New PHP Project > Name and Location panel opens.
  2. In the Project Name text field, enter the name of the project.
  3. In the Sources Folder field, specify the folder from where you want to import the source files.
    Note: If you are going to run the project on a local web server, do not forget to specify copying the source files to it.
  4. From the Default Encoding dropdown list, choose the default encoding for your project.
  5. If you want to store NetBeans metadata in a different location than your source files, select "Put NetBeans metadata into a separate directory." For example, you might want to store your sources in your document root but the NetBeans metadata in your NetBeansProjects directory. 
    New PHP Project Panel with existing sources the fields filled in
  6. Click Next. The Run Configuration panel opens.

Specifying the Default Run Configuration of the New Project

PHP development features a large variety of use cases. The most commonly used cases are:

  • Developing PHP web pages on a local machine with a local web server.
  • Executing PHP scripts using a local PHP engine. This approach is applied to PHP files that are not intended for outputting HTML. Therefore such scripts can be run without a browser.
  • Remote Development. The PHP source code and other application files are uploaded to a remote web server via FTP. This use case is common when the development is shared across multiple people.
  • A combination of the above use cases: an application is developed locally and deployed on a remote production server upon completion. During development, PHP scripts are executed if necessary.

Run configurations accommodate the use cases previously described. A run configuration is a stored setting for running a PHP project. You can define several configurations for one project and switch between them back and forth. For example, if an application has been developed locally and needs to be uploaded to a remote production server, you only need to choose another run configuration. Run configurations apply to both running and debugging.

Note: During the project creation, the default run configuration is defined. To define additional run configurations, customize your project setup.

To set the default run configuration for your project, choose the relevant option from the Run As dropdown list on the Run Configuration panel. The following options are available:

Local Web Site

From the Run As dropdown list, choose Local Web Site. The further procedure depends on the type of your project.
Project without Previously Developed Sources
  1. In the Project URL field, check the automatically generated URL address. Make sure that the Apache HTTP server listens to the default port 80. If not, specify the port number explicitly: 
    localhost:<port number> 
  2. To have a separate storage for the project's source files, select the Copy files from Sources Folder to another location checkbox.
  3. Name and Location panel you selected a location for the source folder that was not the document root, select "Copy files from Sources Folder to another location" and browse to the document root folder. 
    Project Run Configuration: Local Web Server
  4. Click Finish.
Project with Previously Developed Sources
  1. Select the Copy files from Sources Folder to another location checkbox.
  2. In the Copy to Folder field, specify the folder on your web server where you want to store your source files. Use the Browse button, if necessary.
    The field by default specifies the following path: <Document Root>/<New PHP Project>.
    The document root is the folder where the web server looks for files to open in the browser. The document root is specified in the web serverconfiguration file
    The wizard detects the Apache installation type, either a component or within a package, and provides the path to the default location of the htdocsfolder for the current installation type. Therefore, if you accepted the default settings during the installation of the Apache server or the AMP package, choose the path from the dropdown list.
  3. In the Project URL field, check the automatically generated URL address. Make sure that the Apache HTTP server listens to the default port 80. If not, specify the port number explicitly: 
    localhost:<port number> 

    Project Run Configuration: Local Web Server
  4. Click Finish.

Remote Web Site

  1. From Run As dropdown list, choose Remote Web Site (FTP).
  2. From the FTP Connection dropdown list, choose the relevant connection profile. 
    Note: You can have several hosting and FTP accounts to deploy your application with a separate FTP connection profile for each account.
  3. To create, update, or remove an FTP Connection profile, click Manage. The Manage Remote Connections dialog box opens with the fields showing the current FTP connection profile settings. Edit the fields as necessary.
  4. To create a new FTP connection profile, click Add. The Create New Connection dialog box opens.
  5. In the Connection Name field, enter the name of the new connection. In this example the connection name is x10hosting. Click OK. The Manage Remote Connections dialog box displays with the name of the new connection in the Connection Name display field.
  6. From the Type dropdown list, choose FTP.
  7. In the Host Name field, enter the FTP Server name as it is written in the FTP account creation confirmation message. In this example, the FTP server isftp.phpuser.x10hosting.com.
  8. In the Port field, specify 21.
  9. In the User Name field, enter your FTP Username as it is written in the FTP account creation confirmation message. In this example, the FTP username isuploader@phpuser.x10hosting.com.
  10. Fill in the Password field. In this example the password is qwerty1234.
  11. In the Initial Directory field, enter the name of your account directory on the FTP server. In this example, no account directory is specified, enter a slash in the field.
    Manage FTP Connections dialogbox.
  12. Click OK. You return to the Run Configuration panel.
  13. In the Upload Directory field, enter the name of the subfolder in the initial directory where the source files will be uploaded. The prompt below the field shows the FTP host URL.
  14. To specify when the files will be uploaded, choose the relevant option from the Upload Files dropdown list. The available options are: Manually and On Run.
    Run Configurations panel. Remote Site.
  15. Click Finish.

Script

  1. From the Run As dropdown list, choose Script.
  2. To specify the location of the PHP engine, click the Configure button next to the PHP Interpreter field. The Options dialog box, tab PHP opens.
  3. In the PHP 5 Interpreter field, specify the path to the php.exe file. Use the Browse button, if necessary.
    Project Run Configuration: Script. Specifying the path to the PHP engine and the output location
  4. To specify how the script execution results will be shown, select the relevant checkbox in the Open Result In area. The following options are available:

    • Output Window. The results of executing a script will appear in the output window in the bottom of the NetBeans IDE window.
    • Web Browser. The default browser window will open with the results of executing a script in the form of an HTML file.
    • Editor. The results of executing a script will open as an HTML file in the IDE editor window.
  5. Click OK. The Options dialog box closes and the system returns to the Run Configuration panel. 
    Project Run Configuration: Script. Specifying the path to the PHP engine and the output location

Customizing the Project Setup

During the project creation, the basic project settings are defined: the project type, location of the project source files, and the default run configuration. To expand the project setup with new settings, customize the project. Position the cursor on the project node and choose Properties from the popup menu. The Project Properties panel opens with a list of settings categories.

Sources


On the Sources panel:
  1. The Web Root field shows the root folder of your application site. By default, the field shows the Sources folder. To change the web root, click Browse and select another folder.
  2. Select the Copy files from Sources Folder to another location, if necessary, and specify the path to the storage folder.
  3. Change the encoding, if necessary 
    Managing project setup: Project Properties dialog box
  4. To complete the project customization, click OK.

Run Configuration


On the Run Configuration panel, modify the default run configuration and/or define new run configurations, if necessary. 
  1. To modify the default settings, update the fields as during the project creation.
  2. To define a new run configuration, click New next to the Configuration dropdown list. The Create New Configuration dialog box opens.
  3. In the Configuration Name field, enter the name of the new run configuration and click OK. You return to the Run Configuration panel.
  4. Define the run configuration settings in the same way as you defined the default run configuration during the project creation and click OK. The new configuration is added to the Configuration dropdown list.
  5. To remove a configuration, select it from the Configuration dropdown list and click Delete. 
    Managing project setup: Run configuration
  6. To complete the project customization, click OK.

PHP Include Path


On the Include Path panel, specify the location of the files that you need to use in the project but do not need to locate together with the source files.
  1. To add a folder, click Add Folder. The Select Folder(s) dialog box opens.
  2. Select the relevant folders and click Open. You return to the PHP Include Path panel. The new folder is added to the list.
  3. To navigate through the list, use the buttons Move Up and Move Down.
  4. To remove a folder from the list of included folder, select the folder and click Remove.
    Managing project setup: PHP Include Path
  5. To complete the project customization, click OK.

JavaScript Libraries


On the JavaScript Libraries panel, specify the location of the JavaScript libraries that you need to use in the project.
  1. Click Add. The Add JavaScript Libraries dialog box opens.
  2. Select the Add checkbox next to the names of the relevant libraries. The Location field displays the paths to them.
    Selecting JavaScript libraries
    Click OK. You return to the JavaScript Libraries panel. The new folder is added to the list.
  3. To remove a library from the list, select the folder and click Remove.
    Managing project setup: JavaScript Libraries
  4. To complete the project customization, click OK.

Debug


On the Debug panel, choose the part of the application that you need to debug.
  1. To debug the server side of the application implemented with the use of PHP, select the Debug Server side PHP checkbox.
  2. To debug the client side of the application implemented with the use of JavaScript, select the Debug Client side JavaScript checkbox and choose the browser to use. 
    Managing project setup: Choose the debugging area
  3. To complete the project customization, click OK.

Formatting


On the Formatting panel, define the formatting style you want to apply to your source files in the editor.
  1. To apply general IDE settings, choose the Use global options option.
  2. To customize the global options, click Edit Global Options. The standard IDE Options dialog box opens.
  3. From the Language dropdown list, select the language to which the settings should be applied.
  4. From the Categories dropdown list, select the format items to which the setting will be applied.
  5. To replace tabs with spaces, select the Expand Tabs to Spaces checkbox and specify the number of spaces per indent, the tab size, and the right margin. 
    Managing project setup: editing global options
  6. Click OK. You return to the Formatting panel.
  7. To define the formatting settings for the current project, choose the Use project specific options option. The hidden area displays. Define the formatting settings as during the global options' customization. 
    Managing project setup: Formatting
  8. To complete the project customization, click OK.

To send comments and suggestions, get support, and keep informed on the latest developments on the NetBeans IDE PHP development features, join theusers@php.netbeans.org mailing list.

Back to the PHP Learning Trail

Companion 
Projects:
MySQL Database Server  GlassFish Community: an Open Source Application Server  Open Solaris Open JDK: an Open SourceJDK  Mobile & Embedded Community   Open ESB - The Open Enterprise Service Bus OpenOffice - The free and open productivity suite Java.net - The Source for Java Technology Collaboration Sponsored by 
Sponsored by Sun Microsystems

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值