Redmine 1.1.3 on HostMonster
Did you guys ever hear about Redmine? It is an open source project management web application written using Ruby on Rails framework. I already used it in the past and it is quite powerful!
I wanted to install the last version (1.1.3) on my HostMonster account. I would lie if I say that it has been easy… However, after a few try and some help from the HostMonster support, I finally got it to work. 🙂
These instructions are basically a copy of the ones I found on GetTaskDone but updated with additional steps (in red):
- Create MySQL Database and Username
Login to CPanel and click on MySQL Database Wizard, it will prompt you for database name, then ask you to make a user, make sure you GRANT ALL privileges. Remember these database details, we will use them later. - Create a Sub-Domain
For the purposes of this tutorial, name it redmine, point this sub domain to ~/public_html/redmine.
Do NOT copy any files into this directory, we will be deleting it later. - Make sure you have the right version of Rails installed
In case it is different from what you need you can install a specific Rails version on your machine by running:%prompt> gem install rails -v=2.3.5
- Create RoR directory
It is not recommended that you put your RoR apps within the ~/public_html directory, as users would be able to see the rb files. So we are going to create a rails directory.%prompt> cd ~ %prompt> mkdir rails
- Create Rails App
You create a rails app on HostMonster just like you would on your system, by using the rails command. We are creating the rails project inside of the rails directory.%prompt> cd rails %prompt> rails -D redmine
We need -D to let rails know that we want custom dispatch.rb, dispatch.cgi and dispatch.fcgi files for later steps.
- Create a Sym-Link for Sub-Domain
Since the HostMonster interface won’t let you select a directory outside of public_html, we are going to create a symbolic link from the ~/public_html/redmine folder to ~/rails/redmine. To do this we will be deleting the ~/public_html/redmine directory. The symbolic link will recreate it.%prompt> cd ~/public_html %prompt> rm -R redmine %prompt> ln -s ~/rails/redmine/public redmine
Please note the space between ~/rails/redmine/public and redmine This command says create a new folder named redmine that points to ~/rails/redmine/public
- Do a Smoke-Test
Goto subdomain.yourdomain.com, you should see the default rails welcome page. This is fine, this is what you should see right now. - Prepare Redmine
Download the latest final release of Redmine (it’s 1.1.3 now). Extract this to your desktop, you should now have a folder name redmine on your desktop. Login to your CPanel and goto File Manager. You’ll want to navigate to ~/rails/redmine/public, you’ll want to download the following files and put them in your local copy of redmine. Which should be ~/Desktop/redmine/public. Download dispatch.rb, dispatch.cgi and dispatch.fcgi.
Now edit your database.yml file with the database, username and password you created in step one. You only have to change those three values for production and development configurations. To do so copy config/database.yml.example into config/database.yml and edit the latter. Comment out all the rest lines.
Now inside of your local redmine folder select all the files and folders and right click and select ‘Compress all the items…’. What we are doing is uploading this archive, I seem to have problems every time I try to upload redmine file by file. - Upload Redmine
If you don’t have File Manager open still then login to CPanel and open it again. Navigate to your ~/rails/redmine folder and click the check boxes on all items and click delete. Now, upload your archive. Once it’s done uploading click on the archive in File Manager and hit extract. - Finish install
Now ssh into your server, you’re going to want to chmod 755 your ~/rails/redmine/public folder.%prompt> cd ~/rails/redmine %prompt> chmod 755 public
Next, you must create a custom .htaccess file for Apache to handle this directory properly. First remove any .htaccess file that may already be in the ~/rails/redmine/public directory.
%prompt> cd public %prompt> rm .htaccess
Download file from here: http://www.gettaskdone.com/redmine-htaccess/htaccess.txt into ~/rails/redmine/public directory and save it as .htaccess.
Best way to do this is by typing following set of commands:%prompt> cd ~/rails/redmine/public %prompt> wget http://www.gettaskdone.com/redmine-htaccess/htaccess.txt %prompt> mv htaccess.txt .htaccess
- Edit Rakefile
RubyGems 1.6.x is incompatible with the bundled rails 2.3.5. It’s documented in the RubyGems release notes that “RubyGems no longer requires ‘thread’. Rails < 3 will need to addrequire ‘thread’
to their applications.”
So we need to addrequire 'thread'
to the Rakefile after the linerequire 'rake/rdoctask'
. - Generate a session store secret
This is required on the trunk version of Redmine at r2493 or above and the released 0.8.7 version or above.
Redmine stores session data in cookies by default, which requires a secret to be generated. This can be done by running:%prompt> cd ~/rails/redmine %prompt> RAILS_ENV=production rake config/initializers/session_store.rb
- Edit config/enviroment.rb
Insert the following code between the bootstrap and the initialize sections in the config/enviroment.rb file:if Gem::VERSION >= "1.3.6" module Rails class GemDependency def requirement r = super (r == Gem::Requirement.default) ? nil : r end end end end
- Setup Database
We have to give redmine its database structure and default values.%prompt> cd ~/rails/redmine %prompt> RAILS_ENV=production rake db:migrate
- Insert default configuration data in database
Run the following command:%prompt> RAILS_ENV=production rake redmine:load_default_data
This step is optional but highly recommended, as you can define your own configuration from scratch. It will load default roles, trackers, statuses, workflows and enumerations.
- Rename the ‘vendor/rails’ folder
Run the following command:%prompt> mv vendor/rails vendor/rails.old
The vendor directory generally takes precedence over the other locations where Rails looks for libraries, and if it contains different versions of gems or other items, it can cause conflicts.
For your information, these are the links I used to write this article:
Detect if JavaScript is enabled
Because of the emergence of Ajax, people don’t disable JavaScript much nowadays.
I don’t know the percentage of people having disabled JavaScript. It is likely under 5%. But if you have a website visited by millions of visitors every month, even 1% is matter!
This is why I wrote the following code:
<noscript>JavaScript is DISABLED.</noscript> <span id="displayIfJavaScript" style="display:none">JavaScript is ENABLED.</span> <script> document.getElementById('displayIfJavaScript').style.display = "block"; </script>
The text under the noscript
tag will be displayed if JavaScript is disabled or not supported. The text under the span
tag is not displayed by default and will be showed using JavaScript, this is why we can be sure JavaScript is enabled in that case.
You can obviously change the content of the noscript
and span
tags. You could, for example, hide a form which uses JavaScript validation to non-JavaScript users by putting the HTML code of the form under the span
tag.
Please see below the above script in action:
Close ModalPanel if no error
It has been a very long time I wrote this code, but I thought I would share it with you as it is quite useful.
If like me, you are an adept of RichFaces, you might have already seen and used the modal panel functionality. By default, a modal panel is used to display a message, but what if you actually want to display a form within it? How nice would it be if, for example, you could put your login form in a modal panel instead of opening a new page?
With the following steps, you will be able to achieve this:
- First, get the maximum severity in the message queue:
<a4j:outputPanel ajaxRendered="true"> <h:form style="display:none" id="maximumSeverityForm"> <h:inputHidden id="maximumSeverity" value="#{facesContext.maximumSeverity.ordinal}"/> </h:form> </a4j:outputPanel>
This form has to be placed on all your pages using an include for example. This form will basically get refreshed on every postback and will contain the maximum severity in the message queue or null if the queue is empty.
- Create a JavaScript method which reads the
maximumSeverity
hidden field:function ajaxRequestContainsErrors() { return document.getElementById("maximumSeverityForm:maximumSeverity").value > 0; }
This method has to also be included in all the pages.
- Finally, use the following code for the “Submit” button in your form:
<a4j:commandButton action="#{userBean.loginAction}" value="Submit" oncomplete="if (!ajaxRequestContainsErrors()) {Richfaces.hideModalPanel('loginModalPanel');}"/>
This button is actually checking if there is no error before closing the modal panel.
Segmentation fault at end of PHP script
This one is a very strange problem!
I created a little PHP script which connects to a MySQL database. Nothing amazing, except that I needed to run it via command line using the php
command. What happened is that the script ran perfectly fine but, for some reason, it returned “Segmentation fault” when it reached the end of the file! 😯
It reminds me of the old days when I worked on C language, I used to see this not-very-useful message quite often. 😉
Anyway, why do we get a “Segmentation fault” at the end of a PHP script? And when I say ‘the end’, I mean after any other lines!
Looking around the web, I found the following bug report: http://bugs.php.net/bug.php?id=43823
This user seems to have the same problem than me except he is using a PostgreSQL database instead of a MySQL database.
Reading through the page, it looks like the problem comes from the order in which PHP loads his extensions! They explain that PostgreSQL should be loaded before cURL. If I apply the same logic, MySQL should then be loaded before cURL too.
To do that, we need to comment out the line extension=curl.so
from the file /etc/php5/cli/conf.d/curl.ini
:
# configuration for php CURL module #extension=curl.so
And add it to the file /etc/php5/cli/conf.d/mysql.ini
AFTER the line extension=mysql.so
:
# configuration for php MySQL module extension=mysql.so extension=curl.so
To be honest, I don’t really like this solution as it is a bit messy. I would prefer PHP developers to fix the root cause or at least have a way to change the order in which PHP loads the extensions.
NB: I was executing this PHP script on a Debian GNU/Linux 5.0 with Apache 2.2.9 and PHP 5.2.6.
How to dump MySQL functions and stored procedures
I discovered something interesting about MySQL the other day. Interesting enough to share it with you. 😉
I was in the process of moving a MySQL database from a server to another. In order to do this, I created a dump file from the source database using the command mysqldump
and I then restored the database on the destination server using the previously created dump file.
Below is the command I used to create the dump file:
mysqldump -u dbuser -p dbname > dump.sql
And here is the command used to restore the database:
mysql -u dbuser -p dbname2 < dump.sql
The interesting thing is that the functions and stored procedures have not been migrated using these commands… 🙁
To be honest with you, this was the first time I encountered this problem. Which probably means that it is the first time I migrate a database containing functions and/or stored procedures.
Checking the man page of the mysqldump
command, I found the following:
--routines, -R
Dump stored routines (procedures and functions) from the dumped databases. Use of this option requires the SELECT privilege for the mysql.proc table. The output generated by using --routines contains CREATE PROCEDURE and CREATE FUNCTION statements to re-create the routines. However, these statements do not include attributes such as the routine creation and modification timestamps. This means that when the routines are reloaded, they will be created with the timestamps equal to the reload time.
If you require routines to be re-created with their original timestamp attributes, do not use --routines. Instead, dump and reload the contents of the mysql.proc table directly, using a MySQL account that has appropriate privileges for the mysql database.
This option was added in MySQL 5.0.13. Before that, stored routines are not dumped. Routine DEFINER values are not dumped until MySQL 5.0.20. This means that before 5.0.20, when routines are reloaded, they will be created with the definer set to the reloading user. If you require routines to be re-created with their original definer,
dump and load the contents of the mysql.proc table directly as described earlier.
Alright, that looks straight forward! We simply need to add the parameter --routines
to the mysqldump
command in order to include the functions and stored procedures to our dump file.
For example:
mysqldump -u dbuser -p dbname --routines > dump.sql
We now have our dump file containing the functions and stored procedures.
I thought I was done at this stage. But I got the following error message while restoring the database on the destination server:
ERROR 1419 (HY000) at line 1140: You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
The error message is pretty clear. Binary logging needs to be enabled in order to restore the functions. There are two ways for doing this:
- Execute the following command into the MySQL console:
SET GLOBAL log_bin_trust_function_creators = 1;
- Add the line
log_bin_trust_function_creators = 1
to themysql.ini
configuration file
N.B. Execute the following commands to display the list of stored procedures and functions:
SHOW PROCEDURE STATUS; SHOW FUNCTION STATUS;