bosnadev

№ 1 · 2014-09-12 · 1 min · laravel

Install Elasticsearch on Laravel Homestead

Installing Elasticsearch 2.1 inside the Laravel Homestead Vagrant box with apt, forwarding its port and checking from the host that it responds.

written before the past year · entry 1 of 31 · 10 in the past year

This article is out of date
Written for Elasticsearch 2.1 and the Laravel Homestead box of the time.

Recently I started working on a Laravel project that requires integration with Elasticsearch search engine. I didn’t want to change super cool development environment that Taylor (creator of Laravel) so kindly provided to us, so I installed Elasticsearch on Homestead instead of creating a new Vagrant box specially for this project. Here is a little snippet that will help you if you want to use Elasticsearch in you Laravel application.

terminal26 lines
# Login as rootroot@homestead:~# sudo -s# Update Aptituderoot@homestead:~# apt-get update# Install Javaroot@homestead:~# apt-get install openjdk-7-jre-headless -y# Download and install Elasticsearch Public Signing Keyroot@homestead:~# wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -# Add repositoryroot@homestead:~# echo "deb http://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list# Update Aptituderoot@homestead:~# apt-get update# Install Elasticsearchroot@homestead:~# apt-get install elasticsearch# Set Elasticsearch to run on startuproot@homestead:~# update-rc.d elasticsearch defaults 95 10# Start Elasticsearch serverroot@homestead:~# /etc/init.d/elasticsearch start

 

After that you can configure port forwarding, edit your homestead.rb file and add following line just below other port forwards:

homestead.rbruby · 1 line
config.vm.network "forwarded_port", guest: 9200, host: 62000

You need to reload vagrant box:

terminal1 line
vagrant reload

Now, on your host, try to make curl request:

terminal1 line
curl -X GET localhost:62000

and you should have the following response:

{  "name" : "Penance",  "cluster_name" : "elasticsearch",  "version" : {    "number" : "2.1.0",    "build_hash" : "72cd1f1a3eee09505e036106146dc1949dc5dc87",    "build_timestamp" : "2015-11-18T22:40:03Z",    "build_snapshot" : false,    "lucene_version" : "5.3.1"  },  "tagline" : "You Know, for Search"}

That’s it, now when we have installed Elasticsearch on Laravel Homestead, in one of the next tutorials we will see how to index and search data.

 

Update (04.12.2015.) :
Tutorial has been updated to show installation process of the latest stable release of Elesticsearch at this time (2.1.0).

Related

Deploy your Laravel 4 application on HerokularavelLaravel Filters: Route access depending on the user grouplaravelSetting Up Laravel Environmentslaravel