PHP
php is a web scripting language from the last generation. It's fast to write but hard to maintain. Anyone who has studied software engineering will find this "language" a nightmare.Subtopics
I18n using gettext
PHP Security
Running multiple versions on the same web server
Upload
PHPOptimizers
PhpCode
Build RPM
Xcache
eAccelerator
PHP Security
Running multiple versions on the same web server
Upload
PHPOptimizers
PhpCode
Build RPM
Xcache
eAccelerator
php security issues
http://www.securephpwiki.com/index.php/Email_Injectionphp5 typical source configure options (64bit redhat)
In any case, you will need libtool-ltdl-devel to the least./configure --with-libdir=lib64 --libdir=/usr/lib64 --with-apxs2=/usr/local/apache2/bin/apxs \ --sysconfdir=/etc --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 \ --with-curl --with-freetype-dir=/usr --with-png-dir=/usr --with-gd=shared --enable-gd-native-ttf \ --without-gdbm --with-gettext --with-iconv --with-jpeg-dir=/usr \ --with-openssl --with-pspell --with-xmlrpc=shared --with-regex=php --with-zlib \ --with-layout=GNU --enable-bcmath --enable-exif --enable-ftp --enable-magic-quotes \ --enable-sockets --with-mysql=shared,/usr --with-mysqli --enable-shmop \ --enable-calendar --enable-mbstring=shared --enable-mbregex \ --enable-pcntl --enable-wddx --with-libxml-dir=/usr --with-mcrypt=/usr
If you do not need so much crap, here is a minimal install
./configure --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d \ --prefix=/usr --with-mysql=shared,/usr --with-mysqli=shared,/usr/bin/mysql_config \ --enable-mbstring --with-apxs2=/usr/sbin/apxs
Compiling PHP5 /w mysql5 & GD & Apache2 & Mysqli support
The following is tested on FreeBSD6.2.Note: There seems to be a problem compiling the following plus MagickWand. If MagickWand is compiled at the same time, it will stop at mysql_error.
Install first from source
zlib-1.2.3
gd-2.0.43
autoconf (ports)
autoheader (ports)
unixODBC (ports)
"patch" php source with magickwand
MySQL-5.0.37 binary in /usr/local/mysql
gd-2.0.43
autoconf (ports)
autoheader (ports)
unixODBC (ports)
"patch" php source with magickwand
MySQL-5.0.37 binary in /usr/local/mysql
./configure \
--host=i386-FreeBSD-6.2 \
--build=i386-FreeBSD-6.2 \
--target=i386-FreeBSD-6.2 \
--with-apxs2=/usr/local/sbin/apxs \
--with-mysql=/usr/local/mysql \
--with-zlib=/usr/local \
--enable-ftp \
--enable-versioning \
--with-gd=/usr/local \
--with-unixODBC=/usr/local \
--with-mysqli=/path_to/mysql_config
# seems not working --with-mysql=shared,/usr/local/mysql
# will not compile with --with-magickwand=/usr/local
--host=i386-FreeBSD-6.2 \
--build=i386-FreeBSD-6.2 \
--target=i386-FreeBSD-6.2 \
--with-apxs2=/usr/local/sbin/apxs \
--with-mysql=/usr/local/mysql \
--with-zlib=/usr/local \
--enable-ftp \
--enable-versioning \
--with-gd=/usr/local \
--with-unixODBC=/usr/local \
--with-mysqli=/path_to/mysql_config
# seems not working --with-mysql=shared,/usr/local/mysql
# will not compile with --with-magickwand=/usr/local
To test php & mysql, write a simple php page to fetch records. First, create a table on the test database:
CREATE TABLE first_table(name varchar(20), id integer);
INSERT INTO first_table (name) VALUES ('name1');
INSERT INTO first_table (name) VALUES ('name2');
commit;
INSERT INTO first_table (name) VALUES ('name1');
INSERT INTO first_table (name) VALUES ('name2');
commit;
Then retrieve these records from php:
sqltest.php
<?php
$link = mysql_connect('127.0.0.1','root','')
or die('Cannot connect:' . mysql_error());
echo 'Connected successfully.';
mysql_select_db('test') or die('Could not select database test');
// Perform sql query
$query = 'SELECT * from first_table';
$result = mysql_query($query) or die('Query failed:' . mysql_error());
// Print result in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
// Free resultset
mysql_free_result($result);
//Closing connection
mysql_close($link);
?>
$link = mysql_connect('127.0.0.1','root','')
or die('Cannot connect:' . mysql_error());
echo 'Connected successfully.';
mysql_select_db('test') or die('Could not select database test');
// Perform sql query
$query = 'SELECT * from first_table';
$result = mysql_query($query) or die('Query failed:' . mysql_error());
// Print result in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
// Free resultset
mysql_free_result($result);
//Closing connection
mysql_close($link);
?>
Compiling PHP on system with pre-installed PHP
Obtain existing configure options byphp -i | grep configure
# pipe configure command to a file
php -i | grep configure | sed s/#039//g | sed s/\&\;//g | cut -d\> -f5 | cut -d\< -f1 > phpconf
# pipe configure command to a file
php -i | grep configure | sed s/#039//g | sed s/\&\;//g | cut -d\> -f5 | cut -d\< -f1 > phpconf
Obtain php source code and use the same configure options to compile php
Compiling PHP with imap-2006 source
This is one of those things...1. Download imap source from http://www.washington.edu/imap/
2. Extract to /usr/local/imap-2006k
3. make IP6=4 lrh
4. mkdir /usr/local/imap-2006k/lib
5. mkdir /usr/local/imap-2006k/include
6. cp /usr/local/imap-2006k/c-client/*.h /usr/local/imap-2006k/include/
7. cp /usr/local/imap-2006k/c-client/*.c /usr/local/imap-2006k/lib/
8. cp /usr/local/imap-2006k/c-client/c-client.a /usr/local/imap-2006k/lib/libc-client.a
9. configure php with these options: --with-imap=/usr/local/imap-2006k --with-imap-ssl=/usr/loca./imap-2006k
Compiling PHP with ImageMagick and MagickWand support
Assuming php is already installed on RHEL4 in form of rpm and I want to add additional modules to php. BTW, RHEL is crap. Go for CentOS with yum if you absolutely need redhat compability.The dependencies are horrible. I have no idea why php get so popular.
Obtain the followings
ImageMagick
MagickWand
up2date httpd-devel libxml2-devel libxslt-devel libjpeg-devel libpng-devel freetype-devel pcre-devel imap-devel aspell-devel net-snmp-devel unixODBC-devel curl curl-devel gcc4 gmp-devel ncurses-devel bzip2-devel compat* libc-client-devel libc-client zlib-devel openssl-devel e2fsprogs-devel libidn-devel openldap-devel libmcrypt-devel aspell-devel libtool-ltdl libtool-ltdl-devel
*if php is complaining about libjpeg.so and libpng.so not found, just create links to /usr/lib/libjpeg.so.x /usr/lib/libjpeg.so
unixODBC (src install --disable-gui)
(on some fucked systems like RHEL4, get from rpm.pbones.net) uw-imap-devel-2006g libc-client2006
pcre 7.2 (src install)
Php source (preferably matching major version of running php)
MagickWand
up2date httpd-devel libxml2-devel libxslt-devel libjpeg-devel libpng-devel freetype-devel pcre-devel imap-devel aspell-devel net-snmp-devel unixODBC-devel curl curl-devel gcc4 gmp-devel ncurses-devel bzip2-devel compat* libc-client-devel libc-client zlib-devel openssl-devel e2fsprogs-devel libidn-devel openldap-devel libmcrypt-devel aspell-devel libtool-ltdl libtool-ltdl-devel
*if php is complaining about libjpeg.so and libpng.so not found, just create links to /usr/lib/libjpeg.so.x /usr/lib/libjpeg.so
unixODBC (src install --disable-gui)
(on some fucked systems like RHEL4, get from rpm.pbones.net) uw-imap-devel-2006g libc-client2006
pcre 7.2 (src install)
Php source (preferably matching major version of running php)
x86_64 workaround
The new way:
--with-libdir=lib64 --libdir=/usr/lib64
The old way:
# ln -s /usr/include /opt/include
# ln -s /usr/lib64 /opt/lib
set these in your ./configure and it should compile
--with-jpeg-dir=/opt --with-png-dir=/opt --with-mysql=/opt --with-imap=shared,/opt
# Then if you see an error with make, try
EXTRA_CFLAGS=-fPIC make
Install ImageMagick (make will take some time...)
./configure
make && make install
# verify
/usr/local/bin/convert logo: logo.gif
make && make install
# verify
/usr/local/bin/convert logo: logo.gif
Install MagickWand to php source
Extract MagickWand source to php's source under the ext folder. Rename MagickWand's folder to magickwand. Go in the magickwand directory and run the following.# phpize
Configuring for:
PHP Api Version: 20020918
Zend Module Api No: 20020429
Zend Extension Api No: 20021010
Configuring for:
PHP Api Version: 20020918
Zend Module Api No: 20020429
Zend Extension Api No: 20021010
In php source directory
rm ./configure
./buildconf --force
./buildconf --force
Compile php by appending the followings to the existing configure option. To obtain existing configure options, issue php -i | grep configure
--with-magickwand=IMG_MGCK_DIR(/usr/local) --with-apxs2=/usr/sbin/apxs make
Replace existing php binary and libphp4.so
backup /usr/bin/php and /etc/httpd/modules/libphp4.sodo a make install in php source
Configure Apache
If apache is not configured previously, add the following line to make apache recognize php files:AddType application/x-httpd-php .php
Testing
Write a simple php page with phpinfo() inside. The resulting web page should contain a section of magickwand.phpinfo.php
Sample php.ini to start with
php.ini
[PHP]
extension_dir = "/usr/lib/20060613"
extension = mysql.so
extension = gd.so
extension = imap.so
extension_dir = "/usr/lib/20060613"
extension = mysql.so
extension = gd.so
extension = imap.so
MBString
In addition, if MBString is necessary, it can be compiled in easily. Simply compile php --with-mbstirng=all and then add the followings to php.ini; Set default language mbstring.language = Neutral; Set default language to Neutral(UTF-8) (default) mbstring.language = English; Set default language to English mbstring.language = Japanese; Set default language to Japanese ;; Set default internal encoding ;; Note: Make sure to use character encoding works with PHP mbstring.internal_encoding = UTF-8 ; Set internal encoding to UTF-8 ;; HTTP input encoding translation is enabled. mbstring.encoding_translation = On ;; Set default HTTP input character encoding ;; Note: Script cannot change http_input setting. mbstring.http_input = pass ; No conversion. mbstring.http_input = auto ; Set HTTP input to auto ; "auto" is expanded to "ASCII,JIS,UTF-8,EUC-JP,SJIS" mbstring.http_input = SJIS ; Set HTTP2 input to SJIS mbstring.http_input = UTF-8,SJIS,EUC-JP ; Specify order ;; Set default HTTP output character encoding mbstring.http_output = pass ; No conversion mbstring.http_output = UTF-8 ; Set HTTP output encoding to UTF-8 ;; Set default character encoding detection order mbstring.detect_order = auto ; Set detect order to auto mbstring.detect_order = ASCII,JIS,UTF-8,SJIS,EUC-JP ; Specify order ;; Set default substitute character mbstring.substitute_character = 12307 ; Specify Unicode value mbstring.substitute_character = none ; Do not print character mbstring.substitute_character = long ; Long Example: U+3000,JIS+7E7E
There are 987 comments on this page. [Display comments]