Create IBM i HTTP Server from Command Line

Here are some instructions on how to create a HTTP server from your IBM® i server command line.

The first thing we will do, is copy an existing APACHE SERVER that is defined within the IBM i Integrated Web Server. To do this, let's use PDM:

WRKMBRPDM FILE(QUSRSYS/QATMHINSTC)
WRKMBRPDM FILE-QUSRSYS-QATMHINSTC

Enter option 3 next to APACHEDFT, and COPY the definition to your new proposed webserver name. Change the To member (TOMBR) or label parameter to whatever you wish to name your new HTTP server. We will use <NEWSERVER> for use throughout this lesson.

NOTE: If you dont have PDM you can copy this member just as easily using CPYF

NEWSERVER

Once the member is created, type 18 next to the member name to edit with DFU. We cannot use PDM 2 for SOURCE EDIT because this i not a source file. Of course,  you can use any other file editor you may prefer.

NEWSERVER HTTP Server Edit with DFU

Now, simply scroll through the file, looking for any values that contain the old APACHEDFT value and update them to match our new server name <NEWSERVER>.

Find the Server name and change:

-apache -d /www/apachedft -f conf/httpd.conf -AutoStartN

and change this to:

-apache -d /www/<NEWSERVER> -f conf/httpd.conf -AutoStartN
apachedft in DFU

Obviously <NEWSERVER> is the name of the source member, and new Apache HTTP Server, you just created.

You also have the option of setting your new HTTP server <NEWSERVER> so that the server is started every time the STRTCPSVR *HTTP *ALL command is entered. Alternatively, change to -AutoStart N to allow the server to only start when you select it manually (or from the WEBUI).

Press F3 to Save/Exit.

Define IFS components of the HTTP Server

The HTTP Server has its main definition in the IFS. So, lets create the subfolders.

Type the following commands from the 5250 command line:

MKDIR '/www/<NEWSERVER>'
MKDIR '/www/<NEWSERVER>/conf'
MKDIR '/www/<NEWSERVER>/logs'
MKDIR '/www/<NEWSERVER>/htdocs'

Once again, <NEWSERVER> is the name of your new HTTP Server (but you knew that right?)

Now we need to load a very important file into the IFS 'CONF' folder

Create httpd.conf

The 'httpd.conf' file is the main configuration file for the Apache HTTP Server. It contains directives that control the server's behavior and settings. Here are some key points about 'httpd.conf':

  • Location: The file is typically located in the '/etc/httpd/conf/' directory on Unix-based systems.
  • Directives: It includes various directives that define how the server should operate, such as setting the document root, configuring virtual hosts, and specifying which modules to load.
  • Syntax: The file uses a plain text format where each directive is written on a new line. Comments can be added using the '#' character.
  • Customization: You can customize the server's behavior by editing this file. For example, you can change the port number the server listens on or set up URL rewriting rules.

Copy the httpd.conf file from the following location:

/www/apachedft/conf

to your new <serverName> location

/www/<NEWSERVER>/conf

You can do this easily with the CPY command:

CPY OBJ('/www/apachedft/conf/httpd.conf') TODIR('/www/<NEWSERVER>/conf')

When this is completed you should have an IFS location and subfolders for your new HTTP Server that look like this:

NEWSERVER IFS

Edit this new httpd.conf and scan and replace all references of apachedft to <NEWSERVER>.

Now your HTTP server has been created and is ready. Any changes to what port it listens on or configuration options can be done by editing the httpd.conf file.

For example, the Listen *:80 directive in the httpd.conf file instructs the HTTP server to listen on port 80 for all TCP interfaces. If you want your HTTP server to listen on a different port, change the port number in the Listen directive.

This is the file you will EDIT to change the REST YAJL webservices that will be called ... but more on that in the next TWEAKING YAJL lesson 😉

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>