Install Apache Solr on Drupal + CentOS

By BXTra |

1. Install Java SDK using below command :

yum install java-1.6*

2. Download Apache Solr module from Drupal server. (Do it as you normally do with Drupal)

3. Then, get "SolrPhpClient" and put it under Apache Solr module directory. The directory name must be "SolrPhpClient".


4. Download the latest Solr 1.4.x release (Current is 1.4.1). Below, I put it in root directory. You can put it anywhere but not where you can access it through your website. So, not under "public_html" folder. I also renamed folder to make it shorter.

cd /
tar xvfz apache-solr-1.4.1.tgz
mv apache-solr-1.4.1 solr

5. Apache Solr comes with an example files you can use and they are located as a subdirectory in ApacheSolr folder. So, what you have to do is to copy 2 files ( schema.xml and solrconfig.xml ) from Apache Solr Drupal module directory to replace files in "/solr/example/solr/conf" folder

cp ../public_html/sites/all/modules/apachesolr/schema.xml /solr/example/solr/conf
cp ../public_html/sites/all/modules/apachesolr/solrconfig.xml /solr/example/solr/conf

6. To test if Apache Solr is working try below command :

cd /solr/example
java -jar start.jar

Now, try to access your Apache Solr page with below URL :


You may replace "localhost" to your own "IP Address". If you saw an Apache Solr page, then, it's working. If not, make sure you don't have any firewall to block port 8983. After you're done setting it, you can block port 8983 as usual. Since you don't need to open your firewall to access localhost. If Apache Solr is running, you will see something similar to image below :

7. Try to enable Apache Solr Module in your Drupal. It should work now.

8. Now, I'm sure you don't want to run "java -jar start.jar" everytime you reboot your server. So, you have to create Start/Stop script to make it automatically startup when reboot. So, follow steps below :

Create Apache Solr Start/Stop Script

nano -w /etc/init.d/solr

Copy and paste code below :

Apache Solr Start/Stop Script

#!/bin/sh -e

# Starts, stops, and restarts solr
# chkconfig: 35 92 08
# description: Starts and stops Apache Solr

JAVA_OPTIONS="-Xmx1024m -DSTOP.PORT=8079 -DSTOP.KEY=stopkey -jar start.jar"

case $1 in
        echo "Starting Solr"
        cd $SOLR_DIR
        echo "Stopping Solr"
        cd $SOLR_DIR
        $JAVA $JAVA_OPTIONS --stop
        $0 stop
        sleep 1
        $0 start
        echo "Usage: $0 {start|stop|restart}" >&2
        exit 1

Above is the startup script. What you really need to change is line #7 which is the path to your Apache Solr file.

You may also need to look at line #8. "-Xmx1024m" is to set maximum memory allowed to use in Java. Here, I set it to 1 gigabyte (= 1,024 megabytes). Lower it if you don't have that much RAM or increase it if Apache Solr needs more RAM.

Once you are done with it. run

chmod 755 /etc/init.d/solr

Now, you can start stop or restart Apache Solr with below command :

service solr start
service solr stop
service solr restart

To make it run automatically, run below command :

sudo chkconfig --add solr

Software :
- CentOS 5.4 - 64 bits
- Apache Solr 1.4.1
- OpenJDK though Yum package
- Drupal 6.20
- Apache Solr module 1.2 for Drupal

Source :

Update : 2011.07.25 - Tested with Apache Solr 3.3 and it works using the same instruction.

Works like a charm.. Even with Solr 3.3. Thx!!! In addition off this guide -> also visit

hi, i have a problem when i create the solr script , after that I go to localhost:8983/solr and show me HTTP ERROR: 404 Problem accessing /solr. Reason: NOT_FOUND pleasee, help mee!

Hi,Nice trick but for me it is not working. I am using dupal 6.x and try to use your code in my moulde. let me explain what am i exactly doing so you might help me. in my moulde i am creating one database and after that fetching values from .sql file and trying to insert it into newly created database. Now with my moulde i have made one database but to insert new query in that database i have to switch db and run query. When i try to use your trick it simple give me error that Access denied for moulde and logout from website. can you help me ? you can directly email me also if you have some solution.

Add new comment

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.