PHP
PHP scripts and tricks...
Submitted by sandip on Sat, 12/07/2013 - 13:35
Below is a summary of steps taken to get memcache support for php:
1. Install memcached and php-pear for pecl support to download and compile memcache for php.
yum --enablerepo=epel install memcached php-pear pecl install memcache
2. Configure memcached (/etc/sysconfig/memcached) and start it up:
chkconfig memcached on service memcached start
3. Create /etc/php.d/memcache.ini file with the below contents:
extension=memcache.so
4. Reload apache and/or php-fpm processes:
service httpd reload service php-fpm restart
5. Check with "php -i" or "phpinfo()" that memcache support is enabled.
6. Memcached listens to port 11211 by default. Status and stats:
memcached-tool localhost:11211 display memcached-tool localhost:11211 stats
Submitted by sandip on Tue, 08/10/2010 - 14:10
On CentOS, php-fpm can be easily installed via CentALT yum repository. This requires epel repository too and will pull down any dependencies if needed.
Install EPEL release:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm
Install CentALT release:
rpm -Uvh http://centos.alt.ru/repository/centos/5/x86_64/centalt-release-5-3.noarch.rpm
Install via yum:
yum --enablerepo=CentALT --enablerepo=epel install php-fpm
Look through and edit /etc/php-fpm.conf . The config options are well commented... also available at php-fpm.org
The default settings should work quite well.
Bring up the service via:
/etc/init.d/php-fpm start
Submitted by sandip on Sat, 03/13/2010 - 02:11
You can now get the latest PHP with mysqlnd (MySQL Native Driver) support via remis' yum repository as mentioned in PHP-5.3,-zts-and-mysqlnd. The blog mentions that this is enabld in php-zts. However, no php-pecl extension are available and neither are some of the extensions thread safe. So I went about rebuilding php package from source for mysqlnd support.
Download the source php rpm from http://rpms.famillecollet.com/SRPMS/ . Note, I have used php-5.3.2 which is the latest as of this writing.
Install and apply the below diff patch to the spec file via `patch -p0 < {new_patch_file}` where "new_patch_file" has the below contents:
--- php-5.3.2-remi.spec.orig 2010-03-11 23:07:04.000000000 -0600 +++ php-5.3.2-remi.spec 2010-03-11 23:36:03.000000000 -0600 @@ -24,6 +24,7 @@ %global phpversion 5.3.2 # Optional components; pass "--with mssql" etc to rpmbuild. +%define with_mysqlnd %{?_with_mysqlnd:1}%{!?_with_mysqlnd:0} %define with_oci8 %{?_with_oci8:1}%{!?_with_oci8:0} %define with_ibase %{?_with_ibase:1}%{!?_with_ibase:0} %if %{?rhel}%{?fedora} > 4 @@ -677,6 +678,11 @@ %if %{?fedora}%{?rhel:99} >= 10 --with-system-tzdata \ %endif +%if %{with_mysqlnd} + --with-mysql=shared,mysqlnd \ + --with-mysqli=shared,mysqlnd \ + --with-pdo-mysql=shared,mysqlnd \ +%endif $* if test $? != 0; then tail -500 config.log @@ -704,8 +710,13 @@ --enable-dba=shared --with-db4=%{_prefix} \ --with-xmlrpc=shared \ --with-ldap=shared --with-ldap-sasl \ +%if %{with_mysqlnd} + --with-mysql=shared,mysqlnd \ + --with-mysqli=shared,mysqlnd \ +%else --with-mysql=shared,%{_prefix} \ --with-mysqli=shared,%{_bindir}/mysql_config \ +%endif %ifarch x86_64 %{?_with_oci8:--with-oci8=shared,instantclient,%{_libdir}/oracle/%{oraclever}/client64/lib,%{oraclever}} \ %else @@ -725,7 +736,11 @@ --enable-fastcgi \ --enable-pdo=shared \ --with-pdo-odbc=shared,unixODBC,%{_prefix} \ +%if %{with_mysqlnd} + --with-pdo-mysql=shared,mysqlnd \ +%else --with-pdo-mysql=shared,%{_prefix} \ +%endif --with-pdo-pgsql=shared,%{_prefix} \ --with-pdo-sqlite=shared,%{_prefix} \ --with-pdo-dblib=shared,%{_prefix} \ @@ -756,6 +771,16 @@ --with-recode=shared,%{_prefix} popd +%if %{with_mysqlnd} +without_shared="--without-gd \ + --disable-dom --disable-dba --without-unixODBC \ + --disable-xmlreader --disable-xmlwriter \ + --without-sqlite \ + --disable-phar --disable-fileinfo \ + --disable-json --without-pspell --disable-wddx \ + --without-curl --disable-posix \ + --disable-sysvmsg --disable-sysvshm --disable-sysvsem" +%else without_shared="--without-mysql --without-gd \ --disable-dom --disable-dba --without-unixODBC \ --disable-pdo --disable-xmlreader --disable-xmlwriter \ @@ -764,6 +789,7 @@ --disable-json --without-pspell --disable-wddx \ --without-curl --disable-posix \ --disable-sysvmsg --disable-sysvshm --disable-sysvsem" +%endif # Build Apache module, and the CLI SAPI, /usr/bin/php pushd build-apache
Package with:
rpmbuild -bb --with mysqlnd --define "rhel 5" SPECS/php-5.3.2-remi.spec
To install via yum, change to the directory where rpms are located and recreate the repodata via:
createrepo .
Note: you may need to install some of the missing dependent devel packages. I used a combination of base, epel and remi repository to install the dependencies.
Submitted by sandip on Thu, 01/21/2010 - 16:11
As of writing, the current pecl runkit-0.9 package does not compile with PHP 5.2+ . Below is how I got the latest installed from svn trunk on CentOS-5.4 with php-5.2.9.
Install runkit:
svn co http://svn.php.net/repository/pecl/runkit/trunk/ cd trunk phpize ./configure make make install
Create "/etc/php.d/runkit.ini":
extension=runkit.so
Restart apache and validate with phpinfo.
Note: you would need php-pear and php-devel installed already.
Submitted by wizap on Tue, 02/26/2008 - 16:47
As of this writing, the latest versions were:
apache_1.3.41
php-4.4.8
openssl-0.9.8g
mod_ssl-2.8.31-1.3.41
Once the files are downloaded and extracted; config, compile and install in the below order:
Install openssl:
$ ./config --prefix=/usr/local --openssldir=/usr/local/openssl $ make # make install
mod_ssl patch:
$ ./configure \ --with-ssl=../openssl-0.9.8g \ --with-apache=../apache_1.3.41
Pre-configure apache:
$ ./configure
Install php:
$ ./configure \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-zlib-dir \ --with-freetype \ --with-freetype-dir=/usr/lib \ --enable-gd-native-ttf \ --enable-memory-limit \ --with-ldap \ --with-mysql \ --with-apache=../apache_1.3.41 $ make # make install
Install apache
$ SSL_BASE=../openssl-0.9.8g \ ./configure \ --prefix=/usr/local/apache \ --enable-module=rewrite \ --enable-module=so \ --activate-module=src/modules/php4/libphp4.a \ --enable-module=ssl
Submitted by wizap on Thu, 02/14/2008 - 12:26
Download and unpackage the source files:
$ cd /usr/local/src $ wget http://www.ibiblio.org/pub/mirrors/apache/httpd/apache_1.3.41.tar.gz $ wget http://us2.php.net/get/php-4.4.8.tar.gz/from/us.php.net/mirror $ tar -xvzf apache_1.3.41.tar.gz $ tar -xvzf php-4.4.8.tar.gz
Preconfigure apache:
$ cd apache_1.3.41 $ make clean $ ./configure
Configure, compile, install php:
$ cd ../php-4.4.8 $ make clean $ ./configure \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-zlib-dir \ --with-freetype \ --with-freetype-dir=/usr/lib \ --enable-gd-native-ttf \ --enable-memory-limit \ --with-ldap \ --with-mysql=/usr/local/mysql \ --with-apache=../apache_1.3.41 $ make # make install
Configure, compile, install apache:
$ ./configure \ --prefix=/usr/local/apache \ --enable-module=rewrite \ --enable-module=so \ --activate-module=src/modules/php4/libphp4.a $ make # make install
Submitted by sandip on Fri, 11/16/2007 - 16:36
Recently a particular folder in a site started coming up with blank php pages and the root cause being Segmentation fault after memory exhaustion. The subfolder contents would only come up after doing a restart of apache.
So something tried to access a region of memory that it did not have rights to. May be due to either bad RAM, or a code problem.
My first instinct was eAccelerator as I had done a recent php update and had not re-compiled it.
I still had the same issue the next day and bumped up the memory_limit from 16M to 32M in php.ini and from 32M to 64M in eaccelerator.ini .
Submitted by sandip on Fri, 09/07/2007 - 15:26
Download the source tar.gz file from php.net and place it in "/usr/local/directadmin/customapache"
Edit the "/usr/local/directadmin/customapache/build" file and change the version of php to the version that was downloaded.
Then run:
# cd /usr/local/directadmin/customapache/ # ./build clean # ./build update # ./build all
Restart apache when finished.
Submitted by sandip on Fri, 07/20/2007 - 12:41
Godaddys' linux hosting allows for editing your own "php.ini" file and enables support for logging errors, good for debugging purposes when developing with php.
Add the below lines to php.ini in the document root, to log all errors:
error_reporting = E_ALL log_errors = on error_log = /home/content/p/a/t/pathto/html/error_log
You should also protect the php.ini and error_log file via .htaccess:
<FilesMatch "(error_log|php\.ini)$"> Order deny,allow Deny from all </FilesMatch>
Submitted by sandip on Thu, 05/31/2007 - 16:20
Place the snippet of code in an index.php file to pull up a different web page for each domain pointed to the same web-space.
<? $serverName = $HTTP_HOST; $serverName = str_replace("www.","",$serverName); $serverName = str_replace(".com","",$serverName); $serverName = str_replace(".net","",$serverName); $serverName = str_replace(".org","",$serverName); if (!(empty($serverName))) { include("./".$serverName.".html"); } ?>
|