<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ammon Shepherd - Historical Webber &#187; mysql</title>
	<atom:link href="http://mossiso.com/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://mossiso.com</link>
	<description>History, it happens every yesterday</description>
	<lastBuildDate>Fri, 04 Nov 2011 16:43:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Multiple PHP Instances With One Apache</title>
		<link>http://mossiso.com/2009/09/02/multiple-php-instances-with-one-apache.html</link>
		<comments>http://mossiso.com/2009/09/02/multiple-php-instances-with-one-apache.html#comments</comments>
		<pubDate>Wed, 02 Sep 2009 21:12:02 +0000</pubDate>
		<dc:creator>ammon</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[bash code]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://historicalwebber.mossiso.com/?p=311</guid>
		<description><![CDATA[<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;rfr_id=info%3Asid%2Focoins.info%3Agenerator&amp;rft.type=&amp;rft.format=text&amp;rft.title=Multiple PHP Instances With One Apache&amp;rft.source=Ammon Shepherd - Historical Webber&amp;rft.date=2009-09-02&amp;rft.identifier=http://mossiso.com/2009/09/02/multiple-php-instances-with-one-apache.html&amp;rft.language=English&amp;rft.aulast=Shepherd&amp;rft.aufirst=Ammon&amp;rft.subject=Coding"></span>
&#160; Long-winded Introduction It took me a couple of days to figure this out due to lack of decent tutorials and not enough confidence in my Linux skills to build...]]></description>
			<content:encoded><![CDATA[<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;rfr_id=info%3Asid%2Focoins.info%3Agenerator&amp;rft.type=&amp;rft.format=text&amp;rft.title=Multiple PHP Instances With One Apache&amp;rft.source=Ammon Shepherd - Historical Webber&amp;rft.date=2009-09-02&amp;rft.identifier=http://mossiso.com/2009/09/02/multiple-php-instances-with-one-apache.html&amp;rft.language=English&amp;rft.aulast=Shepherd&amp;rft.aufirst=Ammon&amp;rft.subject=Coding"></span>
<p>&nbsp;</p>
<h3>Long-winded Introduction</h3>
<p>It took me a couple of days to figure this out due to lack of decent tutorials and not enough confidence in my Linux skills to build programs from source. I think I have the hang of it now, and write this up with the intent on providing another, or the only, tutorial on setting up CentOS 5 with multiple instances of PHP using one Apache install. That being said, there are a number of good tutorials out there, just none of them explicitly for CentOS and some leave out some details that n00bs like me get confused about.</p>
<p><a href="http://www.aditus.nu/jpgraph/apache2suse10.php">PHP4 and PHP5 on SuSE 10.1</a> &#8211; This was by far the most helpful of the tutorials. Even though it was written for SuSE, it works almost straight across for CentOS.</p>
<p>There is also a great list of instructions in the comments on the php.net site under installing PHP for Apache 2.0 on Unix systems (see <a href="http://www.php.net/manual/en/install.unix.apache2.php#90478">http://www.php.net/manual/en/install.unix.apache2.php#90478</a>).</p>
<p>I found this one after I wrote up this tutorial at <a href="http://cuadradevelopment.com/blog/26/multiple-php-versions-with-apache-using-fastcgi-on-os-x/">http://cuadradevelopment.com</a>. It&#8217;s a bit different, but should work as well.</p>
<p>There are basically two different ways I could have done this. 1- run a single instance of Apache, and run one instance of PHP as a module, and other installs as CGI. 2- run several instances of Apache, each with it&#8217;s own instance of PHP as a module. I chose to do the first method for no particular reason. <a href="http://blog.dreamhosters.com/kbase/index.cgi?area=2933">Dreamhost</a> has a post about the good and bad with running PHP as CGI.</p>
<p>So basically, the steps are: 1. Set up Apache and have PHP install as a module. 2. Configure and make another instance of PHP to run as CGI. 3. Add a virtual host to Apache running under a different port to access the PHP as CGI.<br />
<span id="more-311"></span></p>
<h3>Set up Apache with PHP module</h3>
<p>So here&#8217;s what I did to get the basic Apache, PHP and MySQL working. This sets up the first PHP install to run as a module in Apache:</p>
<p>From a clean install of CentOS 5 (virtually no packages selected during initial install), I installed the following packages:</p>
<p><code>$ yum install gcc make subversion ImageMagick php php-cli php-common php-ldap php-mysql php-pdo php-pear php-devel bzip2-devel libxml2-devel mysql mysql-server mysql-devel mod_auth_mysql httpd httpd-manual</code></p>
<p>From there I needed to get PHP 5.2.x, so I did the following to get PHP, Apache, MySQL and PEAR all set up.</p>
<ol>
<li><strong>Step 1:</strong> GET PHP 5.2.x<br />
Check out instructions and packages here: <a href="http://blog.famillecollet.com/pages/Config-en">http://blog.famillecollet.com/pages/Config-en</a></p>
<pre>$ wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-2.noarch.rpm
$ wget http://rpms.famillecollet.com/el5.i386/remi-release-5-4.el5.remi.noarch.rpm
$ rpm -Uvh remi-release-5<strong>.rpm epel-release-5</strong>.rpm
$ yum—enablerepo=remi update php-pear php</pre>
<p>Copy the /etc/php.ini file from the /etc/php.ini.default:</p>
<pre>$ cp /etc/php.ini.default /etc/php.ini</pre>
<p>Change the following lines:</p>
<ul>
<li>1. upload_max_filesize = 20M #line 573</li>
<li>2. mysql.default_socket =/path/to/mysql/mysql.sock #about line 736</li>
<li>3. mysqli.default_socket =/path/to/mysql/mysql.sock #about line 771</li>
</ul>
</li>
<li><strong>Step 2:</strong>Edit /etc/httpd/conf/httpd.conf by changing the following lines
<ul>
<li>1. Listen xxx.xxx.xxx.xxx:80 #line 134</li>
<li>2. ServerAdmin admin@email.org #line 251</li>
<li>3. ServerName somesite.org #line 265</li>
<li>4. DocumentRoot ”/path/to/htdocs” #line 282</li>
<li>5. &lt;Directory ”/path/to/htdocs”&gt; #line 307</li>
<li>6. AllowOverride All #line 328</li>
<li>7. DirectoryIndex index.php index.html index.html.var #line 392</li>
</ul>
</li>
<li><strong>Step 3:</strong> Create the /etc/my.cnf file for MySQL
<pre>
&lt;pre&gt;[mysqld]
datadir=/path/to/mysql
socket=/path/to/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

[client]
socket=/path/to/mysql/mysql.sock

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid&lt;/pre&gt;
</pre>
</li>
<li><strong>Step 4:</strong> Start apache and mysql and set them to start on boot up:<br />
<blockquote>
<pre>$ service httpd start
$ service mysqld start
$ chkconfig mysqld on
$ chkconfig httpd on</pre>
</blockquote>
</li>
<li><strong>Step 5:</strong> Set the MySQL password for root<br />
<blockquote>
<pre>$ mysqladmin -u root password ‘XXXXXX’</pre>
</blockquote>
</li>
<li><strong>Step 6:</strong> install Phing and other PEAR packages<br />
<blockquote>
<pre>$ pear channel-discover pear.phing.info
$ pear channel-discover pear.phpunit.de
$ pear install phing/phing
$ pear install PhpDocumentor
$ pear install XML_Beautifier
$ pear install PHPUnit
$ pecl install Xdebug</pre>
</blockquote>
</li>
</ol>
<h3>Configure second version of PHP</h3>
<p>From here we need to install a second version of PHP. Grab the version you want from <a href="http://www.php.net/releases/">http://www.php.net/releases/</a>, and stick that any where you want to (usually your root&#8217;s home directory is fine). I&#8217;m installing PHP 5.2.4, so I&#8217;ll use that in my examples.</p>
<p>Unpack the tarball and enter the directory it created.</p>
<pre>$ tar -xjf php-5.2.4.tar.bz2</pre>
<p>Now, you&#8217;ll need to determine which modules you need to install. For this part I used the steps from the php.net comment under &#8220;my approach for determining required modules&#8221; (copied here, without permission, but with lots of gratitude and full credit going to the author of the comment).</p>
<pre>my approach for determining required modules
------------------------------------
1. get the list of the modules
     $  php -m | grep -v -e Modules] -e ^$ &gt; php-default-modules

2. create the configure script
$  for i in $(cat php-default-modules); do echo -n "--with-$i "&gt;&gt; phpconfigure.sh ;done

     2.2 add #!/bin/bash to the top line, and ./configure to the second line.
          Each of the --with-* need to be on the second line.

3. run the configure script, and iterate through the "Configure script errors"
    section below until it completes properly

    $ ./phpconfigure.sh

4. at the end of the output, look for a notice of unknown options

     Notice: Following unknown configure options were used:
     --with-date
     --with-gum-disease

     Check './configure --help' for available options

5. as suggested, execute '$ ./configure --help' and correct the options. The
     "for" command above indiscriminately inserts "--with-" for all modules,
     but bundled modules may require "--enable-" instead, so mostly you'll
     be changing those. For modules that are enabled by default you'll need
     to remove the entry.

6. Add anything else you personally want or need. I like to add "--enable-safe-mode".</pre>
<p>After doing all of that, I had the following in phpconfigure.sh</p>
<pre>
#!/bin/bash
./configure --prefix=/usr/share/ --datadir=/usr/share/php --libdir=/usr/share --includedir=/usr/include --bindir=/usr/bin --enable-safe-mode --with-config-file-path=/etc/php542 --enable-force-cgi-redirect --enable-discard-path --with-bz2 --enable-calendar --with-curl --enable-dbase --enable-exif --enable-ftp --with-gettext --with-gmp --with-iconv --with-ldap --with-libxml-dir=/usr/lib/ --enable-mbstring --with-mime_magic --with-mysql --with-mysqli --with-openssl --enable-pcntl --with-pcre-dir=/usr/lib/ --with-pdo_mysql --with-pdo_sqlite --with-readline --enable-shmop --enable-sockets --with-SQLite --enable-wddx --with-xsl --enable-zip --with-zlib

# Changes from what php -m spits out. You don't need the info below in your phpconfigure.sh script
#--enable-calendar
#--with-ctype # default
#--with-date # not found, default?
#--enable-dbase
#--with-dom # default
#--enable-exif
#--with-filter #default
#--with-ftp
#--with-hash #default
#--with-json #default
#--with-libxml-dir=/usr/lib/
#--enable-mbstring
#--with-memcache #not found, default?
#--enable-pcntl
#--with-pcre-dir=/usr/lib/
#--with-PDO #taken care of with the pdo_mysql and pdo_sqlite
#--with-Reflection #default
#--with-session #default
#--enable-shmop
#--with-SimpleXML #default
#--enable-sockets
#--with-SPL #default
#--with-standard #not found, is it SPL? default?
#--with-tokenizer #default
#--enable-wddx
#--with-xdebug #not found, not needed
#--with-xml #default
#--with-xmlreader #default
#--with-xmlwriter #default
#--enable-zip
#--with-Xdebug #not found, not needed
</pre>
<p><strong>NOTE:</strong> make sure you do not include &#8216;&#8211;with-apxs2=/usr/sbin/apxs&#8217;. This is what installs PHP as an Apache module. Also, since you have the original PHP running, you can theoretically make a phpinfo file (with phpinfo() ) in it, and grab the configure entries from that, making sure to change &#8216;&#8211;with-config-file-path=/etc&#8217; &#8216;&#8211;with-config-file-scan-dir=/etc/php.d&#8217;</p>
<p>During the configure, you might run into some errors. Again from the php.net comment:</p>
<pre>Configure script errors
--------------------------------------------
In my experience, these errors have been due (with any software, PHP included) mostly to missing
development packages, which contain the libraries and headers needed to compile support for that
library's function into the application.

This becomes a process of:
-executing the ./configure script and looking at the error
-installing the devel package providing the resource referenced by the error (google using the error
     as search term as needed)
-repeat until the ./configure script makes it through without error

Upshot: identify the software referenced by the error, and install it.

Example
-----------
Example error:
     configure: error: Cannot find OpenSSL's
Example explanation
     configure is looking for a header (and probably a lot of other stuff) from a missing openssl package.
Example solution:
php-5.2.9]$sudo yum install openssl-devel</pre>
<p>The previous yum command should take care of most of those dependencies.</p>
<p>After the phpconfigure script runs without errors, then simply run</p>
<pre>$ make</pre>
<p>As the JpGraph tutorial explains, there is no need to run &#8220;make install&#8221;. Just simply copy the php-cgi executable to the proper place. We&#8217;ll get to that step shortly.</p>
<h3>Set up Apache VirtualHost and website directories</h3>
<p>Now you need to create two directories to handle the PHP as CGI. They can be virtually wherever, but should be in the same directory where you have the main html content. So if you set the path to the website data (in the httpd.conf) to /path/to/htdocs/, then you&#8217;ll need to make a /path/to/php524/ and a /path/to/php524-cgi/</p>
<pre>$ mkdir /path/to/php524/</pre>
<p>and</p>
<pre>$ mkdir /path/to/php524-cgi/</pre>
<p>After you have those directories, you can add the VirtualHost information to the Apache config (httpd.conf). I like to have a separate file for the VirtualHosts, so I added this to the end of the httpd.conf file.</p>
<pre>Include conf/XXXXX_vhosts.conf</pre>
<p>And to allow VirtualHosts, uncomment this line:</p>
<pre>NameVirtualHost *:80</pre>
<p>To allow Apache to listen on (or accept requests from) different ports besides the default 80, add another Listen line to the httpd.conf file:</p>
<pre>Listen XXX.XXX.XXX.XXX:8524</pre>
<p>I used port 8524 to correspond to version 5.2.4 of PHP</p>
<p>Now create the XXXXX_vhosts.conf file</p>
<pre>
#this doesn't really seem to be needed, but it's there
NameVirtualHost *:8524

# this is the original and runs the PHP as a module

DocumentRoot /path/to/htdocs/
ServerName somesite.org

####### Add other Virtual Hosts below here #######

# Setup PHP 5.2.4 on port 8524

DocumentRoot /path/to/php524/

# We use a separate CGI directory
ScriptAlias /cgi-bin/ /etc/php524/

# For good measure we also add recognition of PHP5 index
DirectoryIndex index.php5

# These are the two critical statements for this virtual
# host. This activates PHP 5.2.4 as a CGI module
Action php524-cgi /cgi-bin/php-cgi
AddHandler php524-cgi .php5 .php
#Options None
Options FollowSymLinks
#AllowOverride None
AllowOverride All
Order allow,deny
Allow from all
DirectoryIndex index.html index.php
</pre>
<p>Now, you need to copy the php-cgi binary/executable to the /path/to/php524-cgi-bin/ directory. The php-cgi file is located in the file where you ran the configure and make for the new php install. So if you did all that in the /opt/php-5.2.4/ directory, the php-cgi will be located at /opt/php-5.2.4/sapi/cgi/php-cgi.</p>
<pre>$ cp /opt/php-5.2.4/sapi/cgi/php-cgi /path/to/php524-cgi-bin/</pre>
<p>Finally, copy the php.ini file to the right place. And configure as needed.</p>
<pre>$ cp /opt/php-5.2.4/php.ini-dist /path/to/php524-cgi-bin/php.ini</pre>
<p>Test the apache configs to make sure they work:</p>
<pre>$ /usr/sbin/apachectl configtest</pre>
<p>If that returns OK restart Apache.</p>
<pre>$ /etc/init.d/httpd graceful</pre>
<p>You can make a phpinfo page to test that it&#8217;s using the new PHP version.</p>
<pre>
&lt; ?php
phpinfo();
? &gt;
</pre>
<p>Then check out your new site: http://somesite.org:8524/phpinfo.php</p>
<p>In order to get the different versions of PHP to interact with MySQL, you&#8217;ll have to use the URL on port 80 as the MySQL host. So, for example, in a WordPress install at http://somesite.org:8524/blog, the wp-config.php will have to have the following for the MySQL hostname:</p>
<pre>define('DB_HOST', 'dev.omeka.org');</pre>
<p>There is some issue with mod_rewrite on the different versions of PHP. I&#8217;ll replace this paragraph with a fix when I have one.<br />
UPDATE: 9/9/09 &#8211; I figured out how to get the .htaccess working for the <a href="http://omeka.org">Omeka</a> installs we were working with. I needed to change the AllowOverride lines in the vhost.conf (or httpd.conf) file from None, to All.</p>
<p>Well, there you go. Hope that&#8217;s enough detail to get you going.</p>
]]></content:encoded>
			<wfw:commentRss>http://mossiso.com/2009/09/02/multiple-php-instances-with-one-apache.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tabledump</title>
		<link>http://mossiso.com/2007/09/05/tabledump.html</link>
		<comments>http://mossiso.com/2007/09/05/tabledump.html#comments</comments>
		<pubDate>Wed, 05 Sep 2007 21:55:52 +0000</pubDate>
		<dc:creator>ammon</dc:creator>
				<category><![CDATA[computer history]]></category>
		<category><![CDATA[bash code]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://historicalwebber.mossiso.com/archives/83</guid>
		<description><![CDATA[<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;rfr_id=info%3Asid%2Focoins.info%3Agenerator&amp;rft.type=&amp;rft.format=text&amp;rft.title=Tabledump&amp;rft.source=Ammon Shepherd - Historical Webber&amp;rft.date=2007-09-05&amp;rft.identifier=http://mossiso.com/2007/09/05/tabledump.html&amp;rft.language=English&amp;rft.aulast=Shepherd&amp;rft.aufirst=Ammon&amp;rft.subject=computer history"></span>
I had the need once again to dump only certain tables from a database, instead of all 100+ tables. This was where I had a database with about 5-8 wordpress...]]></description>
			<content:encoded><![CDATA[<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;rfr_id=info%3Asid%2Focoins.info%3Agenerator&amp;rft.type=&amp;rft.format=text&amp;rft.title=Tabledump&amp;rft.source=Ammon Shepherd - Historical Webber&amp;rft.date=2007-09-05&amp;rft.identifier=http://mossiso.com/2007/09/05/tabledump.html&amp;rft.language=English&amp;rft.aulast=Shepherd&amp;rft.aufirst=Ammon&amp;rft.subject=computer history"></span>
<p>I had the need once again to dump only certain tables from a database, instead of all 100+ tables. This was where I had a database with about 5-8 wordpress installs. I wanted to backup all of the tables for only one install. There is a way with mysqldump to do this, by listing out all of the tables you want to dump.  So I just wrote a bash script to take care of making the list of tables to dump.</p>
<p>It has an array of database table names (without the common prefix) in the script. Then it prompts for the mysql user, database, and prefix.  It could be changed to prompt for a file that contains a list or array of table names.</p>
<p>Anyhow, here it is for anyone&#8217;s use:</p>
<pre>
#!/bin/bash

#-----------------------------------------#
#           Ammon Shepherd                #
#              09.05.07                   #
#  Dump a database with only the tables   #
#   containing the prefix given.          #
#-----------------------------------------#

echo "This will dump just the tables with the specified prefix from the specified database."

echo -n "Enter the database name: "
read dbase

echo -n "Enter the table prefix: "
read prefix

echo -n "The mysql user: "
read sqluser
echo -n "The mysql pass: "
read -s sqlpass

# Get list of tables with the desired prefix
list=( $(mysql -u$sqluser -p$sqlpass $dbase --raw --silent --silent --execute="SHOW TABLES;") )

for tablename in ${list[@]}
do
    if [[ "$tablename" =~ $prefix ]]; then
        tablelist+="$tablename "
    fi
done

`mysqldump -u$sqluser -p$sqlpass --opt $dbase $tablelist > $dbase.$prefix.bak.sql`

echo

exit 0
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mossiso.com/2007/09/05/tabledump.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

