PHP: Difference between revisions
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
== Installation == | == Installation == | ||
The instructions here will enable you to compile (the latest version of) PHP for a prepackaged apache install. The | The instructions here will enable you to compile (the latest version of) PHP for a prepackaged apache install under a RedHat based system (such as CentOS, Fedora, ScientificLinux). The steps below will make use of {{code|apxs2}} from the {{code|http-tools}} package. | ||
{{highlight|lang=terminal|code= | {{highlight|lang=terminal|code= | ||
| Line 26: | Line 23: | ||
Run <code>make</code> and <code>make install</code>. If you had enabled apache apxs2 above, then it should have enabled the PHP module in apache. You may also want to add a custom php.conf file in /etc/httpd/conf.d/ with the following contents: | Run <code>make</code> and <code>make install</code>. If you had enabled apache apxs2 above, then it should have enabled the PHP module in apache. You may also want to add a custom php.conf file in /etc/httpd/conf.d/ with the following contents: | ||
{{highlight|lang=apache|code= | |||
# | # | ||
# PHP is an HTML-embedded scripting language which attempts to make it | # PHP is an HTML-embedded scripting language which attempts to make it | ||
| Line 57: | Line 54: | ||
AddType application/x-httpd-php-source .phps | AddType application/x-httpd-php-source .phps | ||
}} | |||
| Line 64: | Line 61: | ||
==== PDOException : could not find driver ==== | ==== PDOException : could not find driver ==== | ||
You need to have the pdo driver installed. In my case, I was trying to use the pdo-mysql connector which wasn't compiled with PHP. To fix this, install the PDO driver or compile it manually with: | You need to have the pdo driver installed. In my case, I was trying to use the pdo-mysql connector which wasn't compiled with PHP. To fix this, install the PDO driver or compile it manually with: | ||
{{highlight|lang=text|code= | |||
--with-pdo-<driver> | --with-pdo-<driver> | ||
}} | |||
In my case, I needed mysql: | In my case, I needed mysql: | ||
{{highlight|lang=text|code= | |||
--with-pdo-mysql | --with-pdo-mysql | ||
}} | |||
==== UTF-8 to hex ==== | ==== UTF-8 to hex ==== | ||
There is basically NO good way. | There is basically NO good way. | ||
http://www.tokyomuslim.com/2008/01/php-convert-utf-8-to-hex-codepoint-values-unicode-hexidecimal/ | * http://www.tokyomuslim.com/2008/01/php-convert-utf-8-to-hex-codepoint-values-unicode-hexidecimal/ | ||
http://hsivonen.iki.fi/php-utf8/ | * http://hsivonen.iki.fi/php-utf8/ | ||
==== Error Reporting ==== | ==== Error Reporting ==== | ||
{{highlight|lang=php|code= | |||
// Turn off all error reporting | // Turn off all error reporting | ||
error_reporting(0); | error_reporting(0); | ||
| Line 99: | Line 99: | ||
// Same as error_reporting(E_ALL); | // Same as error_reporting(E_ALL); | ||
ini_set('error_reporting', E_ALL); | ini_set('error_reporting', E_ALL); | ||
}} | |||
[[Category:Linux]] | [[Category:Linux]] | ||
[[Category:Code]] | [[Category:Code]] | ||
Revision as of 18:26, 13 January 2016
PHP is a server-side scripting library.
Installation
The instructions here will enable you to compile (the latest version of) PHP for a prepackaged apache install under a RedHat based system (such as CentOS, Fedora, ScientificLinux). The steps below will make use of apxs2 from the http-tools package.
## Install rpmforge repo
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
# rpm -K rpmforge-release-0.5.2-2.el6.rf.*.rpm
# rpm -i rpmforge-release-0.5.2-2.el6.rf.*.rpm
## Install all prerequisites.
# yum -y install make autoconf g++ gcc-c++ libtermcap-devel libgcc-c++ libtool gcc libpng-devel libjpeg-devel libxml1-devel libxml2-devel curl curl-devel libmcrypt libmcrypt-devel libtool-ltdl-devel libxml2.x86_64 libxml2-devel.x86_64 curl-devel.x86_64 openssl-devel httpd-devel
# Compile PHP
# Go to the PHP source directory, then run:
# ./configure --with-apxs2 --with-config-file-path=/etc --with-gd --enable-shmop --enable-ftp --enable-sockets --enable-exif --enable-zip --enable-sysvsem --enable-sysvsem --enable-sysvshm --with-jpeg-dir --with-png-dir --enable-mbstring --enable-embedded-mysqli=shared --with-curl --with-mcrypt --with-mysql --with-mysqli --with-openssl --with-zlib --with-pdo-mysql
Run make and make install. If you had enabled apache apxs2 above, then it should have enabled the PHP module in apache. You may also want to add a custom php.conf file in /etc/httpd/conf.d/ with the following contents:
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
# Cause the PHP interpreter to handle files with a .php extension.
AddHandler php5-script .php
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
AddType application/x-httpd-php-source .phps
Troubleshooting
PDOException : could not find driver
You need to have the pdo driver installed. In my case, I was trying to use the pdo-mysql connector which wasn't compiled with PHP. To fix this, install the PDO driver or compile it manually with:
--with-pdo-<driver>
In my case, I needed mysql:
--with-pdo-mysql
UTF-8 to hex
There is basically NO good way.
- http://www.tokyomuslim.com/2008/01/php-convert-utf-8-to-hex-codepoint-values-unicode-hexidecimal/
- http://hsivonen.iki.fi/php-utf8/
Error Reporting
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR