Databases
Compile Apache 2 with PHP 4 and MySQL 5 (while MySQL 4 is also installed)
by Greg on Apr.02, 2006, under Databases, Linux
Download and unpack Apache and PHP. MySQL 5 is install already. (as per another blog: http://www.1stbyte.com/2006/04/02/mysql-5-upgrade-compiled/
Make sure you have the proper dev packages. In my case I had to install ‘libflex’ and ‘libgdbm-dev’ using apt-get install to install PHP. (I have Debian Unstable)
./configure –prefix=/var/httpd –enable-so –enable-proxy –enable-proxy-ftp –enable-proxy-http –enable-ssl –enable-headers –enable-rewrite –enable-cgi –enable-deflate –enable-mime-magic –enable-dav –enable-dav-fs –enable-userdir –enable-status –enable-info
make && make install
then I copied the original Apache conf from /etc/apache2 to the new root, /var/httpd/conf. I also had to update the httpd.conf file to set the correct server root and other misc server directives, but mostly they were all the same.
Test your install /var/httpd/bin/apachectl start
Goto http://localhost and make sure you get the web site.
Now install PHP.
./configure –with-apxs2=/var/httpd/bin/apxs –with-mysql=/var/mysql5010 –with-mysql-sock=/tmp/mysql5.sock –prefix=/var/httpd/php –with-config-file-path=/var/httpd/php –enable-force-cgi-redirect –disable-cgi –with-zlib –with-gettext –with-gdbm
make
cp -p .libs/libphp4.so /var/httpd/modules
cp -p php.ini-recommended /var/httpd/php/php.ini
I then put these into httpd.conf
<IfModule mod_php4.c>
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
</IfModule>
LoadModule php4_module modules/libphp4.so
then ran:
make install
Edit: 10/25/05
Additional new notes:
When configure is run, I do it this way now:
./configure –prefix=/var/httpd –enable-so –enable-proxy –enable-proxy-ftp –enable-proxy-http –enable-ssl –enable-headers –enable-rewrite –enable-cgi –enable-deflate –enable-mime-magic –enable-dav –enable-dav-fs –enable-userdir –enable-status –enable-info –enable-cache –enable-disk-cache –enable-mem-cache
And…
For setup with Zope I am running ProxyPass instead of Rewrites:
ProxyRequests On ProxyPass / http://127.0.0.1:18080/VirtualHostBase/http/www.adomain.com:80/clients/adomain_com/VirtualHostRoot/ ProxyPassReverse / http://127.0.0.1:18080/VirtualHostBase/http/www.adomain.com:80/clients/adomain_com/VirtualHostRoot/ ProxyRequests On ProxyPass / http://127.0.0.1:18080/VirtualHostBase/http/domain.1stbyte.org:80/clients/domain_com/VirtualHostRoot/ ProxyPassReverse / http://127.0.0.1:18080/VirtualHostBase/http/domain.1stbyte.org:80/clients/domain_com/VirtualHostRoot/
When you add the PHP config, you need to first add flex.
apt-get install flex
Also, the httpd.conf additons are partially done in the mods-enabled folder for php.conf.
Mysql 5 upgrade – compiled
by Greg on Apr.02, 2006, under Databases, Linux
I just upgraded my MySQL server from 5.0.7 to 5.0.10. I wanted to make a few notes about what I did to set it up.
1. I compiled MySQL 5.0.10-beta.
./configure --prefix=/var/mysql5010 --with-unix-socket-path=/tmp/mysql5.sock --with-mysqld-ldflags=-all-static --enable-assembler --with-low-memory --with-named-curses-libs=/lib/libncurses.so.5 --with-mysqld-user=mysql
2. Did a make && make install
3. Stop mysql507 (on my server I created a script to stop and start mysql and mysql5, this way I can easily run both servers at the same time) stopmysql5
4. mkdir /var/mysql5010/var
5. cp -Rv /var/mysql507/var/* /var/mysql5010/var
6. Chmod -Rv mysql.mysql /var/mysql5010
7. Updated the startmysql5 script to point to the new path (var/mysql5010), same with stopmysql5 script.
8. startmysql5
And I was running! Now, this might not work on future versions, particularly since MySQL 5.x is in beta right now.
I did not recompile MySQLdb yet, as it is working fine for me, however it might be wise. In fact, I really should do that because the libraries are pointing to the /var/mysql507 directory.
Edit: 10/25/05
The config options here are for a smaller/slower server. Use this for normal servers with decent amount of RAM:
./configure --prefix=/var/mysql --with-unix-socket-path=/tmp/mysql.sock --with-mysqld-ldflags=-all-static --enable-assembler --with-named-curses-libs=/lib/libncurses.so.5 --with-mysqld-user=mysql --enable-thread-safe-client
This also enables the Thread Safe client, which will work better with mysql-python modules.
Retrieve or return an output parameter from a Mysql stored procedure in Zope
by Greg on Apr.02, 2006, under Databases, Programming, Zope
Zope 2.7.6 – Mysql 5.0.7. I have always thought that output parameters from stored procedures were not useable in Zope’s ZSQL methods, but a few minutes ago is suddenly occured to me that I could do it by using the “sql_delimiter” function in Zope. To be quick, put something like this in a ZSQL method:
call sp_test(@y)
dtml-var sql_delimiter
select @y as thecount
(put the <> around dtml-var sql_delimiter)
This works perfectly! I simply return a count in a simple sproc, but it’s exciting because this makes it even more useable! I LOVE ZOPE! (and now the MySQL has stored procedures, I LOVE MYSQL!)
Sample code if you want it:
— Here is the stored procedure —-
— This simply returns the parameter vout
— as a count.
DELIMITER $$
DROP PROCEDURE IF EXISTS `fb`.`sp_test`$$
CREATE PROCEDURE `fb`.`sp_test` (
out vout int
)
BEGIN
select count(*) into vout from blogs;
END$$
DELIMITER ;
— Here is the ZSQL Method —
call sp_test(@y)
dtml-var sql_delimiter
select @y as thecount
(put the <> around dtml-var)
Now you should note… for some reason, in MySQL Query Browser you can’t issue the commands:
call sp_test(@y);
select @y as thecount;
It wont work. But you can do that at he command line client just fine.
Also, you cannot do this AND return a recordset in the same procedure. It works from the command line client, but not in the ZSQL method. So, you will be limited to only return parameters this way.
Get ZMySQLDA to retrieve MySQL Stored Procedures
by Greg on Jul.06, 2005, under Databases, Programming, Zope
Quick, before I forget!!
Tired of “can’t return a result set in the given context” errors when calling stored procedures in Mysql 5?
The ultra fast how-to on returning records from a multi-column multi-record stored procedure in Mysql 5 using Zope/Python!
In the ZMySQLDA, edit the db.py file and add the lines below in the _parse_connection_string function:
#added by Greg Fischer retheoff at gmaildot com on 07/05/2005
# Wanted an option to use 'client_flag' in connection string
# to utilize MULTI_RESULTS and thereby retrieving full
# recordsets from Mysql 5.x
# There is most likely a better way to implement this,
# but this solved my isssue for now. (what if you have
# more than 1 client_flag?)
if not items: return kwargs
kwargs['client_flag'], items = int(items[0]), items[1:]
# End addition
Like so…
def _parse_connection_string(self, connection): kwargs = {'conv': self.conv} items = split(connection) self._use_TM = None if not items: return kwargs lockreq, items = items[0], items[1:] if lockreq[0] == "*": self._mysql_lock = lockreq[1:] db_host, items = items[0], items[1:] self._use_TM = 1 else: self._mysql_lock = None db_host = lockreq if '@' in db_host: db, host = split(db_host,'@',1) kwargs['db'] = db if ':' in host: host, port = split(host,':',1) kwargs['port'] = int(port) kwargs['host'] = host else: kwargs['db'] = db_host if kwargs['db'] and kwargs['db'][0] in ('+', '-'): self._try_transactions = kwargs['db'][0] kwargs['db'] = kwargs['db'][1:] else: self._try_transactions = None if not kwargs['db']: del kwargs['db'] if not items: return kwargs kwargs['user'], items = items[0], items[1:] if not items: return kwargs kwargs['passwd'], items = items[0], items[1:] #added by Greg Fischer retheoff at gmaildot com on 07/05/2005 # Wanted an option to use 'client_flag' in connection string # to utilize MULTI_RESULTS and thereby retrieving full # recordsets from Mysql 5.x # There is most likely a better way to implement this, # but this solved my isssue for now. (what if you have # more than 1 client_flag?) if not items: return kwargs kwargs['client_flag'], items = int(items[0]), items[1:] # End addition if not items: return kwargs kwargs['unix_socket'], items = items[0], items[1:] return kwargs
Now, when you create your database connection object in Zope to Mysql 5, you use a slightly different connection string:
db user passwd client_flag
The client_flag is 131072 as specified in the CLIENT.py of MySQLdb for Python. (it didnt work for me to just use the constant MULTI_RESULTS.)
It will look like this:
adatabase auser apassword 131072
On Linux, this worked great. I cant get it to work on Windows. Probably need a newer version of _mysql.c from the mysql-python developers. (just a guess)
In Python, if you just want to connect, use the client_flag option in your connection string: (watch the wrapped lines)
cn = MySQLdb.Connection(db=adb, host=ahost,
user=auser, passwd=apw, client_flag=131072)
Worked great, again on Linux! But on Windows, I still get the “can’t return a result set in the given context” error unfortunately. If I find out how to get around that, I’ll post more.
This is a QUICK FIX! It is in know way the proper solution and will most likely cause some other problems, but it works and I needed the sprocs on Mysql! So, use at your own risk. And good luck!
Edit 7/06/05 2PM:
This *was* working. I ran in to a problem after creating a more complicated procedure using multiple statements. I then received an error in Zope stating something about releasing a lock. ?? I duno. I’ll test it in Python directly and see if it’s just my corny DA fix.
Edit 7/06/05 5PM:
Ok, it works, but I need to do more testing. You NEED TO USE A DASH in the connection string. Like so:
-adatabase auser apassword 65536
Also notice I am using 65536 as the client_flag. Using this specifies MULTI_STATEMENTS, and implies MULTI_RESULTS.