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.
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.
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.
Start Virtual Box. Select File > Virtual Media Manager. The Virtual Media Manager opens.
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.
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.
On the main Virtual Box panel, click the New icon or press Ctrl-N. The New Virtual Machine wizard opens on the welcome page.
Click Next. The VM Name and OS Type page opens. Type NBWebStack for the name. Select the Solaris operating system and the OpenSolaris version.
Click Next. The Memory page opens. Select a base memory size of 768 MB.
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.
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.
Click the Settings icon, or press Ctrl-S. The Settings dialog for NBWebStack opens.
Select the Network category. Change the Adapter Type to PCnet-FAST III.
Click OK.
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:
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.)
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.
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:
Start the NBWebStack virtual machine, if it is not running.
Start NetBeans IDE. Create a new PHP project, named WebStackTest, in your NetBeansProjects folder.
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.
Click the Manage... button. The Manage Remote Connections wizard and Create New Connection dialog open.
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
Click Test. If you have set up the connection correctly, the message Connection Succeeded appears.
If the test succeeds, click OK. You return to the Run Configuration panel. Click Finish.
Open the WebStackTest project's default index.php file. Add phpinfo(); to the php section in the <body> element:
<?php phpinfo(); ?>
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:
Open the WebStackTest project's index.php file.
Left-click the margin next to the line phpinfo();. This adds a breakpoint.
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.
Press F8 to step in the debugger. After the IDE steps over the phpinfo(); line, the browser shows the PHP info page.
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:
Open the Services window and expand the Databases node.
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.
Enter the following values and click OK:
Server Host Name: localhost
Server Port Number: 3336
Administrator User Name: osol
Administrator Password: justone1
MySQL Server at localhost:3336 [osol] appears under the Databases node. Right-click on it and choose Connect.
Expand the MySQL Server at localhost:3336 [osol] node. A list of available databases appears.
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.
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.