title: multiple php on apache centos
body: <p>How can I get multiple php versions running on Centos 6.5 at the same time ?</p>
  
  <p>Here's how.</p>
  
  <p><b>Requirements</b><br>
  Centos 6.5 (Possible works with 6.6 and 7) <br/>
  Apache   Apache/2.2.15 (Possible works with other versions)   <br/> </p>
  
  <p><b>This guide installs and uses</b><br> 
  FASTCGI (see the comments for alternative installation)<br>
  PHPFARM<br><br>
  This install was done this way so it would be compatable with iredmail.<br>
  You can install iredmail on a server with this set up.<br></p>
  
  <p><b>Step 1</b><br>
  Installing PHPFarm</p>
  
  <pre><code>yum install gcc libxml2-devel openssl-devel bzip2-devel curl-devel libjpeg-devel     freetype-devel icu libicu-devel gcc-c++ postgresql-devel aspell-devel git -y
  
  $ cd /opt/
  $ git clone https://github.com/cweiske/phpfarm.git phpfarm
  $ cd phpfarm/src/
  $ cd /opt/phpfarm/src/
  </code></pre>
  
  <p>For each version of php you want run this. However, If you want custom modules such as mysql support skip this and see the part just below it.</p>
  
  <pre><code>$ ./compile.sh 5.3.1
  $ ./compile.sh 5.3.3
  $ ./compile.sh 5.5.11
  </code></pre>
  
  <p>If you get compile errors, reboot and try./compile.sh 5.3.1 again
  This worked for me when I ran into this problem<br>
  <br>
  <b>MYSQL &amp; Module Support</b><br>
  Steps for getting MySQL support (and other modules) for custom phpfarm install of php version  5.5.14. These instructions work for any version just rename 5.5.14 to what ever like 5.4.3. You will of course need a mysql server to connect to to make use of the mysql module within php.
  <br>
  These steps need to be completed in this order
  <br>
  <b>Step  1A</b><br>
  Ensure you have these paths and the date time is correct I did this as root. You should have the date.timezone you intend to use.</p>
  
  <pre><code>cd /opt/phpfarm/src
  vi custom-php.ini
  
  date.timezone=America/Halifax
  include_path=".:/opt/phpfarm/inst/php-$version/pear/php/"
  </code></pre>
  
  <p><b>Step  1B</b><br>
  Ensure you have these paths and the date time is correct</p>
  
  <pre><code>cd /opt/phpfarm/src
  vi default-custom-php.ini
  
  date.timezone=America/Halifax
  include_path=".:/opt/phpfarm/inst/php-$version/pear/php/"
  </code></pre>
  
  <p><b>Step 1C</b><br> 
  Pay Special Attention to this line</p>
  
  <pre><code>--with-config-file-path=/opt/phpfarm/inst/php-5.5.11/lib/ \
  </code></pre>
  
  <p>it will need to be adjusted for the version you are working with. As root </p>
  
  <pre><code>vi custom-options-5.5.14.sh
  
  #!/bin/bash
  
  #gcov='--enable-gcov'
  configoptions="
  --disable-debug \
  --with-config-file-path=/opt/phpfarm/inst/php-5.5.11/lib/ \
  --enable-short-tags \
  --with-pear \
  --enable-bcmath \
  --enable-calendar \
  --enable-exif \
  --enable-ftp \
  --enable-mbstring \
  --enable-pcntl \
  --enable-soap \
  --enable-sockets \
  --enable-wddx \
  --enable-zip \
  --with-zlib \
  --with-gettext \
  --enable-pdo \
  --with-pdo-mysql \
  --enable-cgi \
  --enable-json \
  --with-curl \
  --with-openssl \
  --enable-openssl \
  --with-mysql \
  --enable-mysql \
  $gcov"
  </code></pre>
  
  <p><b>Step 1D</b><br> 
  Now compile as root. Phpfarm will automatically look for a file named custom-options-5.5.14.sh when you compile 5.5.14, or any other version with of course respective version numbers.</p>
  
  <pre><code>./compile.sh 5.5.14
  </code></pre>
  
  <p>Later when you check out your web page with the phpinfo(); function, you will see support for these modules and different "Configure Command" text on the page.  </p>
  
  <hr>
  
  <p>If these steps are not completed in order you may have to do it again. 
  In order to do this again first remove the files from the src folder and the inst folder.</p>
  
  <pre><code>rm -rf /opt/phpfarm/inst/php-5.5.14
  
  rm -rf /opt/phpfarm/src/php-5.5.14
  </code></pre>
  
  <p>The rm will remove the folder and the -rf stands for r recursive and f force.
  Ref: <a href="http://linuxcommand.org/lc3_man_pages/rm1.html" rel="nofollow noreferrer">http://linuxcommand.org/lc3_man_pages/rm1.html</a></p>
  
  <hr>
  
  <p>If you have errors check with this site. There are others but I found this one useful.</p>
  
  <p><a href="http://crybit.com/20-common-php-compilation-errors-and-fix-unix/" rel="nofollow noreferrer">http://crybit.com/20-common-php-compilation-errors-and-fix-unix/</a></p>
  
  <hr>
  
  <p>Reference for the mysql and module support</p>
  
  <p><a href="https://stackoverflow.com/questions/26028229/issue-activating-a-php-extension-using-php-farm">Issue activating a php extension using PHP Farm</a></p>
  
  <hr>
  
  <p><b>Step 2</b><br>
  Adding phpfarm to your profiles</p>
  
  <p>add this to the bottom of .bashrc for root and non-root user. The .bashrc file can be found in the users root folder or cd ~/  then ls -all and you should see it.</p>
  
  <pre><code>PATH="$PATH:/opt/phpfarm/inst/bin:/opt/phpfarm/inst/current-bin"
  </code></pre>
  
  <p>also execute this in terminal after you have added it to the .bashrc files for root and non-root user</p>
  
  <pre><code>export PATH="$PATH:/opt/phpfarm/inst/bin:/opt/phpfarm/inst/current-bin"
  </code></pre>
  
  <p>now exit the terminal and log back in. try this command</p>
  
  <pre><code>switch-phpfarm 5.5.11
  </code></pre>
  
  <p>you should be able to switch back and forth between diff php versions </p>
  
  <pre><code>[root@test joe]# switch-phpfarm 5.5.11
  Setting active PHP version to 5.5.11
  PHP 5.5.11 (cli) (built: May 17 2014 22:01:31) (DEBUG)
  Copyright (c) 1997-2014 The PHP Group
  Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
  [root@test joe]#
  </code></pre>
  
  <p>add the repo for CentOS/RHEL 6, 64 Bit (x86_64):</p>
  
  <pre><code>cd /tmp
  rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
  </code></pre>
  
  <p><b>Step 3</b><br>
  install the yums</p>
  
  <pre><code>yum install php php-cli mod_fastcgi
  </code></pre>
  
  <p><b>NOTE</b>
  at this point if you try to run the switch-phpfarm 5.5.11 it wont work properly but thats ok. we will still be able to run multiple websites with different versions of php</p>
  
  <p><b>Step 4</b><br>
  Ensure your cgi-bin is created and files are configured<br></p>
  
  <pre><code>$ cd  /var/www
  </code></pre>
  
  <p>If the cgi-bin isn’t already here create it</p>
  
  <pre><code>$ mkdir cgi-bin
  </code></pre>
  
  <p>For each version of php you intend to use make one of these files. Replace the ending with the version number </p>
  
  <pre><code>vi /var/www/cgi-bin/php.fastcgi.5.5.11
  </code></pre>
  
  <p><b>step 5</b><br>
  Inside the file  php.fastcgi.5.5.11</p>
  
  <pre><code>#!/bin/bash
  PHPRC="/opt/phpfarm/src/php-5.5.11/php.ini-development"
  PHP_FCGI_CHILDREN=4
  PHP_FCGI_MAX_REQUESTS=1000
  export PHPRC
  export PHP_FCGI_CHILDREN
  export PHP_FCGI_MAX_REQUESTS
  exec /opt/phpfarm/inst/bin/php-cgi-5.5.11
  </code></pre>
  
  <p>The first line </p>
  
  <pre><code>PHPRC="/opt/phpfarm/src/php-5.5.11/php.ini-development"
  </code></pre>
  
  <p>Tells you witch php.ini to use this is different in ubuntu. The last line</p>
  
  <pre><code>exec /opt/phpfarm/inst/bin/php-cgi-5.5.11
  </code></pre>
  
  <p>also needs to be changed for each particular version. I am not sure what it does but I do know it needs to be changed.</p>
  
  <p><b>Step 6</b><br>
  Enable fastcgi files to be executable for apache:apache user and group<br></p>
  
  <p>Example 1</p>
  
  <pre><code>[root@test joe]# chown apache:apache /var/www/cgi-bin/php.fastcgi.5.5.11
  [root@test joe]# chmod +x /var/www/cgi-bin/php.fastcgi.5.5.11
  </code></pre>
  
  <p>Example 2</p>
  
  <pre><code>[root@test joe]# chown apache:apache /var/www/cgi-bin/php.fastcgi.5.3.3
  [root@test joe]# chmod +x /var/www/cgi-bin/php.fastcgi.5.3.3
  </code></pre>
  
  <p>Example 3</p>
  
  <pre><code>[root@test joe]# chown apache:apache /var/www/cgi-bin/php.fastcgi.5.3.1
  [root@test joe]# chmod +x /var/www/cgi-bin/php.fastcgi.5.3.1
  </code></pre>
  
  <p><b>Step 7</b><br>
  Editing the httpd.conf file<br>
  Here’s what you need for the /etc/httpd/conf/httpd.conf file.
  First find “NameVirtualHost *:80”  and use this as a starting point.The “#” means the line is commented out. Uncomment this line by deleting the #. it Should now look like this. </p>
  
  <pre><code>NameVirtualHost *:80
  </code></pre>
  
  <p>This will allow multiple virtual host to operate on Apache by their "ServerName" in each virtual host reference. I left some lines commented to show you what you can do without. Make sure the bottom of the /etc/httpd/conf/httpd.conf looks like this.</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName test1.com
     #ServerAdmin admin@tecadmin.net
      DocumentRoot /var/www/html/test1
      ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
      &lt;Directory "/var/www/html/test1"&gt;
              Options +Indexes FollowSymLinks +ExecCGI
              AddHandler php5-fastcgi .php
              Action php5-fastcgi /cgi-bin/php.fastcgi.5.5.11
              AllowOverride All
              Order allow,deny
              Allow from All
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  &lt;VirtualHost *:80&gt;
      ServerName test2.com
  #   ServerAdmin admin@tecadmin.net
      DocumentRoot /var/www/html/test2
      ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
      &lt;Directory "/var/www/html/test2"&gt;
              Options +Indexes FollowSymLinks +ExecCGI
              AddHandler php5-fastcgi .php
              Action php5-fastcgi /cgi-bin/php.fastcgi.5.3.3
              AllowOverride All
              Order allow,deny
              Allow from All
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  &lt;VirtualHost *:80&gt;
      ServerName test3.org
  #   ServerAdmin admin@tecadmin.net
      DocumentRoot /var/www/html/test3
      ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
      &lt;Directory "/var/www/html/test3"&gt;
              Options +Indexes FollowSymLinks +ExecCGI
              AddHandler php5-fastcgi .php
              Action php5-fastcgi /cgi-bin/php.fastcgi.5.3.1
              AllowOverride All
              Order allow,deny
              Allow from All
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  &lt;VirtualHost *:80&gt;
      ServerName test4.net
  #   ServerAdmin admin@tecadmin.net
      DocumentRoot /var/www/html/test6
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p><b>Step 8</b><br>
  Editing the etc/hosts file <br>
  here is what u need in the etc/hosts file.</p>
  
  <pre><code>127.0.0.1   localhost test1.com test2.com test3.org test4.net
  ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  </code></pre>
  
  <p><b>Step 9</b><br></p>
  
  <p>Now restart your server</p>
  
  <pre><code>service httpd restart
  </code></pre>
  
  <p><b>Step 10</b><br>
  Testing<br>
  if you add phpinfo() to each of the index.php sites you will notice that all the php versions will be different. also the last one test4.net will go with the default for centos. Also note that test3.org and test4.net are not .com's but will still work. In the future I plan to make a guide for the phpfarm files so you can install with mysql support. This was another issue I ran into. If you notice some errors in this or have difficult making it work, please comment and I will get to it as soon as I can.</p>