Apache Not Reloading Configuration File / Rewrites Not Updating July 15, 2009
Posted by scoopseven in Apache, Linux.add a comment
This week I experienced a problem where my apache rewrite rules wouldn’t update or reload. I would change a 301 redirect or an alias, restart Apache and the changes wouldn’t process. Humph. I got to the point where I started to believe, like DNS, that these redirects where propagated somewhere out on the Internet and they were just happening. Of course, this doesn’t happen.
Our Apache setup contains conf files for several sites, and our main httpd.conf file has a section that includes these conf files:
# Load config files from the config directory "/etc/httpd/conf.d".
Include conf.d/*.conf
What I had done was left a backup config file in the /etc/httpd/conf.d directory, so I had mysite.conf and mysite-20090710.conf being included when Apache loaded. Weather Apache tried to load both config files or my backup was simply overwriting my real config, I’m not sure, but as soon as I removed the backup config everything started working as normal. From now on, my backup Apache config files will be named mysite.bak!
Django / PythonPath July 8, 2009
Posted by scoopseven in Apache, Django.add a comment
The post below was taken directly from www.ventanazul.com. I republished only because this solved a problem that was a real PITA for me and wasn’t spelled out too clearly in the Django documentation. If you’re having a problem with Django / Apache / mod_python / PythonPath / sys.path / Could not import module things, give it a try.
The importance of PYTHONPATH
According to the official documentation this is what you need on your Apache’s site configuration to setup Django:
<Location “/mysite/”>
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonPath “['/path/to/project'] + sys.path”
PythonDebug On
</Location>
Obviously PythonDebug On should not appear, or should be set to Off, on a production environment.
The lines above assume that your Django project is called mysite and the site is on http://example.com/mysite. And even if the documentation mentions how to handle PYTHONPATH via mod_python I didn’t have a clear picture of the whole thing after running my first failed tests.
I decided to setup a site dedicated just to my Django project, you can use name based or IP based virtual hosts on Apache, and I want to access it from the root: http://example.com/. Also, I store all my Python related stuff in /home/alexis/python-work hence the project will be at /home/alexis/python-work/project and its only application below it: /home/alexis/python-work/project/app.
I know there are better ways to organize reusable applications on Django, as James Bennett suggests, but for my project a traditional project/app structure was enough. Anyway, the following ideas can be applied to any setup. Let’s see all the lines I use on Apache to setup a Django site:
<VirtualHost 192.168.0.180>
ServerName example.com
ServerAdmin alexis@example.com
<Location “/”>
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE project.settings
PythonDebug On
PythonPath “['/home/alexis/python-work', '/home/alexis/python-work/project'] + sys.path”
</Location>
</VirtualHost>
The IP on VirtualHost, 192.168.0.180, is the private one I’ll be using for this site. I’ve also added 192.168.0.180 example.com in /etc/hosts to avoid changes on the DNS server, something you should do on production.
project.settings refers to the settings.py file inside the /home/alexis/python-work/project directory.
I’ve also removed PythonOption django.root /mysite because this site sits on root, Location “/”, and there’s no need to specify a subdirectory.
And the most important part:
PythonPath “['/home/alexis/python-work', '/home/alexis/python-work/project'] + sys.path”
This is how you add paths to PYTHONPATH via mod_python. Notice we have two paths, one for the parent directory and another for the project, both are needed to get all your imports right. Django’s documentation highlights this:
Remember: the parent directories of anything you import directly must be on the Python path.
After adding these changes you should restart Apache, or possibly just reload, and be able to access your Django site at http://example.com/.
Date Parsing with ColdFusion / Twitter June 2, 2009
Posted by scoopseven in ColdFusion.Tags: Twitter
2 comments
The Twitter API is great. Except for the dates it returns, especially if you’re a ColdFusion progammer. I ended up using some code posted by Peter Freitag to write a UDF to convert the Twitter date/time to a ColdFusion friendly date/time.
Twitter makes matters worse with it’s inconsistency between the REST and Search APIs. My UDF also deals with the different date formats returned by the Twitter APIs.
Search API returns: Sat, 16 May 2009 05:26:32 +0000
REST API returns: Sat May 16 05:26:32 +0000 2009
Nice.
*As of May 2009 the Twitter REST API and Search API still return different date formats. http://code.google.com/p/twitter-api/issues/detail?id=206
If you’re interested in the udf, comment or email me at mark at mediapost.com. Unless it’s a weekend I’ll get it to you within a couple of hours.
Get the First x Words from a String / Word Count in ColdFusion April 30, 2009
Posted by scoopseven in ColdFusion.add a comment
Get the first X words in a string:
#REReplace(str,”^(#RepeatString(‘[^ ]* ‘,maxwords)#).*”,“\1″)#
Rough word count, which will miss hyphen-ated or other/words.
#ArrayLen(commentContent.split(‘\s++’))#
JDBC Connection Strings for Coldfusion 6.1 / CFMX April 14, 2009
Posted by scoopseven in ColdFusion, Database, MySQL.add a comment
If you’re trying to setup ColdFusion MX 6 with MySQL here’s how you setup the MySQL datasources. In CF Administrator go to Datasources and Add a New datasource of type “Other”. Enter your datasource name, username and password and the following fields like this:
JDBC URL: jdbc:mysql://192.168.1.100/DatabaseName
Driver Class: com.mysql.jdbc.Driver
Driver Name:MySQL Connector/J
Make sure you have the latest MySQL drivers installed too.
Getting the link from A tags /Getting all the links from a string in ColdFusion April 2, 2009
Posted by scoopseven in ColdFusion, MediaPost.add a comment
I thought for sure that this would be something fairly easy to find. Alas, it was not.
I did find a way to get all of the text from between the a tag, but not the links. Here’s how you do it:
<cfset beginlink = REFindNoCase(“https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?”, myText)>
<cfset endlink = findnocase(‘”‘, myText, beginlink)>
<cfset linklen = endlink – beginlink>
<cfset mylink = mid(myText, beginlink, linklen)>
Obviously, you can optimize this into a couple of lines, but there it is.
Virtual Hosts with Jboss / Apache / ColdFusion March 25, 2009
Posted by scoopseven in ColdFusion, Linux, MediaPost.add a comment
ServerName www.mysite.comServerAlias sitetwo #added this line to Apache .conf file.
<jboss-web><context-root> /</context-root><virtual-host>www.mysite.com</virtual-host><virtual-host>sitetwo.mysite.com</virtual-host></jboss-web>
Spidering and Saving Images with CFHTTP and CFFILE March 11, 2009
Posted by scoopseven in ColdFusion, Linux, MediaPost.add a comment
Goal: To spider a site (our own site) and save all image files from the pages on that site to a hard disk on another server.
Thanks to Ben Nadel for showing me the way on this one. For some reason the path/file attributes on cfhttp were not allowing me to save a image file to the hard disk on our linux (CentOS) server. I thought I could save the file using cfcontent somehow, which led me to Ben’s post. Never thought to just save the binary stream using cffile. Not sure if there was a permissions problem or what, but here’s the work-around.
<!— Grab the image file. —>
<cfhttp
method=”get”
url=”http://www.myurl.com/someimage.jpg”
useragent=”#CGI.http_user_agent#”
getasbinary=”yes”
result=”objGet” /><!— Save the image file. —>
<cffile action=”write”
output=”#objGet.FileContent#”
mode=”777″
file=”/mypath/myimage.jpg”>
This worked like a charm. Again, not sure if this was cfhttp doesn’t support the “mode” attribute or what, but it helped immensely. Thanks, Ben.
PayPal Merchant Sevices Phone Number July 29, 2008
Posted by scoopseven in MediaPost.add a comment
If you’re looking to call PayPal re: a Merchant Services or Payflow Pro account, here’s the direct number, so you don’t have to call India. 866-445-3167.
How to Dump and Import a Database or Table using the CLI on Linux July 8, 2008
Posted by scoopseven in Linux, MySQL.1 comment so far
Log onto your server from the console or with a ssh client. I use Putty. Use the following command to dump a table.
myserver# mysqldump -u yourUserName -p yourDatabaseName yourTableName > yourDestinationFileName.sql
Use this command to dump a whole database (this may take a while). I’m using putting the dump file into a directory below too. Just to add to the example.
myserver# mysqldump -u yourUserName -p yourDatabaseName > /yourDestinationDirectory/yourDestinationFileName.sql
Because I’m moving this to another Linux DB server, I’m going to use scp to copy the file over
myserver# scp theFileIDumpedAbove.sql yourUserName@yourDestinationServer:/yourDestinationDir/yourDestinationFile.sql
Finally, on my destination server, where I just scp’ed the file to, I import my dump file into my database. If you’re replacing tables, make sure you drop those tables from the DB before you try to import them.
myserver# mysql -p yourDestinationDatabase < /yourSourceDirectory/yourSourceSqlFile.sql