corner imagecorner image
FeaturesPluginsDocs & SupportCommunityPartners

Deploying PHP to a Server-only OpenSolaris Web Stack

To run PHP projects, you need a PHP web stack, which consists of the PHP engine, MySQL database server, Apache web server, and XDebug extension. Correctly configuring the web stack, even in an AMP package, can be problematic.

This tutorial describes an alternative to installing and configuring your own PHP web stack. Instead, you download a server-only OpenSolaris image with a pre-configured PHP web stack. This image runs in a Sun VirtualBox virtual machine. Use NetBeans IDE's FTP support to deploy your PHP applications to the OpenSolaris web stack on the virtual machine. You can then develop PHP applications in the operating system of your choice. Use NetBeans running in your host OS to access the preconfigured Apache server, XDebug debugger, and MySQL database server in the OpenSolaris web stack.

This tutorial includes a download link to a server-only OpenSolaris web stack. The tutorial also includes instructions for setting up the web stack in the Sun VirtualBox virtual machine and for deploying a PHP application to the web stack.

Contents

Content on this page applies to NetBeans IDE 6.5

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

Software or Resource Version Required
NetBeans IDE PHP download bundle
Virtual machine VirtualBox, latest version
Server-only OpenSolaris web stack including pre-configured AMP and XDebug

This image is NOT meant for a production environment.
It is provided for testing and development purposes only.

Download here
Requires 768MB base memory

Installing VirtualBox

You need virtual machine software to host the OpenSolaris web stack. This tutorial refers to Sun VirtualBox. Download and install the latest version from http://www.virtualbox.org/wiki/Downloads.

Creating the Web Stack Virtual Machine

Download and unzip the server-only OpenSolaris web stack. Create a virtual machine for the web stack, and configure its network settings.

Warning: This image is NOT suitable for a production environment. It is provided for testing and development purposes only.

To create the web stack virtual machine:

  1. Download the ZIP archive of the server-only OpenSolaris web stack from http://services.netbeans.org/NBDevStack-081212.vdi.zip.
  2. Unpack the archive to your USER_HOME/.VirtualBox/VDI directory. On Windows XP, this is Documents and Settings/USERNAME/.VirtualBox/VDI. Create the VDI directory if it does not exist.
  3. Start Virtual Box. Select File > Virtual Media Manager. The Virtual Media Manager opens.
  4. Select the Hard Disks tab. Click Add. A dialog opens for adding existing virtual drives. Navigate to .VirtualBox/VDI/ and select NBDevStack-DATE.vdi. Click Open.
    The Virtual Media Manager dialog for adding existing virtual drives, with NBDevStack.vdi selected
  5. You return to the Virtual Media Manager, which now displays the NBDevStack VDI in the Hard Disks tab. Click OK. The Virtual Media Manager closes.
    Virtual Media Manager displaying NBDevStack VDI
  6. On the main Virtual Box panel, click the New icon or press Ctrl-N. The New Virtual Machine wizard opens on the welcome page.
  7. Click Next. The VM Name and OS Type page opens. Type NBWebStack for the name. Select the Solaris operating system and the OpenSolaris version.
    New Virtual Machine wizard on VM Name and OS page
  8. Click Next. The Memory page opens. Select a base memory size of 768 MB.
  9. Click Next. The Virtual Hard Disk page opens. Select the NBDevStack-DATE.vdi image from the drop-down menu. If it is not in the menu, click Existing and browse for it. Leave Boot Hard Disk selected.
    New Virtual Machine wizard on Virtual Hard Disk page
  10. Click Next. A summary of the virtual machine's parameters appears. The parameters should be:
    • Name: NBWebStack
    • OS Type: OpenSolaris
    • Base Memory: 768 MB
    • Boot Hard Disk: NBWebStack-[DATE].vdi

    If the parameters are correct, click Finish. The New Virtual Machine wizard closes. On the main panel of Virtual Box, the NBWebStack virtual machine appears.

    Virtual Box main panel showing new NBWebStack virtual machine
  11. Click the Settings icon, or press Ctrl-S. The Settings dialog for NBWebStack opens.
  12. Select the Network category. Change the Adapter Type to PCnet-FAST III. Click OK.
    Network settings for NBWebStack showing PCnet-FAST III selected

The NBWebStack virtual machine is now set up. It includes a preset username and password. Start the virtual machine and verify that you can log in as user osol (lower case letters O S O L) with password justone1 (word "justone" + numeral "1"). Shut down the virtual machine afterward.

Note: If you need to modify the web stack, the root password is osol1108. That is, lower case "O S O L" and the number "1108." User osol is privileged.

Configuring Port Forwarding

The host system needs to access the web stack services on the virtual machine. To provide this access to the host machine, you use the VBoxManage tool to forward the ports from the guest machine to the host machine. You forward the services SSH, FTP, HTTP, and MySQL.

To configure port forwarding:

  1. In a file system explorer, navigate to the directory containing your VBoxManage executable file. On Windows XP, the default location is "C:\Program Files\Sun\xVM VirtualBox". Open a command prompt in this directory. (Alternative: Add the path to the VBoxManage executable file to your Path environment variable. Open the command prompt anywhere, or write and execute a script instead of using a command prompt.)
  2. Type the following lines into your command prompt console, or copy and paste them into a script. Run the commands or your script.

    Warning: You may have to choose different host port numbers, if you have conflicts with existing services on your host.

    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" TCP 
    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" 22
    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 2222

    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestftp/Protocol" TCP
    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestftp/GuestPort" 21
    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestftp/HostPort" 2221

    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/Protocol" TCP
    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/GuestPort" 80
    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/HostPort" 8880

    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestmysqltcp/Protocol" TCP
    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestmysqltcp/GuestPort" 3306
    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestmysqltcp/HostPort" 3336

    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestmysqludp/Protocol" UDP
    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestmysqludp/GuestPort" 3306
    VBoxManage setextradata "NBWebStack" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestmysqludp/HostPort" 3336
  3. Verify that the ports are forwarded by using the following command: VBoxManage getextradata "NBWebStack" enumerate.

Connecting With SSH (Optional)

With the SSH ports forwarded, you now have the option to connect remotely from the host with SSH. You could find this more convenient than using the text console on the guest in VirtualBox. SSH is included in most linux distributions by default. There is also a built-in SSH client on Mac OS. SSH is available on Windows systems by installing Cygwin and including the SSH package.

To connect remotely with the host using SSH, enter the command ssh -l osol -p 2222 localhost. You might need to accept a security certificate or resolve a conflict with an existing fingerprint.

To restart the Apache or MySQL services any time later, use the following commands from your SSH terminal:

pfexec svcadm restart apache22 
pfexec svcadm restart mysql

Deploying a PHP Test Application

Now that your web stack virtual machine is set up and your ports are forwarded, create a simple PHP application to test the connection to your virtual machine.

To deploy a PHP test application:

  1. Start the NBWebStack virtual machine, if it is not running.
  2. Start NetBeans IDE. Create a new PHP project, named WebStackTest, in your NetBeansProjects folder.
  3. In the Run Configuration panel, select FTP from the Run As: drop-down menu. Specify localhost port 8880 in the Project URL. Make certain that the directory in the Project URL matches the Upload Directory.
    Run Configuration page of New PHP Project wizard, showing FTP chosen and project URL including localhost:8880
  4. Click the Manage... button. The Manage Remote Connections wizard and Create New Connection dialog open.
    Name field in Create New Connection dialog
  5. Name the connection NBWebStack, select the FTP connection type (if using 6.7 or later) and click OK. You go to the main Manage Remote Connections page. Set the parameters on that page as follows:
    • Set the Host Name to the actual IP address of the host machine. Neither localhost nor 127.0.0.1 will work! Use ipconfig (Windows), or ifconfig (other systems) to find your real IP address. Also note that if you are connecting via DHCP, or if you are moving with your laptop between various local area networks, the IP address will change and you'll have to configure the FTP settings again (in Project Properties > Run Configuration > Manage...).
    • Port: 2221
    • User name: osol
    • Password: justone1
    • Initial Directory: /var/apache2/2.2/htdocs
    Manage Connection dialog showing real values
  6. Click Test. If you have set up the connection correctly, the message Connection Succeeded appears.
  7. If the test succeeds, click OK. You return to the Run Configuration panel. Click Finish.
  8. Open the WebStackTest project's default index.php file. Add phpinfo(); to the php section in the <body> element:
    <?php phpinfo(); ?> 
  9. Save index.php and run the project. A prompt opens to confirm that the IDE should upload index.php. Confirm the upload. The standard PHP info web page opens in your browser.

Testing XDebug in the Web Stack

OpenSolaris includes XDebug preconfigured in its PHP support. You can use this preconfigured XDebug to debug a PHP application deployed to the web stack without having XDebug on your host system.

To test XDebug in the Web Stack:

  1. Open the WebStackTest project's index.php file.
  2. Left-click the margin next to the line phpinfo();. This adds a breakpoint.
    Breakpoint added to index.php
  3. Debug the project, from the Debug menu or by pressing Ctrl-F5. (WebStackTest must be the main project!)

    If XDebug is properly configured, the debugger stops at the first PHP line in the IDE. The web browser displays a blank page, because the execution is halted in the index.php file. The IDE output shows that a breakpoint is enabled at the correct line.

    Output showing breakpoint tab
  4. Press F8 to step in the debugger. After the IDE steps over the phpinfo(); line, the browser shows the PHP info page.
  5. Press Shift-F5 to stop the debugging session.

Testing the MySQL Database Connection in the Web Stack

OpenSolaris includes a MySQL server in its PHP support. You can test the database connection from your project to the web stack's MySQL server. You do not need to run a MySQL database on your host system.

To test the MySQL Database Connection:

  1. Open the Services window and expand the Databases node.
    Services window showing Databases node
  2. Right-click on the Databases node and select Register MySQL Server. The MySQL Server Properties dialog opens.

    Note: You can have only one MySQL server registered at one time. If you already have a MySQL server registered, right-click on the server node and delete it from the list before registering the MySQL server in NBWebStack. You do not lose any of the database connections you created for the deleted server. You can delete the NBWebStack MySQL server and re-register your other MySQL server later.

    The MySQL Server Properties dialog showing all values
  3. Enter the following values and click OK:
    • Server Host Name: localhost
    • Server Port Number: 3336
    • Administrator User Name: osol
    • Administrator Password: justone1
  4. MySQL Server at localhost:3336 [osol] appears under the Databases node. Right-click on it and choose Connect.
  5. Expand the MySQL Server at localhost:3336 [osol] node. A list of available databases appears.
  6. Right-click on the node representing the Test database and choose Connect.... A new database connection appears under the Databases node. Now you can create tables in the Test database and view or modify their contents from the IDE.

You now have a correctly configured, server-only OpenSolaris web stack. You can develop PHP applications on NetBeans IDE in your preferred operating system and deploy them on the OpenSolaris web stack with the IDE's FTP functionality. You can use the OpenSolaris web stack's XDebug to debug your PHP applications without configuring XDebug in your native OS. You can also perform CRUD operations on the MySQL server in the web stack.


See Also

For more information about PHP technology on netbeans.org, see the following resources:

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