Skip to main content

Converting a simple site from ASP to PHP

Posted in

Maybe I'm a glutton for punishment, but I've taken on a project for which I've promised to convert a site from ASP to PHP so that it can be expanded using some tools already written in PHP. The site is basically static HTML, just using ASP for include files and some minor formatting settings.

Here are the steps I followed to convert the site from ASP to PHP:

  1. Change the file extensions from .asp to .php (this handles it recursively):
    1. find . -name "*.asp" | while read file;
    2. do
    3. mv $file `echo $file | sed 's/\(.*\.\)asp/\1php/'`;
    4. done
  2. Run sed commands to convert PHP code into ASP code:
    1. find . -name "*.php" -print | xargs sed -i "s/^'/# /"
    2. find . -name "*.php" -print | xargs sed -i 's/<%/<?php/'
    3. find . -name "*.php" -print | xargs sed -i 's/%>/?>/'
    4. find . -name "*.php" -print | xargs sed -i 's/PageVar = "\(.*\)"/$PageVar = "\1";/'
    5. find . -name "*.php" -print | xargs sed -i 's/SubNav = "\(.*\)"/$SubNav = "\1";/'
    6. find . -name "*.php" -print | xargs sed -i 's/SubVar = "\(.*\)"/$SubVar = "\1";/'
    7. find . -name "*.php" -print | xargs sed -i 's/SideBar = "\(.*\)"/$SideBar = "\1";/'
    8. find . -name "*.php" -print | xargs sed -i 's/iPodSticky = "\(.*\)"/$iPodSticky = "\1";/'
    9. find . -name "*.php" -print | xargs sed -i 's/AuthorSticky = "\(.*\)"/$AuthorSticky = "\1";/'
    10. find . -name "*.php" -print | xargs sed -i 's/BookSticky = "\(.*\)"/$BookSticky = "\1";/'
    11. find . -name "*.php" -print | xargs sed -i 's/<!--#include file="\([^"]*\)"-->/<?php include("\1") ?>/'
    12. find . -name "*.php" -print | xargs sed -i 's/=(\(.*\))/echo $\1/'
    13. find . -name "*.php" -print | xargs sed -i 's/\.asp/.php/'
    14. find . -name "*.php" -print | xargs sed -i 's/IF Request\.QueryString("id") <> "" THEN/if($_REQUEST["id"]) {/'
    15. find . -name "*.php" -print | xargs sed -i 's/id = Request.QueryString("id")/$id = $_REQUEST["id"];/'
    16. find . -name "*.php" -print | xargs sed -i 's/End if/}/'
    17. find . -name "*.php" -print | xargs sed -i 's/; + PageVar/ . $PageVar;/'
  3. Turned off open_basedir and safe mode in Plesk, following advice found here.
    Created a vhost.conf file in the /conf directory:
    1. <Directory /var/www/vhosts/<DOMAIN.TLD>/httpdocs>
    2. php_admin_value safe_mode off
    3. php_admin_value open_basedir none
    4. </Directory>
    And rebuild the configuration files:
    1. /usr/local/psa/admin/sbin/websrvmng -u --vhost-name=<DOMAIN.TLD>