Update on 2012.09.20: updated for Solr 4.0-BETA (from ALPHA, thanks for the comment Dorthe).
Update on 2013.07.09: updated for Solr 4.3.1
Update on 2013.07.28: the guide works with Solr 4.4, Ubuntu server 13.04 and tomcat7, just replace tomcat6 with tomcat7 and /var/lib/tomcat6/shared with /var/lib/tomcat7/lib

This short guide will describe how to install solr 4 on Ubuntu server. The versions I’m using are: Ubuntu Server 12.04 and Apache Solr 4.3.1. I will also show how to test the installation & perform a sample indexing and query.

Installation on tomcat Ubuntu 12.04 LTS

1. Install packages

  
 apt-get install tomcat6 curl

2. Download solr 4 from http://lucene.apache.org/solr (at the time of writing it was solr-4.3.1.tgz)
3. Choose directory for solr – know as SOLR_HOME. I’ve chosen to put it into /opt/solr so my SOLR_HOME=/opt/solr. Replace /opt/solr with your own location if you want a different one.
4. Extract downloaded files anywhere and copy following to your $SOLR_HOME and to your tomcat installation:

  • copy example/solr/* to /opt/solr
  • copy example/webapps/solr.war to /opt/solr
  • copy example/lib/ext/* to /var/lib/tomcat6/shared

5. Edit dataDir in solr configuration file /opt/solr/collection1/conf/solrconfig.xml:

  
<dataDir>${solr.data.dir:/opt/solr/data}</dataDir>

6. Create directory for solr data and make it write-able for tomcat server

  
% mkdir /opt/solr/data
% sudo chown tomcat6 /opt/solr/data

Here is how my /opt/solr directory looks like (showing only directories):

 
$ tree -d
├── bin
├── collection1
│   └── conf
│       ├── lang
│       ├── velocity
│       └── xslt
└── data

7. Setup new context in tomcat server pointing to our solr files. Create file /etc/tomcat6/Catalina/localhost/solr.xml with the following content:

  
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="/opt/solr/solr.war" debug="0" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value="/opt/solr" override="true"/>
</Context>

8. Restart tomcat

  
/etc/init.d/tomcat6 restart

9. Enjoy your newly set up solr4 by pointing your browser to http://localhost:8080/solr.

Sample indexing and UTF-8 test

solr installation files come with sample schema.xml (we’ve already copied it into our $SOLR_HOME) and some .xml files with sample data we can import. We will use one of them to test if UTF-8 encoding is working as expected.
1. Go to the directory with extracted solr installation files and import utf8-example.xml using curl

  
URL=http://localhost:8080/solr/update
curl $URL --data-binary @example/exampledocs/utf8-example.xml -H 'Content-type:application/xml'

The response from the server should be similar to

  
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">22</int></lst>
</response>
</xml>

2. Commit the documents

  
curl "$URL?softCommit=true"

3. Test it by searching for êâîôû string. Use solr administrative UI or this GET request should do: http://localhost:8080/solr/collection1/select?q=êâîôû. You should see exactly one result.