Search code examples
phprubyapachechef-infracookbook

Chef Apache2 with mod php cookbook from Supermarket - getting no such file or directory


looking for a bit of guidance

I'm trying to use the Apache2 cookbook from the Chef Supermarket. I'm creating a virtualhost with the following code:

#Install shop
directory '/var/www/html/shop/' do
  owner 'www-data'
  group 'www-data'
  mode '0755'
  action :create
end

#Configures Apache Site for shop 
web_app "shop" do
   template 'web_app.conf.erb'
   server_name "www.xyz.com.au"
   server_aliases ["www.xyz.com.au"]
   docroot "/var/www/html/shop"
   options '-Indexes'
   cookbook 'apache2'
   allow_override
end

This works fine and i can connect to the http server ok. But when I invoke mod_php:

apache_module "mod_php" do
  enable true
end

I get the following error. Am I doing something wrong enabling PHP with this cookbook?

apache2: Syntax error on line 121 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/mod_php.load: Cannot load /usr/lib/apache2/modules/mod_mod_php.so into server: /usr/lib/apache2/modules/mod_mod_php.so: 
cannot open shared object file: No such file or directory

So i'm not sure what to do on this one, but i thought i'd ask and see if anyone has experience in using this cookbook? https://supermarket.chef.io/cookbooks/apache2#readme

And i'd be interested if anyone is aware of how to pass php config variables into the php.ini. I cant see it from this cookbook?

thanks,

-nat


Solution

  • As the docs for this cookbook indicate, the recipe will attempt to infer various pieces of information based on the name that you pass in. In your case, this is mod_php. This defaults to looking for a filename of mod_mod_php. You can provide a different filename based on what you need, which might look something like this.

    apache_module "php7" do
      filename "libphp7.so"
    end
    

    I would first check what modules are installed in the /usr/lib/apache2/modules/. You may have a different version of php, or need to install the appropriate module first.

    Edit: It's important to also change the first line from apache_module "mod_php" do to apache_module "php7" do. The default name for the Module is inferred as follows:

    identifier - String to identify the module for the LoadModule directive. Not typically needed, defaults to #{name}_module

    Alternatively, you can set the identifier to 'php7' (or whatever the name of the module is).