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.
- 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.
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 .
- 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.
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
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.
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.