If you have a shared hosting environment you will find it is not straight forward to install WSO2 WSF/PHP + PHP DataServices Library since you have very limited authority on your environment. Here in this post, I’m explaining the steps I followed in setting up my custom PHP, WSF/PHP Extension and DataServices library for http://ws.dimuthu.org (This is a shared hosting environment from dreamhost based on LAMP stack) which I’m using to expose my blog as a WebService.
Prerequisites:
- You should be able to run PHP using mod_fastcgi (not using mod_php) in Apache. That allows you to configure your own php environment.
- The server configurations managed by the hosting service should allow you to handle .php extension from your own CGI executable (here it is php.cgi), If not, you can still try with setting some other extension (say .phq or .qhq, anything not .php) to be handled by your php-cgi. Anyway if your hosting service allow you to run CGI then most probably you have this permission.
- You should have the access to the shell (using SSH) and should be able to use development libraries(libxml, libxsl, libopenssl) + build tools (make)
- There can be some other restrictions that your hosting service has put on you, that I have not experienced with my hosting service. So please check your hosting service support and documentation for possibility of building your own PHP environment.
Install PHP:
I have extracted out most of the steps from dreamhost documentation on custom php.ini.
- Download PHP and compile. You should at least enable –enable-fastcgi –enable-force-cgi-redirect in the configuration.
./configure --enable-fastcgi --enable-force-cgi-redirect --with-xsl --with-openssl --prefix=`pwd`/dist make make install
Note: from here on, php source directory is referred as <php_source_directory>
I have installed the php to <php_source_directory>/dist since we mostly don’t have permission to install it in to default location. (/usr/local). From here on I will be referring php installation directory as <php_install_dir> - create a directory called ‘cgi-bin’ to your web document root directory(<document_root_directory>) and copy the <php_source_directory>/dist/bin/php-cgi in to that. (before php version 5.2.1 there is no php-cgi generated, you can just copy the php to the cgi-bin directory). And rename the php-cgi to php.cgi.
cp <php_install_direcory>/bin/php-cgi <document_root_directory>/cgi-bin/php.cgi
- copy <php_source_direcory/php.ini-dist to the cgi-bin directory and rename it as php.ini, this can be used to configure your php environment.
cp <php_source_directory/php.ini-dist <document_root_directory>/cgi-bin/php.ini
- Create .htaccess file in the cgi-bin directory to allow the access to php-cgi and php.ini files.
cat << EOF ><document_root_directory>/cgi-bin/.htaccess Options +ExecCGI -Indexes +FollowSymLinks <FilesMatch "php(.?)\\.(cgi|ini)$"> Order Deny,Allow Deny from All Allow from env=REDIRECT_STATUS </FilesMatch> EOF
- Create .htaccess file in the root directory redirect all the requests for .php extensions to go through our php-cgi.
cat << EOF > <document_root_directory>/.htaccess AddHandler php-cgi .php Action php-cgi /cgi-bin/php.cgi EOF
If your hosting service doesn’t allow to handle .php just rename the end of the first line to some other extension.
- Check the necessary permissions levels in files.
chmod 644 <document_root_directory>/.htaccess chmod 755 <document_root_directory>/cgi-bin chmod 644 <document_root_directory>/cgi-bin/.htaccess chmod 644 <document_root_directory>/cgi-bin/php.ini chmod 755 <document_root_directory>/cgi-bin/php.cgi
That’s it. Now your .php files should be run on your own php environment. Just to check whether it is working or not create a phpinfo() file.
cat <<EOF > phpinfo.php <?php phpinfo(); ?> EOF
And go to the http://yourdoman.com/phpinfo.php and verify that it is your custom php environment .
Installing WSF/PHP
- Download WSF/PHP latest version and extract it to any of your preferred directory(<wsf_php_source_directory>).
- Set the PATH environment variable to search for your custom php installation first.
- From the same shell go to the <wsf_php_source_directory> and compile it.
./configure make make install
- Now check where you have installed wsf/php. it is in fact the extension dir shown by the php-config command.
php-config --extension-dir
I will refer this directory as <php_extension_directory>
- Open the <document_root_directory>/cgi-bin/php.ini an set the extension directory, enable wsf extension and set the include path to the wsf scripts directory.cat <<EOF >> <wsf_php_source_directory>/cgi-bin/php.ini
cat <<EOF >> <wsf_php_source_directory>/cgi-bin/php.ini extension_dir=<php_extension_directory> extension=wsf.so include_path=".:<wsf_php_source_directory>/scripts" EOF
If you found that you can only put relative directories in your php.ini (that happens when you don’t even have the read access to your root directory ‘/’), follow the workaround mentioned in here, http://phpwebservices.blogspot.com/2008/08/installing-wsfphp-in-third-party.html
export PATH=<php_install_dir>/bin:$PATH
That’s all. Just check the phpinfo (created earlier section) whether your configurations and the wsf extension are loaded correctly. In order to test the functionality copy the wsf/php samples to the web document root and access them from the browser. Go to each sample and verify they function as expected.
cp /samples <wsf_php_source_directory>/ -R
And go to http://yourdomain.com/samples and click on each samples. If this not working most probably your localhost to ip mapping is wrong, most probably this problem is there in your shared host. Just go to the samples directory and change the endpoint to the domain name in place of ‘localhost’ in each client and try it again.
Installing PHP DataServices:
- Download and unpack PHP DataServices. <php_data_services_directory>
- Update the include_path entry in php.ini to DataServices libraries directory as well. So the <wsf_php_source_directory>/cgi-bin/php.ini file now has the following entry.
include_path=".:<wsf_php_source_directory>/scripts:<php_data_services_directory>/lib"
That’ all for the DataService installation. Please read <php_data_services_directory>/README to run the samples. Anyway if you are sure you did followed these simple steps correctly, go on with your DataService development. Specially if you have wordpress database, you may start straight away with the making wordpress a DataService.
I wonder if I can find someone who can help me in installation of php5 and then wsf/php on my account on dreamhost.
Did you follow the above steps?
I’ve tries so many times. and every time I got a different error message. I’m really tired of it:( I need someone to help me and I’ll be more than happy to pay for it..
WSO2, The company behind WSF/PHP is giving support for WSF/PHP and bunch of their other products. You can access them from http://wso2.com/contact/.
Well, I’ve contacted with them and they send me back the link for this post:)
Anyway my problem is not onlye wsf/php installation. I need help to install and compile both php 2.5.6 and wsf/php.
Your tutorial is great, but I ran into some some trouble. It seems like there is an issue with PHP 5.3.x and the latest 2.0 release of WSF, so I downgraded to PHP 5.2.7 and things seemed to build just fine. The only other issue I’ve run into is now I am getting an error when I try to run the sample scripts. From my error log:
[Wed Mar 10 13:37:39 2010] [error] dep_engine.c(1021) Axis2 Configuration file name not found
[Wed Mar 10 13:37:39 2010] [error] dep_engine.c(884) axis2.xml is not available in client repo /home/slotmedia/wso2-wsf-php-src-2.0.0/wsf_c
[Wed Mar 10 13:37:39 2010] [error] conf_init.c(195) Loading deployment engine failed for client repository /home/slotmedia/wso2-wsf-php-src-2.0.0/wsf_c
I see the axis2.xml in my install directory, but I am not sure what setting is incorrect. Any ideas would be appreciated.
Hi Joe,
You should set the wsf.home entry in the php.ini to the installation directory (not to the wso2-wsf-php-src-2.0.0/wsf_c) directory. In the installation directory you will find there is an axis2.xml inside the conf directory.
Thanks
Dimuthu