|By Sriram Natarajan and Marina Sum, November 21, 2006|
Part 1 of this series describes how to set up and configure JSPWiki and then deploy it to Sun Java System Web Server 7.0 (henceforth, Web Server 7.0), Sun's latest Web Server release, now in technology preview. Part 2 shows you how to deploy a PHP technology-based Wiki site, such as MediaWiki, on Web Server.
MediaWiki is free softwarea wiki package that was originally written for Wikipedia. Presently, MediaWiki is the wiki of choice of several other projects of the nonprofit Wikimedia Foundation and other collaborative authoring sites.
Note: Type each of the command lines in this article on one line even though, because of screen width constraints, some of them wrap to the next line.
|-||Understanding the Prerequisites|
|-||Installing Web Server 7.0|
|-||Configuring MySQL for MediaWiki|
|-||Configuring PHP With Web Server 7.0|
|-||Verifying PHP Configurations for FastCGI|
|-||Transposing PHP Configurations to the Repository|
|-||Configuring MediaWiki With Web Server 7.0|
|-||Securing Your MediaWiki Site|
|-||Appendix: Troubleshooting Tips|
To host MediaWiki, first install the following components:
Download the latest Technology Preview release of Web Server 7.0. For details, see its Installation and Migration Guide and this blog.
MediaWiki stores user-created wikis in a database, such as MySQL or PostgreSQL, both of which are bundled with the Solaris 10 Operating System (OS) and Linux. For simplicity, this article describes how to install MySQL on those two platforms.
If you did not install MySQL as part of the default installation of the Solaris OS or Linux, simply download the tar ball version of the MySQL server's community edition, available for free on the MySQL site.
To install MySQL on Solaris 10 OS and Linux:
# groupadd mysql
# useradd -g mysql mysql
# gunzip -c mysql-standard-5.0.27-platform
.tar.gz | tar xvfp -
/usr/local/mysql, or to the location in which you would like to install the MySQL server. Type:
# mv mysql-standard-5.0.27-platform
# chown -R mysql:mysql /usr/local/mysql
# chmod -R 755 /usr/local/mysql
INSTALL-BINARYdocuments that accompany the distribution.
configurescript to configure your MySQL server settings:
# cd /usr/local/mysql
# ./bin/mysqladmin -u root passwordpassword
Afterwards, verify that the installation is successful:
# ./bin/mysql -u root -p
To run a test query from the
Note this strong recommendation: While hosting MediaWiki, store your users' wikis in a separate database. If you have root access to MySQL, the recent releases of MediaWiki, such as version 1.8.x, can automatically create such a database and you need not do so manually. Otherwise, ask your database administrator to do the following:
# mysql -u root - pMySQL-root-password
# create database wikidb;
# grant create, select, insert, update, delete, lock tables on wikidb.* to wiki@localhost identified byMySQL-root-password
# flush privileges;
You can then store your users' wikis in the
Recall that MediaWiki internally uses PHP scripts along with databases like MySQL. To deploy MediaWiki, you must first install PHP and a database, both configured for Web Server 7.0. As with any other open-source software, you have several options for installing and configuring PHP with Web Server 7.0.
You can configure PHP either as an NSAPI or as a FastCGI plug-in. For details on the differences between those two plug-ins and their pros and cons, read the article Using PHP on Sun Java System Web Server .
For simplicity, this article describes the steps for configuring PHP as a FastCGI plug-in with Web Server 7.0.
You can compile and install PHP from the source, that is, download PHP from
php.net and compile PHP yourself. However, you might want to first install the GNU utilities from the Solaris 10 installation CD or DVD.
Note: If you're already using a different distribution of PHP, verify that its binaries are MediaWiki-capable. See the next subsection.
To compile PHP on the Solaris and Linux platforms:
SUNWgcc, all available on the CD or DVD and on the Freeware for Solaris site.
libxml2package by default. If you did not install that package, do so either from the Solaris 10 installation CD or DVD or download
libxml2from Freeware for Solaris.
bison, from your Linux distribution CD or DVD.
libxml2, download and install the
libxml2-develpackages from either your distribution or from the XML C parser and toolkit of Gnome site.
# bunzip2 -c php-5.1.6.tar.bz2 | tar xvfp -
# cd php-5.1.6
PATHenvironment variable to reflect the new location so that the downloaded GNU utilities are in your path.
setenv PATH /bin:/usr/bin:/usr/sfw/bin:/usr/local/bin:/usr/ccs/bin:$PATH
# ./configure --enable-fastcgi --with-mysql=MySQL-install-dir
/usr/local/php/bin. To install in another directory, add the
--prefix=PHPinstall-dir option, where PHP-install-dir is your preferred installation location.
/usr/local/mysql, add the option
configurescript cannot find the location of the
libxml2binaries, manually specify that location by adding the option
--with-libxml-dir, for example,
--with-libxml-dir=/usr/localor the location in which you installed
# gmake install
For more details on the installation procedure:
To verify whether your distribution's PHP binaries are MediaWiki-capable:
phpinfo.phpwith the following content.
<?php phpinfo(); ?>
If your distribution's PHP binaries do not support MySQL or other databases, compile PHP from the source.
To execute PHP scripts, configure the Web Server 7.0 instance on which to deploy MediaWiki. As a reference, read the article Using PHP on Sun Java System Web Server .
By default, during installation, Web Server 7.0 creates a configuration-cum-instance with the same host name as your machine name.
You can do either of the following:
php, with the Web Server 7.0 Administration Server and then deploy PHP support on that configuration. For the procedure, see Chapter 2 in the Sun Java System Web Server 7.0 Administrator's Guide .
/configdirectory, where CONFIG is the name of the configuration of your current Web Server 7.0 server instance.
/bin/wadm --user=admin list-configs
Read on for the specifics of the second option. In the steps in the following subsections, be sure to replace CONFIG with the appropriate configuration name, such as
At startup, Web Server 7.0 reads the
magnus.conf file to determine which plug-ins to load. Revise this file so that Web Server 7.0 can load the FastCGI plug-in when it starts. Follow these steps:
Init fn=load-modules shlib="libfastcgi.so"
Depending on the configuration, the Web Server 7.0 Administration Server creates either a default
obj.conf file or a virtual-server-specific object file in the Web-Server-install-dir
obj.conf configures FastCGI servers to be accessed (or executed) only for certain directories, file types, URI patterns, other elements of the HTTP request (User-Agent version, date), or any combination of those components.
With Web Server 7.0, the Administration Sever can create the
obj.conf file in either of these two ways:
-obj.conf, for example, CONFIG
While starting up or executing dynamic reconfiguration, Web Server reads this object file. To find out which file is in use by the server process, type:
/bin/wadm get-virtual-server-prop --user=admin --config= CONFIG
The output shows the file name, either
obj.conf or VS
-obj.conf, depending on your configuration.
Now specify in the appropriate file how Web Server 7.0 handles PHP scripts. Based on the output, edit the file by adding the bold lines in the following code segment.
<Object name="Default"> ... # Add the following lines after other NameTrans directives. # # Make /wiki the MediaWiki URI. # To access MediaWiki under a different URI or from a different installation location, # specify that value. # NameTrans fn="pfx2dir" from="/wiki" dir="/usr/local/mediawiki" # To make Web Server execute index.php as default page for a directory, edit the # PathCheck directive. # PathCheck fn="find-index" index-names="index.html,home.html,index.jsp" PathCheck fn="find-index" index-names="index.html,home.html,index.jsp,index.php" # Add the following lines after other Service directives. # This can be a single line or a line continued according to the syntax below. # The following example mentions the commonly required LD_LIBRARY_PATH location # for the Solaris and Linux platforms. Add or edit the values, depending on where your # libraries and binaries are installed. Service type="magnus-internal/php" fn="responder-fastcgi" bind-path="localhost:3101" app-path="/usr/local/php/bin/php" app-env="PHP_FCGI_MAX_REQUEST=200" app-env="LD_LIBRARY_PATH=/usr/local/php/lib/php:/usr/local/mysql/lib/mysql:/usr/ local/lib:/usr/sfw/lib:/usr/sfw/lib/mysql" app-env="PHPRC=/usr/local/php/lib/php" ... </Object>
Here are the explanations for the changes:
bind-path="localhost:3101" This line makes PHP run at port 3101 on your machine. Feel free to specify another port number. Ensure that the port of your choice is not in use by another program on your machine.
app-path="/usr/local/php/bin/php" This line tells Web Server where to look for the PHP binary. This example assumes that FastCGI-compliant PHP resides under
/usr/local/php/bin/php. If PHP resides in a different location, specify that location accordingly.
app-env="LD_LIBRARY_PATH=/usr/local/php/lib/php:/usr/local/mysql/lib/mysql: This line tells FastCGI that PHP needs the dependent libraries as specified and directs FastCGI to look for them in those locations. If you have other dependencies, also specify their locations here.
app-env="PHPRC=/path/to/php/config/dir" This line shows PHP FastCGI where to look for the
php.inifile. That file contains all the directives for customizing the behavior of PHP in your machine.
PHPRCenvironment variable must point to the directory for the
php.inifile, not to the file itself.
For details on the directives and on the procedure for configuring FastCGI in Web Server 7, see Appendix C in the Sun Java System Web Server 7.0 Administrator's Guide .
At startup, Web Server 7.0 reads the
mime.types file to determine how to handle various file types, for example, those with a
.php extension. Specifically, this file assigns certain file extensions to the type
magnus-internal/php, which tells Web Server 7.0 whether to serve a file or run it as a CGI.
Add this line to the bottom of the
That line instructs Web Server 7.0 to consider the file extensions
php5 as a type owned by FastCGI. Subsequently, rather than serving the matching file, Web Server 7.0 runs it through the plug-in.
Now verify if Web Server 7.0 can configure PHP scripts:
phpinfo.phpwith the following line. Save the file in your document root directory.
<?php phpinfo(); ?>
/sun/webserver7/https-hostname server instancewhere hostname is the name of the machine on which the instance is runningcan now execute PHP scripts. The default document root location for that instance is
/phpinfo.php, where portnumber is the number of the port on which the server instance is running.
Security Note: For security, because the sample file
phpinfo.php is full of user information, once you have verified that your configurations support PHP scripts, consider deleting that file.
Finally, transpose the manual edits for the
mime.types files to the Web Server 7.0 Administration Server's configuration repository. Perform that task on the command line or from the Administration Console.
Start the Administration Server and then type:
dir/bin/wadm pull-config --user=admin --config= CONFIG hostname
where CONFIG is the name of the configuration that contains the above file changes.
Installing MediaWiki is a simple process. Just unpack and place the downloaded tar ball in a location of your choice, as follows:
/usr/localand rename the folder to delete the version information. For example, on the UNIX and Linux platforms, type:
% gunzip -c mediawiki-1.8.2.tar.gz | tar xvfp -
% mv mediawiki-1.8.2 /usr/local/mediawiki
/usr/local/mediawiki, a location that this article refers to as MediaWiki-install-dir.
By now, you have configured Web Server 7.0 to execute PHP scripts and run MediaWiki when a user accesses the
/wiki URI in a browser. This section describes the configurations for executing MediaWiki within Web Server 7.0.
You must inform the Web Server 7.0 Server instance of the location of the MediaWiki binaries. Do that in either of these two ways:
NameTransdirective to the content of the object file. See "
/admin-server/bin/startservand then go to
configimage that contains PHP support.
/wikias the URI to access MediaWiki and
/usr/local/mediawikias the directory path. To access MediaWiki from a different URI or if you installed MediaWiki in a different location, specify the appropriate values here.
Next, set up the wiki:
(Click image for larger view.)
(Click image for larger view.)
LocalSettings.phpfile in the
configdirectory to its parent directory.
As a precaution, remove the write permission to the
config directory and click "this link" at the bottom of the MediaWiki Installation page.
You can protect your MediaWiki site from vandalism in many ways. A couple of them are as follows:
php.inifile. Most PHP distributions include two sample
php.inifiles in your installation directory, as follows:
php.ini-dist Contains suggested settings for deployment as reference. Familiarize yourself with those settings and their implications before deploying them to production.
php.ini-recommended Contains recommended settings from PHP developers.
Accompanying those files is detailed documentation. Familiarize yourself with the settings and choose what best fits your needs with emphasis on security. If you are using the Web Server 7.0 FastCGI plug-in, you can specify the location of your
php.ini file with the
app-env environment variable, like this:
Note: Specify the directory name, not the file name, for php.ini-file-location. For details, see "
obj.conf or Virtual-Server-Specific
obj.conf File ."
If you run into problems after configuring PHP as a FastCGI plug-in with Web Server 7.0 and MediaWiki with PHP and MySQL support on top of Web Server 7.0, these tips might help solve the problems.
configure: error: libxml2 version 2.6.11 or greater required.
libxml2binaries on your machine.
libxml2package for your platform and then reconfigure PHP by adding the option
--with-libxml-dir=libxml2-install-dir, where libxml2-install-dir is where you installed
my.cnfor the permissions for the MySQL data directory contain errors.
/var/mysql/hostname.err, where hostname is the name of the machine for the MySQL server. That file describes the causes for the failure of the MySQL server
config: CONF2257: Error parsing fileobj.conf, line 51, column 12: Expected "="
php -fcgiobjects within
obj.conffile, as appropriate, to correct the error. Refer to "
Method Not Allowed
An error has occurred.
HTTP2205: The request method is not applicable to the requested resource
obj.conffile that contains no PHP configurations.
/bin/wadm get-virtual-server-prop --user=admin --config=CONFIG
phpinfo.php, you encounter one of these two error messages:
ERROR 500: Server Error
ERROR 500: No Permission
app-pathvariable ise incorrect.
/usr/local/php/bin/php -b localhost:3104
lddon the PHP binary. Be sure to add as anargument the location of all your dependent libraries to
phpinfo.phpscript with PHP to check if the PHP compilation is in order.
3101, which acts as the argument to
obj.confFile "), is in use by another process.
netstat -an | grep 3101. If so, the PHP FastCGI plug-in cannot bind to that port number. Specify another port number as the argument for
--enable-fastcgi, a separate program, such as
php-cgi, then resides under PHP-installation-dir. In this case, use
php-cgias an argument to
app-envin the (see
phpinfo.phpfile, the following error message is displayed:
ERROR 500: Server Process Creation Failure
lddon PHP and ensure that the appropriate dependent libraries are in place as arguments for the
app-envvariable for configuring the object file.
ERROR 500: Server Error:
for host 127.0.0.1 trying to GET /phpinfo.php, func_exec reports: HTTP2302: Function responder-fastcgi aborted the request without setting the status code
No input file specified
mime.typesfile with the PHP extensions.
Servicedirective in the server configuration's object file to describe how to process files with a PHP extension.
obj.confor Virtual-Server- Specific
LocalSettings.phpfile in MediaWiki-install-dir
/configbefore MediaWiki completes the configuration.
LocalSettings.phpfile into the
configdirectory and then reconfigure MediaWiki.
--disable-path-info-checkoption. If so, recompile without that option.
Error 2048 Not safe to rely on system's timezone settings
php.inifile does not exist or is incomplete.
GMT, depending on your location.
php.inifile does not exist, look at the
php.ini-recommendedfile in PHP-source-dir from which you compiled the PHP binaries and then create a
php.inifile with the two-line code above. Place the file in the PHP-install-dir
/lib/phpdirectory, in which the PHP runtime looks for the
obj.conffile within Web Server 7, to configure PHP to read
php.inifrom another directory, set up the
PHPRCenvironment variable to point to that directory.