Archive

Archive for the ‘Guides’ Category

PHP 5.3 symlink() in Windows Vista and Server 2008

June 17th, 2009

I just discovered that Vista can create symbolic links via the command mklink! It performs the same thing as ln in linux with both hard and soft links. My understanding of links is fairly limited but I use them on my web server to apply seam-less templates. Until now, this was something that I could only test on my web server and not my Windows 7 development PC. PHP 5.3 automatically uses the mklink command when you use symlink() but the problem comes with enabling it in Windows Vista or 7.

If you pull up a command prompt and try to use mklink, you’ll see something like this:

D:\Web>mklink /D nnnnn.com\content templates\bluemoon
You do not have sufficient privilege to perform this operation.

Or PHP will throw this back at you:

Debug Warning: /includes/templates.inc.php line 78 - symlink() [function.symlink]: Cannot create symlink, error code(1314)

To fix this:

  1. Bring up your run box, type “secpol.msc” and click OK.
  2. Navigate under the Security Settings \ Local Policies \ User Rights Assignment folder.
  3. Find “Create symbolic links” and add the Users group to it.

I think you need to restart your computer or something after doing this.

Josh Guides, Web Development , , , , , ,

Install PHP 5.3.0 on CentOS 5 as CGI along side PHP 5.2.9

June 16th, 2009

Well, turns out I’d rather play with just PHP 5.3 RC4 for now. Here is my guide to installing it onto my CentOS 5 64-bit VPS from 1&1.

Update: PHP 5.3.0 has been released and there are some changes.

It went pretty smoothly. Here is the guide, minus the hours of trial and error, of course:

First, install anything you may need to compile with.

yum install gcc gcc-c++.x86_64

yum install \
  libicu-devel.x86_64 \
  libxml2-devel.x86_64 \
  mysql-devel.x86_64 \
  libpng-devel.x86_64 \
  libjpeg-devel.x86_64 \
  curl-devel.x86_64 \
  bzip2-devel.x86_64 \
  gettext-devel.x86_64 \
  gmp-devel.x86_64 \
  pcre-devel.x86_64 \
  freetype-devel.x86_64 \
  gd-devel.x86_64 \
  aspell-devel.x86_64

NOTE: You can copy that entire block and paste it, the backslash (\) will carry the command over to the next line automatically.

Next, make the folders for the configs and binaries.

mkdir /usr/local/php53 /etc/php53 /etc/php53.d


Begin, by downloading and extracting the latest snapshot. Don’t use the file name I have below, get it fresh from snaps.php.net.

cd ~
wget http://us2.php.net/get/php-5.3.0.tar.bz2/from/us.php.net/mirror
tar xjf php-5.3.0.tar.bz2
cd php-5.3.0.tar.bz2

# gz: tar xzf php-5.3.0.tar.gz
# bz2: tar xfj php-5.3.0.tar.bz2
# zip: tar xfZ php-5.3.0.zip


Now, set up all of your configuration options. You may want to adjust these. To see what they mean, type: ./configure --help

./configure \
  --prefix=/usr/local/php53 \
  --with-libdir=lib64 \
  --with-config-file-path=/etc/php53 \
  --with-config-file-scan-dir=/etc/php53.d \
  --with-bz2 \
  --with-curl \
  --with-exec-dir=/usr/bin \
  --with-freetype-dir=/usr \
  --with-png-dir=/usr \
  --enable-gd-native-ttf \
  --without-gdbm \
  --with-gettext \
  --with-gmp \
  --with-iconv \
  --with-jpeg-dir=/usr \
  --with-openssl \
  --with-png-dir=/usr \
  --with-pspell \
  --with-libexpat-dir=/usr \
  --with-pcre-regex=/usr \
  --with-zlib \
  --with-layout=GNU \
  --enable-exif \
  --enable-ftp \
  --enable-magic-quotes \
  --enable-sockets \
  --enable-sysvsem \
  --enable-sysvshm \
  --enable-sysvmsg \
  --enable-wddx \
  --with-kerberos \
  --enable-ucd-snmp-hack \
  --enable-shmop \
  --enable-calendar \
  --with-mysql=mysqlnd \
  --with-mysqli=mysqlnd \
  --with-pdo-mysql=mysqlnd \
  --with-mysql-sock=/var/lib/mysql/mysql.sock \
  --with-libxml-dir=/usr \
  --without-mysql \
  --with-gd=/usr


Finally, compile and install!

gmake
gmake install


Lastly, you’ll likely want to use it in Apache… Here is how I set up my domain to use PHP 5.3:

<VirtualHost 74.208.46.111:80>
  ServerName php53.mainelan.com:80
  ServerAlias www.php53.mainelan.com
  UseCanonicalName On
  ServerAdmin "webmaster@mainelan.net"
  DocumentRoot /var/www/vhosts/php53.mainelan.com/httpdocs

  # PHP 5.3
  ScriptAlias /php53-cgi /usr/local/php53/bin/php-cgi
  Action application/x-http-php53 /php53-cgi
  AddHandler application/x-http-php53 .php

  . . .

Josh Guides, Web Development ,

Installing PHP 6 on CentOS 5

June 15th, 2009

I started playing in PHP 5.3 with Zend’s Early Access 7.0 Studio and Server CE and wanted to put it on my web server. Problem: It isn’t released yet and the library name is “php5″, same as PHP 5.2. I didn’t want to replace my production-ready PHP installation with a release candidate. I’m sure that would make my clients happy about unknown security holes, yadda yadda. The only solution is to install PHP 6 and enable it by virtual domain or directory. Please note that it is entirely possible to install PHP 5.3 along side PHP 5.2.9 using the first as CGI, but I want to avoid the confusion.

My CentOS 5 64-bit server is a VPS from 1&1.

Final notes before we get started. I did a “yum update” to bring my system to the latest everything. And no, installing libxml2 or icu via yum won’t help you. You can skip the gmake test, it is 7180 individual tests that can take a LOT of time on slower servers. CentOS is based on RedHat, so this will likely work with it as well.


# install the stuff you need to compile

yum install gcc gcc-c++.x86_64
yum install mysql-devel.x86_64 libpng-devel.x86_64 libjpeg-devel.x86_64

# compile and install icu where php6 can find it

mkdir /usr/local/icu
wget ftp://ftp.software.ibm.com/software/globalization/icu/3.6/icu4c-3_6-src.tgz
tar xkmfz icu4c-3_6-src.tgz
cd icu/source
./configure --prefix=/usr/local/icu
gmake
gmake install
cd ../..

# compile and install icu where php6 can find it

mkdir /usr/local/libxml2
wget ftp://xmlsoft.org/libxml2/libxml2-2.7.3.tar.gz
tar xkmfz libxml2-2.7.3.tar.gz
cd libxml2-2.7.3
autoreconf
./configure --prefix=/usr/local/libxml2
gmake
gmake install
cd ..

# compile php6 from http://snaps.php.net
# with libxml2, GD (jpeg + png) and MySQL

# make the config path
mkdir /etc/php6
mkdir /etc/php6.d

# download and extract the latest path, get it from snaps.php.net
wget http://snaps.php.net/php6.0-############
tar xkmfz php6.0-############
cd ~/php6.0-############

# refresh the conf
autoconf

# paste in this entire block and press enter:
./configure \
--prefix=/usr/local/php6 \
--with-config-file-path=/etc/php6 \
--with-config-file-scan-dir=/etc/php6.d \
--with-icu-dir=/usr/local/icu \
--with-libxml-dir=/usr/local/libxml2 \
--with-gd \
--with-jpeg-dir=/usr/lib64 \
--with-png-dir=/usr/lib64 \
--with-zlib-dir=/usr/lib64 \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock=/var/lib/mysql/mysql.sock

# alt for mysqli: --with-mysqli=/usr/bin/mysql_config

# compile and install. you can skip test if you want.
gmake
gmake test
gmake install

# prepare configuration
cp php.ini-* /etc/php6

# and ONE of the following to set up your php.ini

# if you plan to host pages to the outside world
cp php.ini-production /etc/php6/php.ini

# if you plan to use this installation as a test site for development
cp php.ini-development /etc/php6 php.ini

# if you have issues with mysql:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

Oh yeah, and running along side PHP 5? Toss something like this in a new file: /etc/httpd/conf.d/php6.conf


ScriptAlias /php6-cgi /usr/local/php6/bin/php-cgi
Action application/x-http-php6 /php6-cgi
AddHandler application/x-http-php6 .php6

Now anything .php6 will run php6 as cgi. If you have problems with CGI or MySQL, try nixing SuExec first. If you want to use it, you’ll need to be recompile it with a special folder permission for PHP 6.

Josh Guides, Web Development , , , ,