1 #!/usr/bin/perl -w # please develop with -w
4 use strict; # please develop with the strict pragma
7 print "You must be root to run this script.\n";
13 **********************************
14 * Welcome to the Koha Installer *
15 **********************************
16 Welcome to the Koha install script! This script will prompt you for some
17 basic information about your desired setup, then install Koha according to
18 your specifications. To accept the default value for any question, simply hit
21 Please be sure to read the documentation, or visit the Koha website at
22 http://www.koha.org for more information.
24 Are you ready to begin the installation? (Y/[N]):
30 if ($answer eq "Y" || $answer eq "y") {
31 print "Great! continuing setup... \n";
34 This installer currently does not support an completely automated
37 Please be sure to read the documentation, or visit the Koha website
38 at http://www.koha.org for more information.
46 # Test for Perl and Modules
55 print "\nChecking perl modules ...\n";
56 unless (eval "require 5.004") {
57 die "Sorry, you need at least Perl 5.004\n";
61 unless (eval {require DBI}) { push @missing,"DBI" };
62 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
63 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
64 unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
65 #unless (eval {require Net::Z3950}) {
68 #The Net::Z3950 module is missing. This module is necessary if you want to use
69 #Koha's Z39.50 client to download bibliographic records from other libraries.
70 #To install this module, you will need the yaz client installed from
71 #http://www.indexdata.dk/yaz/ and then you can install the perl module with the
74 #perl -MCPAN -e 'install Net::Z3950'
76 #Press the <ENTER> key to continue:
82 # Print out a list of any missing modules
86 print "You are missing some Perl modules which are required by Koha.\n";
87 print "Once these modules have been installed, rerun this installer.\n";
88 print "They can be installed by running (as root) the following:\n";
89 foreach my $module (@missing) {
90 print " perl -MCPAN -e 'install \"$module\"'\n";
93 print "All modules appear to be installed, continuing...\n";
99 my $domainname = `hostname -d`;
101 my $opacdir = '/usr/local/koha/opac';
102 my $kohadir = '/usr/local/koha/intranet';
104 while ($getdirinfo) {
105 # Loop until opac directory and koha directory are different
110 Please supply the directory you want Koha to store its OPAC files in. Leave off
111 the trailing slash. This directory will be auto-created for you if it doesn't
117 print "Enter directory [$opacdir]: ";
118 chomp($input = <STDIN>);
127 INTRANET/LIBRARIANS DIRECTORY
128 =============================
129 Please supply the directory you want Koha to store its Intranet/Librarians files
130 in. Leave off the trailing slash. This directory will be auto-created for you if
135 print "Enter directory [$kohadir]: ";
136 chomp($input = <STDIN>);
141 if ($kohadir eq $opacdir) {
144 You must specify different directories for the OPAC and INTRANET files!
157 my $hostname = 'localhost';
158 my $user = 'kohaadmin';
165 Koha uses a small configuration file that is usually placed in your /etc/ files
166 directory. The configuration file, will be created in this directory
170 #Get the path to the koha.conf directory
171 print "Enter the path to your configuration directory [$etcdir]: ";
172 chomp($input = <STDIN>);
179 #Get the database name
182 Please provide the name of the mysql database for your koha installation.
183 This is normally "$dbname".
187 print "Enter database name [$dbname]: ";
188 chomp($input = <STDIN>);
195 #Get the hostname for the database
198 Please provide the hostname for mysql. Unless the database is located on another
199 machine this will be "localhost".
202 print "Enter hostname [$hostname]: ";
203 chomp($input = <STDIN>);
209 #Get the username for the database
212 Please provide the name of the user, who will have full administrative rights
213 to the $dbname database, when authenticating from $hostname.
215 If no user is entered it will default to $user.
218 print "Enter username [$user]:";
219 chomp($input = <STDIN>);
225 #Get the password for the database user
228 Please provide a good password for the user $user.
231 print "Enter password:";
232 chomp($input = <STDIN>);
241 #Create the configuration file
242 open(SITES,">$etcdir/koha.conf") or warn "Couldn't create file
243 at $etcdir. Must have write capability.\n";
249 includes=$kohadir/htdocs/includes
254 print "Successfully created the Koha configuration file.\n";
259 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
260 /usr/local/etc/apache/httpd.conf
261 /usr/local/etc/apache/apache.conf
262 /var/www/conf/httpd.conf
263 /etc/apache/conf/httpd.conf
264 /etc/apache/conf/apache.conf
265 /etc/httpd/conf/httpd.conf
266 /etc/httpd/httpd.conf)) {
267 if ( -f $httpdconf ) {
268 $realhttpdconf=$httpdconf;
269 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
270 while (<HTTPDCONF>) {
271 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
278 $httpduser ||= 'Undetermined';
281 # Set ownership of the koha.conf file for security
283 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
284 chmod 0440, "$etcdir/koha.conf";
289 my $svr_admin = "webmaster\@$domainname";
290 my $servername=`hostname -f`;
297 OPAC and KOHA/LIBRARIAN CONFIGURATION
298 =====================================
299 Koha needs to setup your Apache configuration file for the
300 OPAC and LIBRARIAN virtual hosts. By default this installer
301 will do this by using one ip address and two different ports
302 for the virtual hosts. There are other ways to set this up,
303 and the installer will leave comments in httpd.conf detailing
304 what these other options are.
306 Please enter the e-mail address for your webserver admin.
310 print "Enter e-mail address [$svr_admin]:";
311 chomp($input = <STDIN>);
321 Please enter the domain name or ip address of your computer.
323 print "Enter server name/ip address [$servername]:";
324 chomp($input = <STDIN>);
327 $servername = $input;
332 Please enter the port for your OPAC interface.
334 print "Enter OPAC port [$opacport]:";
335 chomp($input = <STDIN>);
343 Please enter the port for your Intranet/Librarian interface.
345 print "Enter intranet port [$kohaport]:";
346 chomp($input = <STDIN>);
354 # Update Apache Conf File.
358 my $logfiledir=`grep ^ErrorLog $realhttpdconf`;
362 $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
366 unless ($logfiledir) {
377 print "Checking for modules that need to be loaded...\n";
380 my $includesmodule=0;
381 open HC, $realhttpdconf;
383 if (/^\s*#\s*LoadModule env_module /) {
385 print " Loading env_module in httpd.conf\n";
388 if (/^\s*#\s*LoadModule includes_module /) {
390 print " Loading includes_module in httpd.conf\n";
392 if (/\s*LoadModule includes_module / ) {
398 my $apachebackupmade=0;
399 if ($envmodule || $includesmodule) {
400 system("mv -f $realhttpdconf $realhttpdconf\.prekoha");
402 open HC, ">$realhttpdconf";
408 if (`grep 'VirtualHost $servername' $realhttpdconf`) {
410 $realhttpdconf appears to already have an entry for Koha
411 Virtual Hosts. You may need to edit $realhttpdconf
412 if anything has changed since it was last set up. This
413 script will not attempt to modify an existing Koha apache
417 print "Press <ENTER> to continue...";
421 unless ($apachebackupmade) {
422 system("cp -f $realhttpdconf $realhttpdconf\.prekoha");
424 my $includesdirectives='';
425 if ($includesmodule) {
426 $includesdirectives.="Options +Includes\n";
427 $includesdirectives.="AddHandler server-parsed .html\n";
429 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
433 # Ports to listen to for Koha
437 # NameVirtualHost is used by one of the optional configurations detailed below
439 #NameVirtualHost 11.22.33.44
441 # KOHA's OPAC Configuration
442 <VirtualHost $servername\:$opacport>
443 ServerAdmin $svr_admin
444 DocumentRoot $opacdir/htdocs
445 ServerName $servername
446 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
447 ErrorLog $logfiledir/opac-error_log
448 TransferLog $logfiledir/opac-access_log
449 SetEnv PERL5LIB "$kohadir/modules"
453 # KOHA's INTRANET Configuration
454 <VirtualHost $servername\:$kohaport>
455 ServerAdmin $svr_admin
456 DocumentRoot $kohadir/htdocs
457 ServerName $servername
458 ScriptAlias /cgi-bin/koha/ "$kohadir/cgi-bin/"
459 ErrorLog $logfiledir/koha-error_log
460 TransferLog $logfiledir/koha-access_log
461 SetEnv PERL5LIB "$kohadir/modules"
465 # If you want to use name based Virtual Hosting:
466 # 1. remove the two Listen lines
467 # 2. replace $servername\:$opacport wih your.opac.domain.name
468 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
469 # 4. replace $servername\:$kohaport wih your intranet domain name
470 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
472 # If you want to use NameVirtualHost'ing (using two names on one ip address):
473 # 1. Follow steps 1-5 above
474 # 2. Uncomment the NameVirtualHost line and set the correct ip address
479 print "Successfully updated Apache Configuration file.\n";
483 # Setup the modules directory
487 CREATING REQUIRED DIRECTORIES
488 =============================
493 unless ( -d $kohadir ) {
494 print "Creating $kohadir...\n";
495 my $result=mkdir ($kohadir, oct(770));
497 my @dirs = split(m#/#, $kohadir);
501 unless (-e "$checkdir") {
502 mkdir($checkdir, 0775);
506 chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
507 chmod (oct(770), "$kohadir");
509 unless ( -d "$kohadir/htdocs" ) {
510 print "Creating $kohadir/htdocs...\n";
511 mkdir ("$kohadir/htdocs", oct(750));
513 unless ( -d "$kohadir/cgi-bin" ) {
514 print "Creating $kohadir/cgi-bin...\n";
515 mkdir ("$kohadir/cgi-bin", oct(750));
517 unless ( -d "$kohadir/modules" ) {
518 print "Creating $kohadir/modules...\n";
519 mkdir ("$kohadir/modules", oct(750));
521 unless ( -d $opacdir ) {
522 print "Creating $opacdir...\n";
523 my $result=mkdir ($opacdir, oct(770));
525 my @dirs = split(m#/#, $opacdir);
529 unless (-e "$checkdir") {
530 mkdir($checkdir, 0775);
534 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
535 chmod (oct(770), "$opacdir");
537 unless ( -d "$opacdir/htdocs" ) {
538 print "Creating $opacdir/htdocs...\n";
539 mkdir ("$opacdir/htdocs", oct(750));
541 unless ( -d "$opacdir/cgi-bin" ) {
542 print "Creating $opacdir/cgi-bin...\n";
543 mkdir ("$opacdir/cgi-bin", oct(750));
548 print "\n\nINSTALLING KOHA...\n";
549 print "\n\n==================\n";
550 print "Copying internet-html files to $kohadir/htdocs...\n";
551 system("cp -R intranet-html/* $kohadir/htdocs/");
552 print "Copying intranet-cgi files to $kohadir/cgi-bin...\n";
553 system("cp -R intranet-cgi/* $kohadir/cgi-bin/");
554 print "Copying script files to $kohadir/modules...\n";
555 system("cp -R modules/* $kohadir/modules/");
556 print "Copying opac-html files to $opacdir/htdocs...\n";
557 system("cp -R opac-html/* $opacdir/htdocs/");
558 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
559 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
561 system("chown -R root.$httpduser $opacdir");
562 system("chown -R root.$httpduser $kohadir");
571 my $mysqluser = 'root';
574 foreach my $mysql (qw(/usr/local/mysql
585 To allow us to create the koha database please supply the
586 mysql\'s root users password
589 print "Enter mysql\'s root users password: ";
590 chomp($input = <STDIN>);
602 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
604 print "\nCouldn't connect to the MySQL server for the reason given above.\n";
605 print "This is a serious problem, the database will not get installed.
\a\n";
606 print "Press <ENTER> to continue...";
610 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname < koha.mysql");
611 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
612 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv, index_priv, alter_priv) values ('%','$dbname','$user','Y','Y','Y','Y','Y','Y','Y','Y')\"");
613 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
615 system ("perl -I $kohadir/modules scripts/updater/updatedatabase");
622 If you are installing Koha for evaluation purposes, I have a batch of sample
623 data that you can install now.
625 If you are installing Koha with the intention of populating it with your own
626 data, you probably don't want this sample data installed.
628 print "\nWould you like to install the sample data? Y/[N]: ";
629 chomp($input = <STDIN>);
630 if ($input =~/^y/i) {
631 system("gunzip sampledata-1.2.gz");
632 system("cat sampledata-1.2 | $mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname");
633 system("gzip -9 sampledata-1.2");
634 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('Main', 'Main Library', 1)\"");
635 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
637 print "\n\nWould you like to add a branch and printer? [Y]/N: ";
638 chomp($input = <STDIN>);
641 unless ($input =~/^n/i) {
642 my $branch='Main Library';
643 print "Enter a name for the library branch [$branch]: ";
644 chomp($input = <STDIN>);
648 $branch=~s/[^A-Za-z0-9\s]//g;
649 my $branchcode=$branch;
650 $branchcode=~s/[^A-Za-z0-9]//g;
651 $branchcode=uc($branchcode);
652 $branchcode=substr($branchcode,0,4);
653 print "Enter a four letter code for your branch [$branchcode]: ";
654 chomp($input = <STDIN>);
658 $branchcode=~s/[^A-Z]//g;
659 $branchcode=uc($branchcode);
660 $branchcode=substr($branchcode,0,4);
661 print "Adding branch '$branch' with code '$branchcode'.\n";
662 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
663 my $printername='Library Printer';
664 print "Enter a name for the printer [$printername]: ";
665 chomp($input = <STDIN>);
669 $printername=~s/[^A-Za-z0-9\s]//g;
670 my $printerqueue='lp';
671 print "Enter the queue for the printer [$printerqueue]: ";
672 chomp($input = <STDIN>);
674 $printerqueue=$input;
676 $printerqueue=~s/[^A-Za-z0-9]//g;
677 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
691 Congratulations ... your Koha installation is almost complete!
692 The final step is to restart your webserver.
694 You will be able to connect to your Librarian interface at:
696 http://$servername\:$kohaport/
698 and the OPAC interface at :
700 http://$servername\:$opacport/
703 Be sure to read the INSTALL, and Hints files.
705 For more information visit http://www.koha.org
707 Would you like to restart your webserver now? (Y/[N]):
710 my $restart = <STDIN>;
713 if ($restart=~/^y/i) {
714 # Need to support other init structures here?
715 if (-e "/etc/rc.d/init.d/httpd") {
716 system('/etc/rc.d/init.d/httpd restart');
717 } elsif (-e "/etc/init.d/apache") {
718 system('/etc//init.d/apache restart');
719 } elsif (-e "/etc/init.d/apache-ssl") {
720 system('/etc/init.d/apache-ssl restart');
724 Congratulations ... your Koha installation is complete!
725 You will need to restart your webserver before using Koha!