简体   繁体   中英

Puppet : How to stop from PHP code printing in browser window

For the sake of learning, I am trying to provision a PHP Web server using Puppet on Vagrant. However, I'm getting PHP code dump on the browser window, instead of execution. I have tried looking for a solution to the problem, but I can't find one here. Any help would be highly appreciated.

This is what I have done so far.

puppetmaster/manifests/site.pp

node /^puppet/ {
  include puppetmaster         
}   

node /^web/ {
  include webserver
  include php
}   

puppetmaster/module/webserver/manifests/init.pp (custom module)

class webserver {
  notify{"provision a web server": }

  package{['git', 'links']:
    ensure => installed,
  }

  include apache        

  file{'/var/www/test':
    ensure => directory,
    owner  => 'www-data',
    group  => 'www-data',
  }

  vcsrepo { "/var/www/test":
    ensure   => present,       
    provider => git,
    source   => 'https://github.com/example/test.git',
    require => File['/var/www/test'],
  }     

  apache::vhost{'git.example.com':
    port    => '80',
    docroot => '/var/www/test',
    require => File['/var/www/test'],
  }

  host{'git.example.com':
    ip => '127.0.0.1',
  }
}

Vagrantfile

VAGRANTFILE_API_VERSION = "2"  

# Assinging static IP
$puppet_ip = "10.1.1.33"       

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.box = "puppetlabs/ubuntu-14.04-32-puppet"
config.vm.network "private_network", ip: "10.1.1.34"

    config.vm.define "web01" do |web|
        web.vm.hostname = "web01"       
        web.vm.network :forwarded_port, host: 1234, guest: 8983
        web.vm.network :forwarded_port, host: 11000, guest: 80
        web.vm.provision "shell", inline: "apt-get update"
        web.vm.provision "shell", inline: "echo '#{$puppet_ip} puppet' >> /etc/hosts"
    end 
end 

apache2.conf (web01.home)

# Security
ServerTokens OS
ServerSignature On
TraceEnable On

ServerName "web01.home"
ServerRoot "/etc/apache2"
PidFile ${APACHE_PID_FILE}
Timeout 120
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 15

User www-data
Group www-data

AccessFileName .htaccess
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

<Directory />
  Options FollowSymLinks
  AllowOverride None
</Directory>


HostnameLookups Off
ErrorLog "/var/log/apache2/error.log"
LogLevel warn
EnableSendfile On

#Listen 80


Include "/etc/apache2/mods-enabled/*.load"
Include "/etc/apache2/mods-enabled/*.conf"
Include "/etc/apache2/ports.conf"

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional "/etc/apache2/conf.d/*.conf"
IncludeOptional "/etc/apache2/sites-enabled/*"

Thanks in adavnce

To fix your issue, you could create a simple php.conf with the limited

LoadModule php5_module modules/libphp5.so
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

and ask puppet to push this file in /etc/apache2/conf.d/ so at least php script should run

The second best option is to look at https://puphpet.com so you get all the provisioning done for you

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