试图安装php-cgi / Apache / Ubuntu 14.04

我试图在我干净的安装Ubuntu 14.04上使用“Php反向shell”作为学校用途。 我正常地configuration了我的Apache / PHP / MySQL。

我需要得到php函数“pcntl_fork()”的工作。 为了得到它的工作,我需要使用PHP-CGI,但是在6个小时的尝试之后我无法工作。

这是我遵循的最后一个教程: http : //www.binarytides.com/setup-apache-php-cgi-ubuntu/

我有一些麻烦,现在我试图解决它们。 这是我的.conf文件现在的样子:

<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port t$ # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html ScriptAlias /cgi-bin/ /usr/bin/ Action cgi-handler /cgi-bin/php-cgi AddHandler cgi-handler .php <Directory /usr/bin> Require all granted Options FollowSymLinks </Directory> <Directory /var/www/html/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order Allow,Deny Allow from all </Directory> # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, eg #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> 

我得到这个错误:

404-未find

在此服务器上未find请求的URL /cgi-bin/php-cgi/test.php。

有人可以帮助我吗? 先谢谢你。

编辑:我已经尝试过FastCGI,但pcntl_fork()仍然拒绝工作。

简洁版本:

假设请求的URL是http://some.host/test.php ,使用你的apacheconfiguration,一个php-cgi可执行文件应该放在/ usr / bin文件夹中,并且应该由Apache用户执行。 另外,test.php脚本应该出现在/ var / www / html中

长/完整版本:

根据您所报告的configuration,在请求URL http://some.host/test.php&#x65F6; ,Apache将会:

  • 看到这是一个以“.php”结尾的请求,因此,由于AddHandler指令和相关的Action,决定需要启动一个“/ cgi-bin / php-cgi”CGI应用程序;

  • 至于ScriptAlias指令,决定将“/ cgi-bin / php-cgi”CGI应用程序在底层文件系统中映射到“/ usr / bin / php-cgi”完整path名。 因此…

  • Apache将启动“/ usr / bin / php-cgi”(应该存在并且可以被Apache执行),注意添加对要执行的脚本的引用(通过PHP;在你的情况下是“test.php”)定义几个环境variables(PATH_INFO,PATH_TRANSLATED,QUERY_STRING,SCRIPT_NAME等)。

由于上述原因,假设文件系统中存在“/ usr / bin / php-cgi”,并且可以由Apache执行:

  • 下面的环境variables是由Apache定义的:

 SCRIPT_NAME: /cgi-bin/php-cgi PATH_INFO: /test.php PATH_TRANSLATED: /var/www/html/test.php 

  • 在以上环境下,启动/ usr / bin / php-cgi;

  • 一旦启动,php-cgi将search要执行的脚本,如PATH_TRANSLATED环境variables所指定;

  • php-cgi将尝试打开并阅读“/var/www/html/test.php”和…

  • 执行它。

当您的Apache正在search/cgi-bin/php-cgi/test.php时,我怀疑它不识别/ usr / bin文件夹中的php-cgi可执行文件。

我build议仔细检查你的整个configuration,确保:

  • php-cgi是/ usr / bin中的一个可执行文件。 请注意,常见的Ubuntu使用/ usr / bin / php5-cgi二进制文件(添加了“5”);
  • 你的PHP脚本存储在/ var / www / html中
  • 您的url格式为: http : //some.host/test.php
  • 如果遇到更多问题,请检查日志文件,通常位于/var/log/apache/error.log

最后的笔记

强烈地不同意让CGI应用程序可以访问整个/ usr / bin:请考虑将CGI存储在其他地方(/ var / www / cgi-bin或/ usr / lib / cgi-bin或其他),特别是如果你的是“公共”networking服务器。