Chef : Writing cookbook to configure apache webserver

Share At:

Chef is infrastructure automation tool which can be used to build infra as code. This is quite useful tool which lets you to do numerous tasks simultaneously on hundreds of servers with just few commands…e.g. configuring application , install packages, create users…etc and much more…

Here, we’ll see how to write cookbook to configure apache server on centos and upload the cookbook on “Chef Server”.

We will also learn how to bootstrap client server and configure apache on client server.


  1. You should have a chef account created(go to and sign up for the account if you don’t have it).
  2. You have already downloaded “Chef Starter kit” from chef website
  3. You have already installed “Chef development kit” on chef workstation
  4. latest version of chef Development Kit can be downloaded for centos7 from below url:


  1. Generate a apache cookbook:

2. Now you will see a directory called apache. Please go inside apache/recipes:

3. Open the default.rb file in your favourite test editor and update it with below contents:

4. Now cd to “apache” directory once again and create “files/default” directories. Chef will look for index.html in this location.

5. Create index.html with below contents:

6. Upload the cookbook to Chef Server using Knife utility:

7. Now visit the Chef server portal and you will see your cookbook listed there

8. Here you can see the content of your recipe:

Your cookbook is ready to use.

Bootstrapping chef client:

Bootstrapping chef client from chef workstation would install chef client package in the chef client server and also list the chef client in the chef server.


knife bootstrap — sudo -U vagrant -N chefnode1

where is the client node ip (chefnode1) in our case.

Showing Client node Ip
Image showing bootstrapping the client node from chef workstation

You will see chef node entry similar to this in the chef server:

Now add the runlist “apache” to the chef client — “chefnode1” .

command: knife node run_list add chefnode1 “recipe[apache]”

Now go to the chef client — chefnode1 and run below command:

Verify that httpd is installed and running in the chefnode1:

Now open your browser and type the ip of chefnode1, you will see the “Hello World” webpage.

Well, you have just created a webpage.

Happy Learning !!!

Share At:
0 0 votes
Article Rating
Notify of
Oldest Most Voted
Inline Feedbacks
View all comments
gate io giriş
6 days ago

I am a student of BAK College. The recent paper competition gave me a lot of headaches, and I checked a lot of information. Finally, after reading your article, it suddenly dawned on me that I can still have such an idea. grateful. But I still have some questions, hope you can help me.

gate io vip 1 olmak
8 days ago

I am a website designer. Recently, I am designing a website template about The boss’s requirements are very strange, which makes me very difficult. I have consulted many websites, and later I discovered your blog, which is the style I hope to need. thank you very much. Would you allow me to use your blog style as a reference? thank you!

gate io kimlik doğrulama

Thank you very much for sharing. Your article was very helpful for me to build a paper on After reading your article, I think the idea is very good and the creative techniques are also very innovative. However, I have some different opinions, and I will continue to follow your reply.

giresun kültür sitesi

thank you

karabük eğitim sitesi

thank you

Back To Top

Contact Us