Information Technology Center, The University of Tokyo

Campus-wide Computing Research Division

Home > Campus-wide Computing Research Division > Services > WEB PARK > FAQ > ■How to operate files which have .htlm or .htm extension as PHP.

■How to operate files which have .htlm or .htm extension as PHP.


[Notes] This is the method for advanced users. There is no guarantee that you will be able to use it in the same way in the future. If a security problem occurs in PHP program, you will need to deal with the problem by yourself. Therefore, we do not recommend this method.

It is possible to copy to and use a PHP program that is on the server provided by Sakura Internet on /home/webparkNNNN/www.
The following method assumes that you are using a terminal software (Terminal on Mac or Tera Term on Windows).

1. Copy the CGI version of PHP on the server under /home/webparkNNNN/www
% cp /usr/local/php/5.6/bin/php-cgi ~/www/php.cgi

2. Change the permission of the copied program to 705.
% ls -l ~/www/php.cgi
-rwxr-xr-x 1 webparkNNNN users 33761644 Jan 18 16:43 /home/webparkNNNN/www/php.cgi

% chmod 705 ~/www/php.cgi
% ls -l ~/www/php.cgi
-rwx—r-x 1 webparkNNNN users 33761644 Jan 18 16:43 /home/webparkNNNN/www/php.cgi

3. Use .htaccess so that the copied php.cgi can be use with .html file.
Add the following two lines to .htaccess in the directory (or the folder one level higher) which has the file you would like to operate.
Action myphp-script /php.
cgi AddHandler myphp-script .html