Sun Java Solaris Communities My SDN Account Join SDN
 
Article

Writing Your First Web Application Using PHP on the Solaris OS

 
Writing a web application with PHP on the Solaris OS is now very easy using the new Solaris Express Developer Edition (SXDE). This article contains information on creating a sample program using PHP on the Solaris OS and was developed from the NetBeans IDE tutorials. It also provides an introduction to SXDE and the web stack integrated with it, and explains the procedure to create a "Hello World" program in PHP using the web stack integrated with SXDE.

The intended audience is developers who are new to the Solaris OS and SXDE.

Contents
 

Requirements

In this tutorial, you use the web stack in SXDE to create a sample PHP program. You must install the latest edition of SXDE on your machine because it includes the components (PHP, NetBeans IDE, and Apache web server) that are required to perform the steps provided in this tutorial.

You can download SXDE from the Sun web site.

Introduction to SXDE

SXDE is a version of the Solaris OS that includes the latest technologies, platforms, and tools to create applications for the Solaris OS. It includes a completely integrated and easy-to-use web stack with Apache, PHP, and MySQL. It also has a complete development environment with Sun Studio software that includes compilers optimized for C, C++, and Fortran. The Solaris OS includes the NetBeans IDE, an open-source integrated development environment and application platform, which can be used as a generic framework to build all kinds of applications. The Sun xVM hypervisor software included in SXDE allows you to run virtual machine hosts with guest operating systems such as Microsoft Windows and Linux on the Solaris OS.

Introduction to Web Stack in SXDE

SXDE comes with an integrated web stack that is ready to use once you complete the installation. The web stack is a collection of open-source software used to build and deploy web applications on the Solaris OS. To manage the services in the web stack, SXDE provides a control panel to enable services quickly and easily.

Components available as part of the web stack include:

  • Apache 2.2.6
  • MySQL 5.0.45
  • PHP 5.2.4
  • NetBeans IDE 6.0.1
  • PostgreSQL 8.2.5
  • Ruby 1.8.6
  • Squid 2.6

Apache 2.2.6
Apache is one of the most popular web servers. It is the web server component of the popular LAMP web server application stack, along with MySQL and PHP. It is a free, open-source, extensible web server. In SXDE, Apache web server has a PHP module integrated into it.

MySQL 5.0.45
MySQL is an open-source database management system that is fast, highly reliable, and easy to use. SXDE includes a 32-bit version of the MySQL database.

PHP 5.2.4
PHP is a powerful server-side scripting language used for creating dynamic web pages. It is very popular because of its suitability for web development. PHP is often used with Apache web server.

NetBeans IDE 6.0.1
The NetBeans IDE is a free, open-source integrated development environment. Using the NetBeans IDE, you can create professional desktop, enterprise, web, and mobile applications easily and efficiently.

PostgreSQL 8.2.5
PostgreSQL is an object-relational database management system (ORDBMS). It runs on almost all major operating systems including Linux, most versions of UNIX, and Microsoft Windows. It has native programming interfaces for most programming languages including C/C++, the Java language, .Net, Perl, Python, and Ruby.

Ruby 1.8.6
Ruby is an object-oriented programming language for creating web pages. It is a dynamic, open-source language with an elegant syntax.

Squid 2.6 proxy server
Squid is an HTTP/1.0 proxy server that offers a rich access control, authorization, and logging environment to develop web proxy applications and content serving applications.

Tutorial

In this tutorial, you use the web stack in SXDE to create a "Hello World" program in PHP. The first step is to initialize the web stack in SXDE, which displays the options in the control panel for enabling services. You then start the Apache web server for running the PHP program. After the Apache web server is started, you must set up the environment for developing the PHP program.

To create the PHP program, you use the NetBeans IDE for PHP that is included with SXDE. After you register the Apache server with the NetBeans IDE, you can write and run the PHP program.

The steps are provided in detail in the following four sections:

Initializing the SXDE Web Stack

As the first step in creating a PHP project, you must initialize the web stack. This step enables the options for the SXDE web stack, and then you can start the Apache web server.

To initialize the Solaris web stack:

  1. Click All Applications > Developer Tools > Web Stack Admin > Initialize.  

    Starting the Web Stack Initialization Process
    Figure 1: Starting the Web Stack Initialization Process
    Click here for a larger image.
     

    The Password Required window appears.

  2. Enter the root password and click Continue.  

    Entering the Root Password height=
    Figure 2: Entering the Root Password
    Click here for a larger image.
     

    The web stack is initialized.

  3. Press Enter to continue.  

    Continuing Web Stack Installation
    Figure 3: Continuing Web Stack Installation
    Click here for a larger image.
     
  4. Click All Applications > Developer Tools > Web Stack Admin > Start Apache2/MySQL Servers to start the Apache web server and MySQL database.  

    Starting the Apache and MySQL Servers
    Figure 4: Starting the Apache and MySQL Servers
    Click here for a larger image.
     

    The Apache and MySQL servers are started.

Preparing the Development Environment

After you initialize the web stack and start the Apache web server, you must register and configure the Apache web server with the NetBeans IDE.

To register and configure the Apache web server with the NetBeans IDE:

  1. Click All Applications > Developer Tools > NetBeans PHP IDE 6.0.  

    Starting the NetBeans PHP IDE 6.0
    Figure 5: Starting the NetBeans PHP IDE 6.0
    Click here for a larger image.
     

    The NetBeans PHP IDE 6.0 starts.

  2. On the left side of the screen, click the Services tab.  

    Selecting the Services Tab
    Figure 6: Selecting the Services Tab
    Click here for a larger image.
     
  3. Right-click Web Servers and then select Add Web Server in the NetBeans IDE.  

    Adding a Web Server
    Figure 7: Adding a Web Server
    Click here for a larger image.
     

    The Add New Web Server Record wizard appears.

  4. Enter a connection name for the web server, select Local Web Server with File Access for Server Type, and click Next.  

    Adding a New Web Server Record
    Figure 8: Adding a New Web Server Record
    Click here for a larger image.
     

    The Find Configured Hosts screen appears.

  5. Select Manual Configuration. Enter the path to the Apache 2 configuration file, or select the path to the Apache configuration file. The default path of the Apache configuration file is /etc/apache2/2.2/httpd.conf. The host name for the local host is displayed automatically. Click Next to continue.  

    Specifying the Apache 2 Configuration File
    Figure 9: Specifying the Apache 2 Configuration File
    Click here for a larger image.
     

    The Configure Http Server screen appears.

  6. Accept the default values for configuring the HTTP server, or provide the values for your system, and then click Next.  

    Configuring the HTTP Server
    Figure 10: Configuring the HTTP Server
    Click here for a larger image.
     

    The Configure File Access screen appears.

  7. Accept the default path for the Apache Document Root (the directory location of the root document). Click Finish to close the Add New Web Server Record wizard.  

    Accepting the Default Path
    Figure 11: Accepting the Default Path
    Click here for a larger image.
     

Creating a PHP Project

In this procedure, you create a PHP project for displaying "Hello World" using the NetBeans PHP IDE.

To create a PHP project:

  1. Click File > New Project to open a new project.  

    Opening a New Project
    Figure 12: Opening a New Project
    Click here for a larger image.
     

    The Choose Project screen appears.

  2. Click PHP Project from the listed PHP categories and then click Next.  

    Creating a New Project
    Figure 13: Creating a New Project
    Click here for a larger image.
     

    The Name and Location screen appears.

  3. Enter the project name, accept default settings for project location and project folder, and click Next.  

    Specifying the Project Name and Location
    Figure 14: Specifying the Project Name and Location
    Click here for a larger image.
     

    The Web Server Configuration screen appears.

  4. Select the server name you registered or the name of the target server for your PHP project and click Finish.  

    Configuring the Web Server
    Figure 15: Configuring the Web Server
    Click here for a larger image.
     

    The NetBeans PHP IDE editor appears.

  5. Create the "Hello World" PHP program by entering the code into the NetBeans PHP IDE editor, as shown in Figure 16.  

    Entering the Program Code
    Figure 16: Entering the Program Code
    Click here for a larger image.
     
  6. Save the program. Then select the project and click Run to run the program and see "Hello World" displayed in a browser.  

    Running the 'Hello World' Program
    Figure 17: Running the 'Hello World' Program
    Click here for a larger image.
     

Modifying the PHP Code

To modify the existing code of the PHP program by applying HTML tags to change size and font:

  1. In the NetBeans PHP IDE editor, apply the font tag inside the body tag to change the color and font size of the "Hello World" text.  

    Applying Font Tags
    Figure 18: Applying Font Tags
    Click here for a larger image.
     
  2. Save the program. Then select the project and click Run to run the program and see "Hello World" displayed with the new font size and color in a browser. If the browser does not immediately display the changes, refresh the browser.  

    Running the Modified 'Hello World' Program
    Figure 19: Running the Modified 'Hello World' Program
    Click here for a larger image.
     

For More Information

After you finish the tutorial, use the links in this section to learn more.

Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.