{{parent page="WebServer" }} ===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== ~ [[PHPI18n I18n using gettext]] ~ [[PHPSecurity PHP Security]] ~ [[PHPFastCGI Running php as fastcg on apache2]] ~ [[PHPMixedVersion Running multiple versions on the same web server]] ~ [[PHPUpload Upload]] ~ [[PHPOptimizers PHPOptimizers]] ~ [[PHPCode PhpCode]] ~ [[PHPBuildRpm Build RPM]] ~ [[PHPXcache Xcache]] ~ [[PHPEaccelerator eAccelerator]] ~ [[PHPsuPHP suPHP]] ===php security issues=== http://www.securephpwiki.com/index.php/Email_Injection ===php5 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 %%(bash) ./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 %% To test php & mysql, write a simple php page to fetch records. First, create a table on the test database: %%(sql) create table first_table(name varchar(20), id integer); insert into first_table (name) values ('name1'); insert into first_table (name) values ('name2'); commit; %% Then retrieve these records from php: %%(php;sqltest.php) \n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t\n"; foreach ($line as $col_value) { echo "\t\t$col_value\n"; } echo "\n"; } echo "\n"; // Free resultset mysql_free_result($result); //Closing connection mysql_close($link); ?> %% === Compiling PHP on system with pre-installed PHP === Obtain existing configure options by %%(bash) php -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 %% 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 ~{{color [text="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" [c="blue"]}} ~~{{color [text="CentOS5: yum -y install libxml2-devel libpng-devel freetype-devel pcre-devel aspell-devel curl-devel ncurses-devel bzip2-devel zlib-devel openssl-devel libjpeg-devel gmp-devel gd-devel mysql-devel libxslt-devel " [c="blue"]}} ~*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...) == %%(bash) ./configure 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. %%(bash) # phpize Configuring for: PHP Api Version: 20020918 Zend Module Api No: 20020429 Zend Extension Api No: 20021010 %% In php source directory %%(bash) rm ./configure ./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.so do 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. %%(php;phpinfo.php) %% ==Sample php.ini to start with== %%(text;php.ini) [PHP] 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 %%