Displaying articles with tag apache
Posted by hank,
Wed Feb 21 23:13:00 UTC 2007
I had some difficulty along the way, and I have some fixes for those of you who are having trouble converting. I found that Mephisto is actually very friendly to the ./script/console hacker. Also, though it took a while to actually get a response, I ended up getting direct help from technoweenie in #mephisto@irc.freenode.net, which was a big help. So, here’s the situation:
My current host is Site5. I have gems set up in my home directory, and I have rails 1.2.2 installed as a gem. I tried using it, but just ended up freezing edge rails because I ran into some trouble. I created a db, subdomain, and .htaccess entry for the site. Then, I actually checked it out:
svn co http://svn.techno-weenie.net/projects/mephisto/trunk mephisto
Then, I created config/database.yml. Here’s a template you can use:
development:
adapter: mysql
database: mephisto
username: meph
password: <new-pw>
host: localhost
production:
adapter: mysql
database: mephisto
username: meph
password: <new-pw>
host: localhost
typo:
adapter: mysql
database: typo
username: typo
password: <typo-pass>
host: localhost
Next, I installed tzinfo as a gem to my home directory, and froze it in the project root:
gem install tzinfo
cd mephisto
rake gems:freeze GEM=tzinfo
Finally, it’s time to fill the database with stuff:
rake db:bootstrap
Now that that’s done, for CGI and FastCGI to work, we need a .htaccess file in public:
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
Notice I left it as dispatch.cgi. It’s up to you, but while I was still converting I left it like this since it didn’t want to run with FastCGI.
Let’s make sure log and public can be read and, if need be, written to:
chmod -R 755 public log
And finally, the moment we’ve all be waiting for:
script/runner "Mephisto.convert_from :typo" -e production
This connects to the Typo database and runs a converter script in Mephisto’s vendor/plugins/ directory. It takes all the attributes Typo articles and users and comments had and converts them to Mephisto form. Rockin’.
Old Typo Woes
I did this with Typo trunk v1246 with migration level 55. If you are at a similar Typo state, then you may definitely want to continue reading as the next steps I took will be necessary for you as well.
First of all, I saw that my Markdown with SmartyPants formatting was not being interpreted at all! This was, of course, easy to fix because Mephisto is awesome:
./script/console
# Don't do this unless you ALWAYS used Markdown with SmartyPants
# Refer to vendor/plugins/filtered_column if you use Textile or straight up Markdown
# It's just a different a.filter= line below.
Article.find(:all).each {|a|a.filter='smartypants_filter';a.save};1
What this does is find all the Mephisto articles and set their filter to Markdown with SmartyPants. The 1 on the end just prevents it from spewing every article to the console.
Now here’s where I ran into some trouble. Typo has changed its Tag storage technique at least twice, and the way my tags happened to be stored is as follows:
articles
- id
articles_tags
- article_id
- tag_id
tags
- id
- name
Someone else had posted a small loop to cure another type of Typo tagging scheme, where there was just one tag grouping string per article. I ran that. Don’t do that.
I noticed that each one of my articles only had one tag, which made me a sad monkey. To remedy this, I wrote a small loop to find all the tags of a Typo article and set them up for the same article in Mephisto. Now, since the id’s on articles and tags are not kept constant in the conversion scripts, this was a bit tricky. Luckily, I never have duplicate permalinks (I guess that means I’m creative…).
First, you have to enable the Typo converter in the console. I did this by adding these 2 lines to the bottom of vendor/plugins/mephisto_converters/init.rb:
require "converters/base"
require "converters/typo"
Then, it’s simply a case of the following:
./script/console
# Remove All Mephisto Taggings as to not make dupes
Tagging.find(:all).each{|t|t.destroy}
# Loop through every Typo article
# Find the associated Mephisto article
# Loop through all the Typo Tags
# Append each tag to the Mephisto tag array
Typo::Article.find(:all).each do |ta|
a = Article.find_by_permalink(ta.permalink)
ta.tags(true).collect{|b|b.name}.each do |tag|
a.tags(true) << Tag.find_by_name(tag)
end
end
Don’t forget to remove the requires you put into init.rb above. Once you do that, you should have a nicely running Typo -> Mephisto conversion. Congratulations!
Tags: apache
Posted by hardwarehank,
Thu Jun 22 22:34:30 UTC 2006
So, Apache (httpd) was hanging for some reason, and it was really perplexing. I turned on the mod_status stuff and looked at the results, and found that the hung processes were caused when requests went to certain Subversion repositories. All I had to do was svnadmin recover them, and all was well.
Otherwise, I found an interesting function for ruby today…
#number_with_delimiter(number, delimiter)
number_with_delimiter(2000000)
Makes 2000000 look like 2,000,000. Amazing!
Tags: apache
Posted by hardwarehank,
Thu Jun 15 10:14:37 UTC 2006
So, after a day of working on it, I finally fixed the problems I was having.
I wanted to have Apache forward all traffic hitting a path to a mongrel server running in a rails application. So, I did as bish0p suggested, and set up the rails app to accept this behavior. First, I put this at the bottom of my environment.rb:
ActionController::AbstractRequest.relative_url_root = "/MyRailsApp"
This make it so all the urls in the Rails app are prepended with /MyRailsApp. Without this, you’ll get renders that don’t have stylsheets, javascripts, or anything else that resides in the public directory of rails.
Second, I made a ProxyPass entry in the Apache configuration:
Redirect /MyRailsApp http://www.example.com/MyRailsApp/
ProxyPass /MyRailsApp/ http://localhost:6402/MyRailsApp/
ProxyPassReverse /MyRailsApp/ http://localhost:6402/MyRailsApp/
This allows all traffic that goes to /MyRailsApp on the server to be redirected to my mongrel server, which is running on port 6402 (This port does not have to be unfirewalled since all the requests are done locally by Apache).
Next, I have to further fix the problem of mongrel not being able to find things in public by making a symlink in public to itself. Make sure not to just do a link to ../public. Here’s an example:
cd public
mkdir MyRailsApp # This has to be whatever you used in your Apache configuration.
cd MyRailsApp
ln -s ../* . # Link to everything above.
rm MyRailsApp # Get rid of the recursive link.
Now, just configure your db, application, etc. and start the mongrel server from the root of the application.
mongrel_rails start -p 6402 -e production -d
And voila! You have a working ProxyPass connection from Apache to Mongrel.
Update:
Thanks to this article, I now have mod_deflate running! It was very easy to install:
apxs -c -i mod_deflate.c # As Root
This will install it to your apache installation’s modules directory. Now, just add some lines in your config:
Redirect /MyRailsApp http://www.example.com/MyRailsApp/
ProxyPass /MyRailsApp/ http://localhost:6402/MyRailsApp/
<Location /MyRailsApp>
ProxyPassReverse /MyRailsApp
SetOutputFilter INFLATE;proxy-html;DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript
</Location>
Congratulations, you’re now deflating your HTML/XML/CSS/JS/PlainText files! This works on all modern browsers (yes, even Lynx), and greatly reduces the size of the files sent. Here’s a summary:
Before:
14.4K: 172.65 seconds
28.8K: 86.32 seconds
33.6K: 73.99 seconds
56K: 44.40 seconds
ISDN 128K: 13.60 seconds
T1 1.44Mbps: 1.18 seconds
After:
14.4K: 52.27 seconds
28.8K: 26.13 seconds
33.6K: 22.40 seconds
56K: 13.44 seconds
ISDN 128K: 4.12 seconds
T1 1.44Mbps: 0.36 seconds
Roughly 3 times as fast!!
Also, it may be possible to leave off a lot of the junk here. I might have to streamline the configuration some in the following days. If I’m right, you won’t even need the ActionController line anymore.
Tags: apache
Posted by hardwarehank,
Tue Jun 13 23:54:58 UTC 2006
Well, I guess I might as well finish the job as much as I can before bed. I’m going to install Collaboa. Here’s the beginning:
Get rails and mongrel, along with all the deps:
sudo gem install rails mongrel redcloth syntax sqlite3-ruby xhtmldiff
Now, get ruby-mysql, which requires some junk on FC5:
sudo yum install mysql mysql-devel
sudo gem install mysql -- --with-mysql-config
Now, get the trunk:
svn co http://svn.collaboa.org/svn/collaboa/trunk/ collaboa --username=anon --password=anon
I’m going to use SQLLite for this project. I have to make the database:
touch db/pdn.db
Here’s my database.yml:
production:
adapter: sqlite3
dbfile: db/pdn.db
Now, I have to tell it where my repositories are (config/repository.yml):
production:
repos_path: /path/to/repos/hank
Now that the database and repository files are setup, I have to import the schema and default settings:
RAILS_ENV="production" rake db_schema_import
RAILS_ENV="production" ruby db/default_content.rb
Now I finally sync the repository with the database:
./script/repository_syncer
Time to start mongrel!
mongrel_rails start -p 3010
Now, I redirect the apache server to mongrel when /browse is accessed (I’m running mongrel on port 3010)(bottom of conf.d/svn.conf):
Redirect /browse http://example.com/browse
ProxyPass /browse/ http://localhost:3010/browse/
ProxyPassReverse /browse/ http://localhost:3010/browse/
NOTEs:
- Make sure that BOTH YOUR PROXYPASS LINES HAVE A FINAL / AT THE END OF EACH ARGUMENT. This will solve the redirection limit errors.
- Make a symbolic link in public to itself, and call it whatever you named the proxypass (in this example, browse). This will stop the no-images/stylesheets madness.
Tags: apache
Posted by hardwarehank,
Tue Jun 13 22:55:48 UTC 2006
This will let you redirect an apache request to a local mongrel or webrick server. Very handy, yet maybe some logging of the used ports would be good at some point.
<VirtualHost collaboa.example.com:80>
Servername collaboa.example.com
CustomLog /www/collaboa/logs/access.log combined
ErrorLog /www/collaboa/logs/error.log
ProxyPass / http://127.0.0.1:3005/
ProxyPassReverse / http://127.0.0.1:3005/
</VirtualHost>
Tags: apache
Posted by hardwarehank,
Tue Jun 13 22:32:33 UTC 2006
I was trying to move the subversion server today, and found some good tips, but I had some problems today building subversion, so I decided I better write the process down. While I’m at it, I better detail the steps to install apache as well.
Apache
Get the trunk, and go to the source library directory:
svn co http://svn.apache.org/repos/asf/httpd/httpd/branches/2.0.x httpd-2.0
cd httpd-2.0/srclib
Now, check APR out of svn:
svn co http://svn.apache.org/repos/asf/apr/apr/branches/0.9.x apr
svn co http://svn.apache.org/repos/asf/apr/apr-util/branches/0.9.x apr-util
cd ..
Build with some awesome options:
./buildconf
./configure --enable-so --enable-dav --enable-rewrite --enable-ssl --enable-proxy --enable-proxy-http --enable-proxy-connect --enable-proxy-ftp
make
sudo make install
Make sure to edit the httpd.conf file’s ServerName and, if necessary, User and Group. Also, make a conf.d and include it in your config file:
Include conf.d/*.conf
Then, make a sweet config file for subversion (conf.d/svn.conf):
<Location /repos>
DAV svn
SVNParentPath /path/to/repos
AuthType Basic
AuthName "GINA Beta Subversion Repository"
AuthUserFile /path/to/repos/svn-auth-file
AuthGroupFile /path/to/repos/svn-group-file
# read-only access to repos
# only authenticated users may modify repos
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require group devel
</LimitExcept>
<Limit GET PROPFIND OPTIONS REPORT>
require valid-user
</Limit>
</Location>
Subversion
Now, just get it:
svn co http://svn.collab.net/repos/svn/trunk subversion
cd subversion
Now, get APR again:
svn co http://svn.apache.org/repos/asf/apr/apr/branches/0.9.x apr
svn co http://svn.apache.org/repos/asf/apr/apr-util/branches/0.9.x apr-util
Configure it (buildconf first), build it, install it, then do SWiG Ruby stuff:
./buildconf
./configure --with-apxs=/usr/local/apache2/bin/apxs
make
sudo make install
make swig-rb
make check-swig-rb # This might have some bdb failures. Who cares?
sudo make install-swig-rb
Now, it should be up and running. Next time, Collaboa.
Tags: apache