Marked as: Normal
Hello,
Here's my script to automatically configure PHP5, Apache and PHPPGAdmin so you can use you web browser to add tables and configure Postgres databases.
The installation script for Postgres should be used first, but I may have anticipated that someone would try the opposite.
Download PHPPgAdmin ( http://phppgadmin.sourceforge.net/ (http://phppgadmin.sourceforge.net/), the Beta is OK to use as well ), PHP5 ( http://www.smedley.info/os2ports/index.php?page=php-5 (http://www.smedley.info/os2ports/index.php?page=php-5) ) and Apache ( http://www.smedley.info/os2ports/index.php?page=apache2 (http://www.smedley.info/os2ports/index.php?page=apache2) ) and unzip them to some folders.
You can then run the following script that will create/update a folder on you desktop with some icons.
Note that you may want to change the entry "Europe/Berlin" in the code below if you live in another time zone. Also ensure that you start Postgres (see other post on how to install it) before you run Apache/PHP.
You can then point your web browser to phppgadmin by specifying the local ip address... http://127.0.0.1 and log on with the name you specified during creation of the database (see other post).
The user PHPPgAdmin interface is available in many languages and is quite easy to use. You can export and import data there as well.
/* REXX Script to configure PHP5 and PhpPGAdmin */
Call Time 'R'
CALL RxFuncAdd 'SysCls', 'RexxUtil', 'SysCls'
call SysCls
say ''
call Meter 0, 1
CALL RxFuncAdd 'SysDriveMap', 'RexxUtil', 'SysDriveMap'
drives = SysDriveMap();
drives.0 = WORDS( drives );
CALL RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
DO i = 1 TO drives.0
say 'Searching drive '||subword( drives, i, 1 )||' for PHP...one moment please.'
call Meter i / drives.0, drives.0 * 3
call SysFileTree subword( drives, i, 1 )||'\*php.exe', 'php_path', 'SFO'
stpath = strip( filespec( 'D', php_path.1 )||filespec( 'P', php_path.1 ), 'T', '\' )
if php_path.0 > 0 then
leave i
END
if php_path.0 = 0 then do
say "Couldn't find PHP..."
Return -1
end
DO i = 1 TO drives.0
say 'Searching drive '||subword( drives, i, 1 )||' for phpPGAdmin...one moment please.'
call Meter i / drives.0 + drives.0, drives.0 * 3
call SysFileTree subword( drives, i, 1 )||'\*sqledit.php', 'phppgadmin_path', 'SFO'
phpgconf = phppgadmin_path.1
a_len = LASTPOS( '\', phpgconf ) - 1
if a_len < 1 then iterate i
phppgadmin_path = LEFT( phpgconf, a_len )
if phppgadmin_path.0 > 0 then
leave i
END
if phppgadmin_path.0 = 0 then do
say "Couldn't find phpPGAdmin..."
Return -2
end
DO i = 1 TO drives.0
say 'Searching drive '||subword( drives, i, 1 )||' for Apache...one moment please.'
call Meter i / drives.0 + 2 * drives.0, drives.0 * 3
call SysFileTree subword( drives, i, 1 )||'\*httpd.conf', 'apache_path', 'SFO'
aconf = apache_path.1
a_len = LENGTH( aconf ) - 16
if a_len < 1 then iterate i
apache_path = LEFT( aconf, a_len )
if apache_path.0 > 0 then
leave i
END
if apache_path.0 = 0 then do
say "Couldn't find Apache..."
Return -3
end
etcpath = value( 'etc', , 'OS2ENVIRONMENT')
filedef = stpath||'\php.ini-recommended'
fileconf = etcpath||'\php.ini'
crlf= '0d0a'x
lf = '0a'x
replace_from.1 = 'memory_limit = 8M'
replace_tgt.1 = 'memory_limit = 32M ; Maximum amount of memory a script may consume (8MB)'
replace_from.2 = 'extension_dir = "./"'
replace_tgt.2 = 'extension_dir = "'||stpath||'\modules"'
replace_from.3 = 'upload_max_filesize = 2M'
replace_tgt.3 = 'upload_max_filesize = 10M'
replace_from.4 = ';extension=php_xsl.dll'
replace_tgt.4 = ';extension=php_xsl.dll'||lf,
'extension=bz2.dll'||lf,
'extension=curl.dll'||lf,
'extension=dbase.dll'||lf,
'extension=exif.dll'||lf,
'extension=filepro.dll'||lf,
'extension=gd.dll'||lf,
'extension=gettext.dll'||lf,
'extension=mbstring.dll'||lf,
'extension=mysql.dll'||lf,
'extension=mysqli.dll'||lf,
'extension=openssl.dll'||lf,
'extension=pdo_mysq.dll'||lf,
'extension=pdo_sqli.dll'||lf,
'extension=pgsql.dll'||lf,
'extension=sqlite.dll00'
replace_from.5 = 'date.timezone ='
replace_tgt.5 = 'date.timezone = Europe/Berlin' /* can you determine this at runtime please?! */
replace.0 = 5
apache_startup = apache_path||'\startup.cmd'
apache_startup.conf = '@echo off'||lf,
'SET LIBPATHSTRICT=T'||lf,
'SET BEGINLIBPATH='||strip( apache_path, 'T', '\' )||'\bin;'||strip( apache_path, 'T', '\' )||'\modules;'||lf,
strip( filespec( 'D', apache_path ), 'T', '\' )||lf,
'cd '||strip( filespec( 'P', apache_path )||filespec( 'N', apache_path ), 'T', '\' )||lf,
'bin\httpd -d . 2>&1'
apache_shutdown = apache_path||'\shutdown.cmd'
apache_shutdown.conf = '/* Rexx script to shut down Apache */'||lf,
'pid = linein("logs\httpd.pid")'||lf||"'kill.exe -TERM '||pid"
say ""
say "PHP:"
say "Reading from: "||filedef
say "Configures: "||fileconf
say ""
say "Apache:"
say "Reading from: "||aconf||'.sample'
say "Configures: "||aconf
say "Startup Apache: "||apache_startup
say "Shutdown Apache:"||apache_shutdown
apache_path = translate( apache_path, '/', '\' )
CALL RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
CALL RxFuncAdd 'SysCurPos', 'RexxUtil', 'SysCurPos'
/* update php.ini */
f_size.0 = Stream( filedef, 'C', 'QUERY SIZE' ) + Stream( aconf, 'C', 'QUERY SIZE' )
f_size = 0
outlines = ""
i = 1
do while( lines( filedef ) )
rec = linein( filedef )
f_size = f_size + length( rec )
if time( 'E' ) > 0.5 then
call Meter f_size, f_size.0
/* substitute data */
if POS( replace_from.i, rec ) > 0 then do
rec = replace_tgt.i
i = i + 1
end
outlines = outlines||rec||crlf
end
rc = Stream( filedef, 'C', 'Close' )
rc = SysFileDelete( fileconf )
call lineout fileconf,, 1
call lineout fileconf, outlines
rc = Stream( fileconf, 'C', 'Close')
replace_from.1 = 'ServerRoot "/apache2"'
replace_tgt.1 = 'ServerRoot "'||filespec( 'P', apache_path )||filespec( 'N', apache_path )||'"'
replace_from.2 = '# LoadModule vhost_alias_module modules/vhost_al.dll'
replace_tgt.2 = '# LoadModule vhost_alias_module modules/vhost_al.dll'||lf,
'Loadmodule php5_module modules/modphp5.dll'
replace_from.3 = 'DocumentRoot "/apache2/htdocs"'
replace_tgt.3 = 'DocumentRoot "'||phppgadmin_path||'"'
replace_from.4 = '<Directory "/apache2/htdocs">'
replace_tgt.4 = '<Directory "'||phppgadmin_path||'">'
replace_from.5 = ' DirectoryIndex index.html'
replace_tgt.5 = ' DirectoryIndex index.html index.htm index.html.var index.php'
replace_from.6 = ' ScriptAlias /cgi-bin/ "/apache2/cgi-bin/"'
replace_tgt.6 = ' ScriptAlias /cgi-bin/ "'||filespec( 'P', apache.path )||filespec( 'N', apache_path )||'/cgi-bin/"'
replace_from.7 = '<Directory "/apache2/cgi-bin">'
replace_tgt.7 = '<Directory "'||filespec( 'P', apache.path )||filespec( 'N', apache_path )||'/cgi-bin/">'
replace_from.8 = '#AddOutputFilter INCLUDES .shtml'
replace_tgt.8 = ' #AddOutputFilter INCLUDES .shtml'||lf||lf,
' # For PHP Scripts'||crlf,
' AddType application/x-httpd-php .php'||lf,
' AddType application/x-httpd-php-source .sphp'||lf||lf
replace.0 = 8
rc = SysFileDelete( apache_startup )
call lineout apache_startup,, 1
call lineout apache_startup, apache_startup.conf
rc = Stream( apache_startup, 'C', 'Close')
rc = SysFileDelete( apache_shutdown )
call lineout apache_shutdown,, 1
call lineout apache_shutdown, apache_shutdown.conf
rc = Stream( apache_shutdown, 'C', 'Close')
outlines = ""
i = 1
do while( lines( aconf||'.sample' ) )
rec = linein( aconf||'.sample' )
f_size = f_size + length( rec )
if time( 'E' ) > 0.5 then
call Meter f_size, f_size.0
/* substitute data */
if POS( replace_from.i, rec ) > 0 then do
rec = replace_tgt.i
i = i + 1
end
outlines = outlines||rec||crlf
end
call Meter f_size.0, f_size.0
rc = Stream( aconf||'.sample', 'C', 'Close' )
rc = SysFileDelete( aconf )
call lineout aconf,, 1
call lineout aconf, outlines
rc = Stream( aconf, 'C', 'Close')
If SysCreateObject( 'WPFolder', 'Postgres 8.x', '<WP_DESKTOP>', 'OBJECTID=<PGSQL8>', 'u' ) Then
If SysCreateObject( 'WPProgram', 'Start Apache', '<PGSQL8>', 'EXENAME='||apache_startup, 'u' ) Then
If SysCreateObject( 'WPProgram', 'Stop Apache', '<PGSQL8>', 'EXENAME='||apache_shutdown, 'u' ) Then
say 'Installation done!'
Return 0
Meter:
parse value SysCurPos( 18, 0 ) with row col
SAY left( COPIES( '█', ( ARG(1) * 80 ) % ARG(2) ), 80, '░' )
call SysCurPos row, col
RETURN;