Lamp on Centos 7
- Manual Steps for Centos 7
sudo yum install httpd -y sudo systemctl enable httpd.service sudo systemctl start httpd.service sudo yum install php php-mysql sudo systemctl restart httpd.service sudo vi /var/www/html/info.php <?php phpinfo(); ?>
- Reference from here
- Create a new recipe called as httpdphp for redhat flavor
chef generate recipe . httpdphp
- Recipe will be as shown below
# # Cookbook:: . # Recipe:: httpdphp # # Copyright:: 2019, The Authors, All Rights Reserved. package 'httpd' do action :install notifies :enable, 'service[httpd]' end package_names = ["php", "php-mysql"] package_names.each do |package_name| package package_name do action :install end end cookbook_file '/var/www/html/info.php' do source 'info.php' action :create notifies :restart, 'service[httpd]' end service 'httpd' do action :nothing end
If you compare recipes of redhat and ubuntu, they are almost similar so trying to write one recipe for both.
This requires to understand couple of concepts in chef
- Node Object
- Information collected about node during convergence.
- This information is collected by Ohai
- Information Collected by ohai will be stored as Node Object.
- Accessing Node objects can be done in recipes by using following syntax
- Use Node Objects and User Defined Attributes to write one recipe for lamp stack which runs on ubuntu and centos.