To finish the lamp stack, Robin creates a simple PHP application and adds these components to the lamp cookbook.
- [Instructor] We're ready to set up our PHP application. Now, to configure PHP, we'll have to make sure Apache and MySQL are configured to speak to PHP and interpret PHP files. There's only a couple more pieces to configure inside of our web recipe here because we have laid most of the groundwork by setting up the httpd cookbook already. The httpd cookbook defines this httpd module resource that we can utilize to install Apache modules, httpd_module.
This essentially allows us to configure Apache to speak to particular types of applications like PHP. So, as an argument here for the name, we'll state that we're going to configure php5. Opening up a do and Ruby block for this resource, we'll simply go through and state the instance that we would like to add, the PHP module too. We'll state that we're adding this to default.
Now, that's all that will be necessary to set up Apache to speak to a PHP application. Now we need to install the native php5 MySQL package which enables PHP code to connect to your MySQL database. To do this, we'll use the package resource, a simple one, and we'll give it a name of php5-mysql. Opening up a do and Ruby block, we can then take the action of install on this package.
And lastly here, we don't just want to install this package. We need to actually restart the httpd_service when this package is installed so that it understands that a new package has been loaded that allows MySQL to connect to our PHP app. To do this, we'll use a notification like you saw earlier when we had a subscribe statement in httpd_service. For this package resource, we're going to send the notification with notifies.
We're going to restart the httpd_service resource and the name of it is default. I want to make sure you understand the notification in the sense that I'm telling this package resource to send a notification to httpd_service. However, this only occurs when the package resource itself changes its state. In other words, when this package is installed, it will send this notification to tell the service to restart, but only when the package is installed or changed.
Well done, this sets up PHP. Go ahead and save this file.
This intermediate-level course provides insights into the Chef architecture through practical examples and demos, including the deployment of a PHP application on top of a LAMP stack. Instructor Robin Beck walks through recipe development and the various prebuilt cookbooks available from the Chef community Supermarket, and reviews best practices for building wrapper cookbooks that allow you to access recipes from different cookbooks. He also shows how to work more efficiently with knife commands for managing clients, cookbooks, and data.
- Building a setup recipe
- Using cookbooks to organize recipes
- Using community recipes
- Uploading cookbooks
- Using the database cookbook
- Adding PHP to the mix
- Searching with knife
- Testing cookbooks with Kitchen