如何停止在浏览器窗口中打印PHP代码


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

为了学习,我试图在Vagrant上使用Puppet提供一个PHP Web服务器。然而,我得到的PHP代码转储在浏览器窗口,而不是执行。我试图寻找解决这个问题的办法,但在这里找不到。如有任何帮助,我将不胜感激。

这是我到目前为止所做的。

傀儡师/表现/site.pp

node /^puppet/ {
  include puppetmaster         
}   
node /^web/ {
  include webserver
  include php
}   

傀儡师/模块/网络服务器/表现/init。pp(自定义模块)

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/*"

提前致谢

要解决这个问题,您可以创建一个简单的php.conf,其中包含有限的

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

并要求puppet将此文件推入/etc/apache2/conf.d/,这样至少php脚本应该运行

第二个最佳选择是查看https://puphpet.com,以便为您完成所有配置