我在 stackoverflow 上被告知在这里发布这个问题:
向下滚动查看我根据建议所做事情的结果
我正在使用 Vagrant 设置我的第一个项目。我puppetlabs/debian-7.8-64-puppet
为 Debian 服务器选择了以下软件包,因为它与我们用于远程开发服务器的软件包相同。不幸的是,这个 Debian 发行版仅包含 PHP 版本 5.4,因此我尝试安装 dotdeb,以便我可以使用 PHP 5.6.11。
我补充道
deb http://packages.dotdeb.org wheezy all
deb-src http://packages.dotdeb.org wheezy all
deb http://packages.dotdeb.org wheezy-php56 all
deb-src http://packages.dotdeb.org wheezy-php56 all
正如这里提到的https://www.dotdeb.org/instructions/然后/etc/apt/sources.list
运行以下命令
wget http://www.dotdeb.org/dotdeb.gpg
sudo apt-key add dotdeb.gpg
## get package list from sources incl. new set source dotdeb
sudo apt-get update
## Install php, APC, gd and cURL
sudo apt-get install -y php5 php5-apcu php5-gd php5-curl
现在,使用php --version
它时它告诉我我正在使用版本 5.6.11,所以似乎安装成功了。但我遇到的问题是,网络服务器似乎无法解释它,因为它显示了真正的 php 代码。我做错了什么?
这是我的Vagrantfile
,没有评论
config.vm.box = "puppetlabs/debian-7.8-64-puppet"
config.vm.provision :shell, path: "vagrant_ressources/bootstrap.sh"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.synced_folder ".", "/var/www"
这是我的bootstrap.sh
#!/usr/bin/env bash
# Use single quotes instead of double quotes to make it work with special-character passwords
PASSWORD='12345678'
# Update package manager
apt-get update
# Install apache2
sudo apt-get install -y apache2
# Add dotdeb to packages
if [ ! -f /var/log/dotdebconfig ];
then
echo "" | sudo tee --append /etc/apt/sources.list
echo "#dotdeb" | sudo tee --append /etc/apt/sources.list
echo "deb http://packages.dotdeb.org wheezy all" | sudo tee --append /etc/apt/sources.list
echo "deb-src http://packages.dotdeb.org wheezy all" | sudo tee --append /etc/apt/sources.list
echo "deb http://packages.dotdeb.org wheezy-php56 all" | sudo tee --append /etc/apt/sources.list
echo "deb-src http://packages.dotdeb.org wheezy-php56 all" | sudo tee --append /etc/apt/sources.list
wget http://www.dotdeb.org/dotdeb.gpg
sudo apt-key add dotdeb.gpg
## get package list from sources incl. new set source dotdeb
sudo apt-get update
## Install php, APC, gd and cURL
sudo apt-get install -y php5 php5-apcu php5-gd php5-curl
touch /var/log/dotdebconfig
fi
#install mysql and give password to installer
if [ ! -f /var/log/mysqlconfig ];
then
# Set passwords
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $PASSWORD"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $PASSWORD"
# Install MySQL Server and cURL
sudo apt-get -y install mysql-server
sudo apt-get -y install php5-mysql
touch /var/log/mysqlconfig
fi
if [ ! -f /var/log/XXXXXX ];
then
mkdir -p /var/www/htdocs
# Install XXXXXX vhost
sudo a2dissite default
sudo a2enmod rewrite
cd /etc/apache2/sites-available
# copy default vhost conf to sites-available
sudo cp /var/www/vagrant_ressources/XXXXXX.vhost.conf XXXXXX.dev
sudo a2ensite XXXXXX.dev
touch /var/log/XXXXXX
fi
sudo /etc/init.d/apache2 restart
这是我的 XXXXXX.vhost.conf(不知道是否需要)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/htdocs
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/htdocs/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
建议
有人告诉我:“尝试安装 libapache2-mod-php5”
但是,它似乎已经在我的服务器上了,因为我收到以下错误消息:libapache2-mod-php5 is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
答案1
检查 php 是否已添加到 apache 配置中。
至少你必须在你的 apache 配置中有一行类似的内容:
LoadModule php5_module modules/libphp5.so
或者像这样的一行:
SetHandler application/x-httpd-php
如果这是问题的话,您必须添加:
LoadModule php5_module modules/libphp5.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
您还可以调整一些额外的参数,完整文档如何操作在这里:这里
如果一切就绪但仍无法正常工作,请检查是否安装了 php 模块,方法是dpkg -l |grep mod-php
尝试重新安装,然后将其删除purge
并再次安装