Tag Archive: apache


隐藏Apache的版本

让我们着眼于2个参数,分别为ServerTokens和ServerSignature,通过控制这2个阀门应该就能起到一些作用,比如我们可以在配置文件中这么写:

ServerTokens ProductOnly
ServerSignature Off

ServerTokens
这个阀门用于控制服务器是否相应来自客户端的请求,向客户端输出服务器系统类型或内置模块等重要的系统信息。

* 在主配置文件中提供全局控制
* 默认阀值为”Full”(ServerTokens Full),所以,如果你的Linux发行版本没有更改过这个阀值的话,所有与你的系统有关的敏感信息都会向全世界公开(恐怖哦~)。比如RHEL会将该阀值更改为”ServerTokens OS”,而Debian依然使用默认的”Full”阀值

以apache-2.0.55为例,阀值可以设定为以下某项(后面为相对应的Banner Header):

ProductOnly >>> Server: Apache
Major >>> Server: Apache/2
Minor >>> Server: Apache/2.0
Minimal >>> Server: Apache/2.0.55
OS >>> Server: Apache/2.0.55 (Debian)
Full (or not specified) default >>> Server: Apache/2.0.55 (Debian) PHP/5.1.2-1
+b1 mod_ssl/2.0.55 OpenSSL/0.9.8b

ServerSignature
这个阀门控制由系统生成的页面(错误信息,mod_proxy ftp directory listing等等)的页脚中如何显示信息。

* 可在全局设置文件中控制,或是通过.htaccess文件控制
* 默认为”off “(ServerSignature Off),有些Linux发行版本可能会打开这个阀门,比如Debian在默认的虚拟主机上默认将这个阀门设置为开放
* 全局阀门的阀值会被虚拟主机或目录单位的配置文件中的阀值所覆盖,所以,必须确保这样的事情不应该发生

可用的阀值为下面所示:

Off (default): 不输出任何页脚信息 (如同Apache1.2以及更旧版本,用于迷惑)
On:输出一行关于版本号以及处于运行中的虚拟主机的ServerName
(2.0.44之后的版本,由ServerTokens负责是否输出版本号)
EMail: 创建一个发送给ServerAdmin的”mailto”

注意*上述关于如何设置2个阀门从而尽量减少敏感信息泄露的方法,并不会使你的服务器真的更安全,如果你现在使用的版本比较旧,请务必尽快将系统升级,降低被蠕虫攻击的风险。

php默认会输出header信息:
Date: Tue, 15 Apr 2008 13:58:46 GMT
Server: Apache/2.2.8
X-Powered-By: PHP/5.2.3
这样一下子php信息就全曝光了。怎样解决呢。

网上一搜中文,还真找不到相关信息。用英文一搜搜到了(下面是原文)

If you have read my previous tip, “Hide apache software version“, you have seen how you can configure apache to provide only a minimal amount of information about the installed software versions in its banner. But if you are using the PHP module in your web server (as most of us are), then there is one additional step that need to be completed, and this is what I will show you in this tip.

After implementing the apache directives ServerTokens and ServerSignature as shown in “Hide apache software version“, we test its functionality against a regular html file and we get the following response:

HEAD http://remote_server.com/index.html
200 OK
Connection: close
Date: Fri, 16 Jun 2006 01:13:23 GMT
Server: Apache
Content-Type: text/html; charset=UTF-8
Client-Date: Fri, 16 Jun 2006 21:42:53 GMT
Client-Peer: 192.168.0.102:80
Client-Response-Num: 1

This looks good. But if we do the same thing against an URL that is a PHP file:

HEAD http://remote_server.com/index.php 200 OK Connection: close Date: Fri, 16 Jun 2006 01:16:30 GMT Server: Apache Content-Type: text/html; charset=UTF-8 Client-Date: Fri, 16 Jun 2006 21:48:13 GMT Client-Peer: 192.168.0.102:80 Client-Response-Num: 1 X-Powered-By: PHP/5.1.2-1+b1

Ups… As we can see PHP adds its own banner:

X-Powered-By: PHP/5.1.2-1+b1…

Let’s see how we can disable it. In order to prevent PHP from exposing the fact that it is installed on the server, by adding its signature to the web server header we need to locate in php.ini the variable expose_php and turn it off.

By default expose_php is set to On.

In your php.ini (based on your Linux distribution this can be found in various places, like /etc/php.ini, /etc/php5/apache2/php.ini, etc.) locate the line containing “expose_php On” and set it to Off:

expose_php = Off

After making this change PHP will no longer add it’s signature to the web server header. Doing this, will not make your server more secure… it will just prevent remote hosts to easily see that you have PHP installed on the system and what version you are running.

结果简单的让人吃惊,只是需要修改php.ini 的 expose_php 把默认的 On改成 Off 就行了。

解决Skype默认占用80/443端口

刚才我想调试一个PHP脚本,就启动我的Apache服务器,居然提示本地端口80已经被占用不能绑定(我的Apache用的是80端口),然后我就开始查是什么占了80端口。

解决方法:

  1. 工具-选项-连接
  2. 把“将80端口与443端口作为接入连接”前面打上钩”这个选项去掉。

PS:Web迅雷也默认占用80端口

CentOS Apache配置详解

要想在linux上实现网页服务器(www)需要Apache这个服务器软件,不过Apache仅能提供最基本的静态网站数据而已,想要实现动态网站的话,最好还是要PHP与MySQL的支持,所以下面我们将会以LAMP(linux+Apache+MySQL+PHP)作为安装与设置的介绍。

LAMP所需软件与其结构
httpd mysql mysql-Server php php-devel php-mysql
可以用rpm包安装,或者直接用yum安装
#yum install httpd mysql-server php php-devel php-mysql
先来了解一下apache 2.0这个版本的相关结构,这样才能知道如何处理我们的网页数据
/etc/httpd/conf/httpd.conf:最主要的配置文件,不过很多其他的distribution都将这个文件拆成数个小文件,分别管理不同的参数。但是最主要配置文件还是以这个文件名为主。
/etc/httpd/conf.d/*.conf:这个事CentOS的特色之一,如果你不想修改原始配置文件httpd.conf的话,那么可以将你自己的额外参数独立出来,而启动apache时,这个文件就会被读入到主要配置文件。
/usr/lib/httpd/modules:apache支持很多的模块,所以您想要使用的模块默认都放置在此目录
/var/www/html:这里是CentOS默认的“首页”所在目录。
/var/www/error:如果因为主机设置错误,或者是浏览器端要求的数据错误,在浏览器上出现的错误信息就已这个目录的默认信息为主。
/var/www/icons:提供apache的一些小图标
/var/www/cgi-bin :默认给一些可执行的CGI程序放置的目录
/var/log/httpd:默认apache的日志文件都放在这里,对于流量大的网站来说,这个目录要很小心,因为这个文件很容易变的很大,您需要足够的空间哦
/usr/sbin/apachectl:这是Apache的主要执行文件,这个执行文件其实是shell script,它可以主动检测系统上的一些设置值,好让您启动Apache时更简单
/usr/sbin/httpd:这是主要的apache的二进制文件
/usr/bin/htpasswd:当您想登陆某些网页时,需要输入账号与密码。那么Apache本身就提供一个最基本的密码保护方式。该密码的产生就是通过这个命令实现的

至于MySQL方面,您需要知道的几个重要目录与文件有以下几个:
/etc/my.cnf:这是Mysql的配置文件,包括您想要进行mysql数据库的最佳化,或者是正对mysql进行一些额外的参数指定,都可以在这个文件里实现
/usr/lib/mysql:这个目录是MySQL数据库放置的位置,当启动任何MySQL的服务器时,请务必记得在备份时,将此目录完整的备份下来。

另外,在PHP方面,应该了解以下几个文件。
/usr/lib/httpd/modules/libphp4.so:PHP提供给apache使用的模块,这个关系我们能否在apache网页上面设计php程序语言的最重要文件
/etc/httpd/conf.d/php.conf:你要不要手动将该模块写入Httpd.conf中呢?不需要,因为系统已经主动将php设置参数写入到这个文件中了,而这个文件会在apache重新启动时被读入。
/etc/php.ini:这是PHP的主要配置文件,包括PHP能不能允许用户上传文件,能不能允许某些低安全性的标志等,都在这个配置文件中设置。
/etc/php.d/mysql.ini /usr/lib/php4/mysql.so:PHP能否可以支持MySQL接口就看这两个文件了。这两个文件是由php-mysql软件提供的
/usr/bin/phpize /usr/include/php:如果您以后想要安装类似PHP加速器可以让浏览速度加快的话,那么这个文件与目录就需要存在,否则加速器软件没法用。

httpd.conf的基本设置
首先,你需要在/etc/hosts内需要有个一个完整的主机名,否则在重启apache服务时,会提示找不到完整的主机名。
httpd.conf的基本设置是这样的:
<设置项目>
      次设置项目内的相关参数
      。。。。
</设置项目>
例如,你想要针对首页/var/www/html提供额外的功能,那么可以进行如下设置:
<Directory “/var/www/html”>
   Options Indexes
   ……
</Directory>

针对主机环境的设置项目
#vi /etc/httpd/conf/httpd.conf
ServerTokens OS
# 这个项目在告诉客户端WWW服务器的版本和操作系统,不需要改编它
#如果你不想告诉太多的主机信息,将这个项目的OS改成Minor

ServerRoot “/etc/httpd”
#这个是设置文件的最顶层目录,通常使用绝对路径,下面某些数据设置使用相对路径时
#就是与这个目录设置值有关的下层目录,不需要更改它
ServerRoot
设定Apache 安装的绝对路径
TimeOut
设定 服务器接收至完成的最长等待时间
KeepAlive
设定服务器是否开启连续请求功能,真实服务器一般都要开启
Port
设定http服务的默认端口。
User/Group
设定 服务器程序的执行者与属组,这个一般是apache

下面我们就针对Apache做几个实验
1:我们测试把默认网站目录改到root家目录下
新建/root/website目录
#mkdir -p /root/website
#echo “website page” >> /root/website/index.html
#vi /etc/httpd/conf/httpd.conf
找到 DocumentRoot “/var/www/html” 这一段   //apache的根目录
把/var/www/html 这个目录改到 /root/website
在找到 <Directory “/var/www/html”> //定义apache /var/www/html这个区域
把 /var/www/html改成/root/website
这样我们就把apahce的默认路径改掉了
然后重启服务
#service httpd restart  
//这里在你重启服务的时候,可能会报错,说找不到目录,这个主要是由于selinux导致的
那怎么解决呢?有2个办法,关掉selinux  
#setenforce 0
或者更改/root/website这个文件的selinux属性,让它匹配httpd这个服务器的要求
怎么改?我们可以复制/var/www/html这个目录的selinux属性
#chcon -R –reference /var/www/html /root/website
然后在重启服务,之后你就看到它没有报错了
不过你去访问localhost的时候,会发现访问拒绝 这是为什么呢?主要是因为你的/root的权限是750,ahache这个用户没有权限访问,你需要更改掉权限,可以这样改
#chmod -R 755 /root
然后去访问 发现正常了

2:基于名称的虚拟主机
需要两个域名解析到你的服务器,对应关系是
/var/www/server             server.example.com
/var/www/client                client.example.com
当访问这两个域名时,可以分别显示出不同文件里面主页的内容
#echo “server page” >> /var/www/server/index.html
#echo “client page” >> /var/www/client/index.html
然后我们编辑一个配置文件
#vi /etc/httpd/conf.d/virtual.conf //记住conf.d里面的内容也是apache的配置文件
添加如下内容:
NameVirtualHost 192.168.76.133:80

<VirtualHost 192.168.76.133:80>
ServerName service.example.com
DocumentRoot /var/www/server
</VirtualHost>

<VirtualHost 192.168.76.133:80>
ServerName client.example.com
DocumentRoot /var/www/client
</VirtualHost>
#service httpd restart
这样基于名称的虚拟主机就配置好了
如果你没有DNS你可以再你的机器上hosts文件里加记录 linux在/etc/hosts这个文件 windows在C:\windows\system32\drivers\etc\hosts文件
加上这两行
192.168.76.133    server.example.com
192.168.76.133    client.example.com
这样你在去测试,就会发现访问不同的域名显示不同的内容了 这样基于名称的虚拟主机就配置好了!

3:基于IP地址的虚拟主机
先添加一个临时网卡
#ifconfig eth0:0 192.168.76.132 //临时使用,重启后就会消失
然后便捷virtual.conf文件
#vi /etc/httpd/conf.d/virtual.conf
把内容修改为
#NameVirtualHost 192.168.76.133:80

<VirtualHost 192.168.76.133:80>
ServerName service.example.com
DocumentRoot /var/www/server
</VirtualHost>

<VirtualHost 192.168.76.132:80>
ServerName client.example.com
DocumentRoot /var/www/client
</VirtualHost>
让后你在用ip访问,发现也能显示不同的内容,或者你编辑hosts文件,用域名访问也没问题
这样基于IP地址的虚拟主机也成功了!

4:别名
在/etc/httpd/conf/httpd.conf里加入
Alias /test “/root/website/”    // 别名 这样你用192.168.76.133/test访问 也会显示192.168.76.133的页面
这个地方需要注意的就是/test 还是/test/ 这个是用区别的 你用/test 那么你访问的时候只能用192.168.76.133/test访问   如果你用/test/ 那么192.168.76.133/test/访问,而/test将不会放你访问
忘了这里你的先把/etc/httpd/conf.d目录里面刚刚设置的虚拟目录注释掉 不然没法访问,是因为做了虚拟目录,而httpd.conf里面的设置就无法访问 当然可以用localhost来访问,其他的访问都不行

5:实现网页的资源下载
首先添加别名
#vi /etc/httpd/conf/httpd.conf
在Alias /test “/root/website/” 后面加入
Alias /down “/var/ftp/pub”
让后对/var/ftp/pub区域设置参数
<Directory “/var/ftp/pub”>
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
在Options 加入 MultiViews   //没有index时自动列出目录文档
然后重启服务,这样http://192.168.76.133/down/里面就可以列出/var/ftp/pub里面的文件了,试着点一个另存为,是否可以下载? 呵呵 成功!

6:.htpasswd的实现
#vi /etc/httpd/conf/httpd.conf
我们针对刚刚做的/var/ftp/pub来做
加入如下信息
Alias /down “/var/ftp/pub/”
<Directory “/var/ftp/pub”>
    Options Indexes MultiViews
    AllowOverride AuthConfig
    Order allow,deny
    Allow from all
</Directory>
<Directory “/var/ftp/pub”>
AuthType Basic
AuthName “this is test”
AuthUserFile /etc/httpd/htpasswd
Require User test
</Directory>
然后重启httpd服务,
让后生成.htpasswd用户密码
htpasswd -c /etc/httpd/htpasswd test
让后去访问192.168.76.133/down会需要密码
这样就成功了

How to Install and Configure PHP 5 to Run with Apache on Windows

How to Install and Configure PHP 5 to Run with Apache on Windows

by Christopher Heng, thesitewizard.com

Many web developers want to run Apache and PHP on their own computer since it allows them to easily test their scripts and programs before they put them “live” on the Internet. This article gives a step by step guide on how you can install and configure PHP5 to work together with the Apache HTTP Server on Windows. The procedure has been tested to work on both Windows XP and Vista.

If you have not already installed Apache on your machine, check out one of the guides listed below. This “How To” guide assumes that you have already completed installing Apache.

Note: those planning to install PHP 4 on Apache 1.x should read my article How to Install and Configure PHP4 to Run with Apache on Windows instead.

Steps to Setting Up PHP 5

  1. Download PHP 5

    Before you begin, get a copy of PHP 5 from the PHP download page. In particular, download the VC6 thread-safe zip package from the “Windows Binaries” section — that is, don’t get the installer. For example, select the package labelled “PHP 5.2.5 zip package” if 5.2.5 is the current version.

    [Update: note that I have not tested the procedure below with any of the PHP 5.3 versions, only with 5.2.5, which was the latest version at the time I originally wrote this. In theory, the procedure should work with later 5.2 versions as well. I'm not sure about 5.3 though. A version jump from 5.2 to 5.3 usually means bigger changes than simple bug fixes. If you want to be sure the procedure below will work, just get the latest of the 5.2 series.]

  2. Install PHP 5

    Create a folder on your hard disk for PHP. I suggest “c:php” although you can use other names if you wish. Personally though, I prefer to avoid names with spaces in it, like “c:Program Filesphp” to avoid potential problems with programs that cannot handle such things. I will assume that you used c:php in this tutorial.

    Extract all the files from the zip package into that folder. To do that simply double-click the zip file to open it, and drag all the files and folders to c:php.

  3. Upgraders: Remove the Old PHP.INI File from Your Windows Directory

    If you are upgrading to PHP 5 from an older version, go to your windows directory, typically c:windows, and delete any php.ini file that you have previously placed there.

  4. Configuring PHP

    Go to the c:php folder and make a copy of the file “php.ini-recommended”. Name the new file “php.ini”. That is, you should now have a file “c:phpphp.ini”, identical in content with “c:phpphp.ini-recommended”.

    Note: if you are using Apache 1, you should either move the php.ini file to your windows directory, “C:Windows” on most systems, or configure your PATH environment variable to include “c:php”. If you don’t know how to do the latter, just move the php.ini file to the “c:windows” folder. You do not have to do this if you are using Apache 2, since we will include a directive later in the Apache 2 configuration file to specify the location of the php.ini file.

    Use an ASCII text editor (such as Notepad, which can be found in the Accessories folder of your Start menu) to open “php.ini”. You may need to make the following changes to the file, depending on your requirements:

    1. Enable Short Open Tags

      Search for the line that reads:

      short_open_tag = Off

      If short_open_tag is set to “off”, tags like “commercial web hosts that support PHP have no issues with your scripts using “

      short_open_tag = On
    2. Magic Quotes

      By default, input data is not escaped with backslashes. That is, if your visitors enter an inverted comma (single quote) into your web form, the script will receive that unadorned inverted comma (single quote). This is for the most part desirable unless you special requirements. If you want your input data to have the backslash (“”) prefix, such as, for example, to mimic your web host’s settings, search for the following:

      magic_quotes_gpc = Off

      and replace it with:

      magic_quotes_gpc = On

      Do not do this unless your web host has this setting as well. Even with the setting of “Off”, you can still use the addslashes() function in PHP to add the slashes for the specific pieces of data that need them.

    3. Register Globals

      A number of older scripts assume that all data sent by a form will automatically have a PHP variable of the same name. For example, if your form has an input field with a name of “something”, older PHP scripts assume that the PHP processor will automatically create a variable called $something that contains the value set in that field.

      If you are running such scripts, you will need to look for the following field:

      register_globals = Off

      and change it to the following:

      register_globals = On

      WARNING: Do NOT do this unless you have third party scripts that need it. When writing new scripts, it’s best to always code with the assumption that the register_globals item is set to “Off”.

    4. Display Errors

      On a “live” website, you typically want errors in your script to be silently logged to a PHP error file. On your own local machine, however, while you are testing and debugging a PHP script, it is probably more convenient to have error messages sent to the browser window when they appear. This way, you won’t miss errors if you forget to check the error log file.

      If you want PHP to display error messages in your browser window, look for the following:

      display_errors = Off

      And change it to:

      display_errors = On

      This value should always be set to “Off” for a “live” website.

    5. Session Path

      If your script uses sessions, look for the following line:

      ;session.save_path = “/tmp”

      The session.save_path sets the folder where PHP saves its session files. Since “/tmp” does not exist on Windows, you will need to set it to a directory that does. One way is to create a folder called (say) “c:tmp” (the way you created c:php earlier), and point this setting to that folder. If you do that, change the line to the following:

      session.save_path = “c:tmp”

      Notice that in addition to changing the path, I also removed the semi-colon (“;”) prefix from the line.

      Alternatively, you can find out the current TEMP folder on your computer and use that. Or create a “tmp” folder in your PHP directory, like “c:phptmp” and set the configuration file accordingly. The possibilities are endless. If you can’t decide, just create “c:tmp” and do as I said above.

    6. SMTP Server

      If your script uses the mail() function, and you want the function to successfully send mail on your local machine, look for the following section:

      [mail function]
      ; For Win32 only.
      SMTP = localhost
      smtp_port = 25

      ; For Win32 only.
      ;sendmail_from = me@example.com

      Change it to point to your SMTP server and email account. For example, if your SMTP server is “mail.example.com” and your email address is “youremail@example.com”, change the code to:

      [mail function]
      SMTP = mail.example.com
      smtp_port = 25
      sendmail_from = youremail@example.com

      Note that after you do this, when your script tries to use the mail() function, you will need to be connected to your ISP for the function to succeed. If you do not modify the above lines and attempt to use mail() in your script, the function will return a fail code, and display (or log) the error (depending on how you configure php.ini to handle errors).

      (Note that in Apache 1.x, the smtp_port line may not be present. If so, don’t include it.)

How to Configure Apache for PHP 5

There are two ways to set up Apache to use PHP: the first is to configure it to load the PHP interpreter as an Apache module. The second is to configure it to run the interpreter as a CGI binary. I will supply information for how you can accomplish both, but you should only implement one of these methods. Choose the module method if your web host also installed PHP as an Apache module, and use the CGI method if they have implemented it to run as a CGI binary.

  1. Running PHP 5 as an Apache Module

    To configure Apache to load PHP as a module to parse your PHP scripts, use an ASCII text editor to open the Apache configuration file, “httpd.conf”. If you use Apache 1.x, the file is found in “c:Program FilesApache GroupApacheconf”. Apache 2.0.x users can find it in “C:Program FilesApache GroupApache2conf” while Apache 2.2.x users can find it in “C:Program FilesApache Software FoundationApache2.2conf”. Basically, it’s in the “conf” folder of wherever you installed Apache.

    Search for the section of the file that has a series of “LoadModule” statements. Statements prefixed by the hash “#” sign are regarded as having been commented out.

    If you are using Apache 1.x, add the following line after all the LoadModule statements:

    LoadModule php5_module “c:/php/php5apache.dll”

    If you are using Apache 2.0.x, add the following line after all the LoadModule statements:

    LoadModule php5_module “c:/php/php5apache2.dll”

    If you are using Apache 2.2.x, add the following line instead:

    LoadModule php5_module “c:/php/php5apache2_2.dll”

    Note carefully the use of the forward slash character (“/”) instead of the traditional Windows backslash (“”). This is not a typographical error.

    If you are using Apache 1.x, search for the series of “AddModule” statements, and add the following line after all of them. You do not have to do this in any of the Apache 2 series of web servers.

    AddModule mod_php5.c

    Next, search for “AddType” in the file, and add the following line after the last “AddType” statement. Do this no matter which version of Apache you are using. For Apache 2.2.x, you can find the “AddType” lines in the section. Add the line just before the closing for that section.

    AddType application/x-httpd-php .php

    If you need to support other file types, like “.phtml”, simply add them to the list, like this:

    AddType application/x-httpd-php .phtml

    Finally, for those using one of the Apache 2 versions, you will need to indicate the location of your PHP ini file. Add the following line to the end of your httpd.conf file.

    PHPIniDir “c:/php”

    Of course if you used a different directory for your PHP installation, you will need to change “c:/php” to that path. Remember to use the forward slash (“/”) here again.

    If you are using Apache 1, you will have already placed your php.ini file in either the Windows directory or somewhere in your PATH, so PHP should be able to find it by itself. You can of course do the same if you are using Apache 2, but I find modifying the Apache configuration file a better solution than cluttering your c:windows directory or your PATH variable.

  2. Running PHP 5 as a CGI Binary

    If you have configured PHP 5 to run as an Apache module, skip forward to the next section. This section is for those who want to configure PHP to run as a CGI binary.

    The procedure is the same whether you are using the Apache 1.x series or one of the 2.x series.

    Search for the portion of your Apache configuration file which has the ScriptAlias section. Add the line from the box below immediately after the ScriptAlias line for “cgi-bin”. If you use Apache 2.2.x, make sure that the line goes before the closing for that section.

    Note that if you installed PHP elsewhere, such as “c:Program Filesphp”, you should substitute the appropriate path in place of “c:/php/” (for example, “c:/Program Files/php/”). Observe carefully that I used forward slashes (“/”) instead of the usual Windows backslashes (“”) below. You will need to do the same.

    ScriptAlias /php/ “c:/php/”

    Apache needs to be configured for the PHP MIME type. Search for the “AddType” comment block explaining its use, and add the AddType line in the box below after it. For Apache 2.2.x, you can find the AddType lines in the section. Add the following line just before the closing for that section.

    AddType application/x-httpd-php .php

    As in the case of running PHP as an Apache module, you can add whatever extensions you want Apache to recognise as PHP scripts, such as:

    AddType application/x-httpd-php .phtml

    Next, you will need to tell the server to execute the PHP executable each time it encounters a PHP script. Add the following somewhere in the file, such as after the comment block explaining “Action”. If you use Apache 2.2.x, you can simply add it immediately after your “AddType” statement above; there’s no “Action” comment block in Apache 2.2.x.

    Action application/x-httpd-php “/php/php-cgi.exe”

    Note: the “/php/” portion will be recognised as a ScriptAlias, a sort of macro which will be expanded to “c:/php/” (or “c:/Program Files/php/” if you installed PHP there) by Apache. In other words, don’t put “c:/php/php.exe” or “c:/Program Files/php/php.exe” in that directive, put “/php/php-cgi.exe”.

    If you are using Apache 2.2.x, look for the following section in the httpd.conf file:


    AllowOverride None
    Options None
    Order allow,deny
    Allow from all

    Add the following lines immediately after the section you just found.


    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
  3. Configuring the Default Index Page

    This section applies to all users, whether you are using PHP as a module or as a CGI binary.

    If you create a file index.php, and want Apache to load it as the directory index page for your website, you will have to add another line to the “httpd.conf” file. To do this, look for the line in the file that begins with “DirectoryIndex” and add “index.php” to the list of files on that line. For example, if the line used to be:

    DirectoryIndex index.html

    change it to:

    DirectoryIndex index.php index.html

    The next time you access your web server with just a directory name, like “localhost” or “localhost/directory/”, Apache will send whatever your index.php script outputs, or if index.php is not available, the contents of index.html.

Restart the Apache Web Server

Restart your Apache server. This is needed because Apache needs to read the new configuration directives for PHP that you have placed into the httpd.conf file. The Apache 2.2 server can be restarted by doubleclicking the Apache Service Monitor system tray icon, and when the window appears, clicking the “Restart” button.

Testing Your PHP Installation

Create a PHP file with the following line:

Save the file as “test.php” or any other name that you fancy, but with the “.php” extension, into your Apache htdocs directory. If you are using Notepad, remember to save as “test.php” with the quotes, or the software will add a “.txt” extension behind your back.

Open your browser and access the file by typing “localhost/test.php” into your browser’s address bar. Do not open the file directly on the hard disk – you’ll only see the words you typed in earlier. You need to use the above URL so that the browser will try to access your Apache web server, which in turn runs PHP to interpret your script.

If all goes well, you should see a pageful of information about your PHP setup. Congratulations – you have successfully installed PHP and configured Apache to work with it. You can upload this same file, test.php, to your web host and run it there to see how your web host has set up his PHP, so that you can mimic it on your own machine.

If for some reason it does not work, check to see whether your PHP setup or your Apache setup is causing the problem. To do this, open a Command Prompt window (found in the “Accessories” folder of your “Start” menu) and run php-cgi.exe on test.php with a command line like “c:phpphp-cgi test.php” (without the quotes).

If invoking PHP from the command line causes a large HTML file with all the PHP configuration information to be displayed, then your PHP set up is fine. The problem probably lies with your Apache configuration. Make sure that you have restarted the Apache server after making configuration changes. Verify that you have configured Apache correctly by looking over, again, the instructions on this page and the steps given in How to Install and Configure Apache 1.x for Windows (for Apache 1.x users) or How to Install and Configure Apache 2 on Windows (for Apache 2.x users).

Learning PHP

The complete PHP reference manual can be obtained from the php website. You can refer to it online or download the entire set of HTML files for reference offline. As its name implies, it is a reference manual only. For tutorials, check out the PHP tutorials at thesitewizard.com. If you are new to writing PHP scripts, the following chapters may interest you:

Have fun!

FollowSymLinks is a directive in your web server configuration that tells your web server to follow so called symbolic links. As one would expect, FollowSymLinks is an acronym for Follow Symbolic Links. FollowSymLinks is a very important setting that plays a role in your website security.

In the following text, we will explain general knowledge about FollowSymLinks with some emphasis and how it relates to the Apache

Order allow,deny is a setting in your Apache web server configuration that is used to restrict access to certain

Apache Conf – What is IndexIgnore?

IndexIgnore is an important security setting in your Apache configuration files which commands what gets displayed to the visitor coming to your website. IndexIgnore is a simple setting which is often forgotten or neglected. Not having IndexIgnore set properly can have negative consequences and compromise your website server security.

What is IndexIgnore?

When

Using LDAP for Apache Authentication

This method authenticates using Apache 2.0/2.2 and the LDAP authentication modules on Linux (supplied by default with most Linux distros) and an LDAP server. LDAP can be used to authenticate user accounts on Linux and other computer systems as well as web site logins.
Also see YoLinux TUTORIAL: LDAP system authentication.

Try this out with your Apache server authenticating to our open LDAP server using our Three Stooges example.

Step 1: Edit the configuration file
Now you need to edit the current file path with the file path to your site. Make sure the path goes all the way to the root folder of your site, not just the enclosing folder. Here’s an example of a virtual directory for a site called examplesite and saved on the Desktop. The text in red shows what was changed to create this new virtual directory.

# Alias for examplesite
Alias /examplesite "/Users/lgrillo/Desktop/examplesite_folder/examplesite"
/Users/lgrillo/Desktop/examplesite_folder/examplesite">
       Options Indexes FollowSymLinks MultiViews ExecCGI
       AllowOverride All
       Order allow,deny
       Allow from all

Now let’s dissect this to learn what we’ve just done:

--------------| line 1 |----------------
# Alias for examplesite

This line is just a comment and is optional. It’s a good idea to keep it because it will help you to recognize the various virtual directory entries quickly and easily.

--------------| line 2 |----------------
Alias /examplesite "/Users/lgrillo/Desktop/examplesite_folder/examplesite"

The part in blue is the name of the virtual directory and you can think of it as an alias. Choosing a name for the virtual directory that matches the name of the site you are working on is a good idea but not technically required.

The part in red is the path to your site’s root folder. If any of the folders along the way contain spaces we strongly recommend you go back and change them to underscores. If for some reason you really must use spaces, you must translate them to %20 in line 2 or it will not work. The easiest way to make sure this path is correct is to open the Terminal application inside the Applications/Utilities folder and then drag and drop the root folder of your site into the terminal window. This will give you the full path which you can then copy and paste into the httpd.conf file using TextEdit.

--------------| line 3 |----------------
/Users/lgrillo/Desktop/examplesite_folder/examplesite">

Again, replace the part in red with the path to your site’s root folder. This should be the same as in line 2.

--------------| the rest |----------------
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all

Unless you need to set access in a specific way you can leave the rest of this as is. If you want more details on the exact meaning of these options, the Apache documentation is included as part of the GoLive Preconfigured Servers package. See http://localhost:8200/manual/mod/directives.html for a list of all of the directives and their meanings.

Save the file, close it, and quit TextEdit when you are done making the necessary edits.

Step 2: Restarting the Webserver
You must restart the Apache web server before it will recognize the new virtual directory. Restart the server by double-clicking the Restart Webserver alias on your Desktop.

Powered by WordPress | Theme: Motion by 85ideas.