简体   繁体   中英

How to connect Nginx and PHP via Puppet (on Vagrant)?

I'm setting up a puppet file for Vagrant to use to provision a LEMP stack and so far, I've been able to install everything I need via this:

exec { "apt-get update":
command => "/usr/bin/apt-get update",
}

package { "acl":
    ensure => "present",
    require => Exec ["apt-get update"],
}

class nginx{
  package { "nginx":
    ensure => present,
    require => Exec ["apt-get update"],
  }
    service { "nginx":
        ensure  => "running",
        require => Package["nginx"],
    }

    file { "/var/www":
        ensure  => "link",
        target  => "/vagrant/web",
        require => Package["nginx"],
        notify  => Service["nginx"],
        force => true,
    }
}

class php {
    package { "php5-cli": ensure => present }
    package { "php5-dev": ensure => present }
    package { "php5-mysql": ensure => present }
    package { "php-pear": ensure => present }
    package { "php5-common": ensure => present}
    package { "php5-fpm": ensure => present}
    package { "php5-cgi": ensure => present}
    package { "php-apc": ensure => present}
    exec { "pear upgrade":
        command => "/usr/bin/pear upgrade",
require => Package["php-pear"],
    }
}
class mysql {
  package { "mysql-server":
    require => Exec["apt-get update"],
    ensure => present,
  }
  service { "mysql":
    enable => true,
    ensure => running,
    require => Package["mysql-server"],
  }
  exec { "Set MySQL server root password":
        require => Package["mysql-server"],
        unless => "/usr/bin/mysqladmin -uroot -proot status",
        command => "/usr/bin/mysqladmin -uroot password root",
  }
}  

include nginx
include php
include mysql

I've Vagrant setup correctly, I was using a LAMP stack script for that and it worked flawlessly; however, substituting Nginx for Apache and php-fpm for php5 caused a break. Whenever I try to load up my site, I get a "Welcome to nginx!". If I specify a specific path to an image (or any other static file), the image loads up. If I specify a specific path to a PHP file, the PHP file gets downloaded instead of executing.

I'm using Ubuntu 12.04 64-bit.

I'm thinking that the socket is not correctly setup from the Nginx side but I'm not entirely sure how I can set it up via a puppet manifests file for portability.

Ideas?

You need puppet to replace the /etc/nginx/sites-available/default file with a config that has the php socket stuff uncommented.

Try uncommenting the location ~ \\.php$ block and restart nginx to see if things work... if so then getting puppet to replace that file with your config should get it working for you.

There are quite a few more robust nginx puppet scripts out there that you might want to take a look at as well... you should probably being doing this as a vhost for example... and beware that there are some security issues to look out for if using this in production.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM