在WIN平台上让你的Apache2.0.45支持PHP
前言 如果你对使用 Apache 缺乏信心。或者你已经在使用 apache 2 但是不能让他和 PHP 一起工作(apache不能解析你的.php脚本)。不要怕,读完本文后,所有的问题都会迎韧而解的。 我将如何使 Apache 和 PHP 共同合作的方法步骤归纳总结了一下。其实,这么比其他人所说的简单得多。我很惊讶为什么在这之前没有人写一个针对这个问题的操作指南,好让每个人都能够更好地理解和使用 Apache 2.0 。凭着个人的兴趣,我分析了 Apache 2.0,特别地,为了获得最新的 Apache服务器,本文所用的,是2.0.45版。 现在,对任何对升级有顾虑的人来说,把服务器升级到 Apache 2.0,比升级微软的IIS要安全得多,并且,还有一大堆有用的工具。在本文章中,我将向大家演示如何配置你的 httpd.conf 文件来使你的服务器能够处理 .php 和.phps 脚本。 接下来我们要一起来配置apache 2,当我们请求 .php 页面时才不会显示源代码或提示下载而不显示我们想看到的页面。 我们要做的工作包括: 下载和安装apache 2.0.45 配置httpd.conf文件 使apache2运行.php和.phps文件 这篇文章是针对Windows 2000/Me/XP用户的。WIN95/98 和 NT4.0 用户如果没有 msi installer 可能需要先从微软下载并安装它。之所以我要强调 Msi 安装程序,是因为本文是针对初次安装 Apache 2 的人的。如果你已经在此之前安装了 Apache,那么你可以直接开始安装了。但也要需要注意本文的一些步骤,特别是当你打算安装PHP 4.3.1的时候。好了,让我们开始吧。 下载apache2 如果你已经安装了apache 1.3,请先别卸载它,先把它停了。在安装了apache2并且PHP脚本工作后,你就可以安全的卸载 apache1.3 了,卸载请一定注意备份好你的 httpd.conf 文件,这样,你就只需改动很少的地方,就可以把它用到新的服务器上了。 对机器上没有安装过apache或安装了其他服务器的人,请先去apache.org下载apache2.0.45(http://nagoya.apache.org/mirror/httpd/binaries/win32/)。确信你下载的.msi文件是5.3M大小。运行下载的.msi文件安装apache。你的服务器就会自动启动。如果你有防火墙,请确保防火墙允许对 Apache 的访问。 你应该注意apache服务监视器(一个绿灯,在任务栏里面),标志着apache在工作。要确保它在工作,只要把鼠标箭头移动到监视器上,它将会告诉你它在工作。你的任务栏应该和下图差不多: 有人也许想知道为什么会显示 “running 1 out of 2 apache services”,那是因为你可能有不止一个版本的apache在工作。大多数人不会这么干,但我的机器上的确有两个 apache 服务器。我的 1.3.27 停止运行了,而 apache 2 则正在运行中。下图是我的机器的情况: 注意,在apache1.3.27 的监视器上有个红灯,而在apache2的上面有个绿灯。第一次安装 apache 的人只能看见一个,因为你只装了一个。 好了。Apache服务器已经基本安装完毕了。现在让我们去下载PHP的源代码,因为我们想让 PHP 和 APACHE 合作,去php.net下载最新版的PHP(目前为PHP 4.3.2 http://www.php.net/downloads.php)。如果你已经安装了PHP,检查sapi文件下是否有php4apache2.dll文件,如果有,你可以跳过下面的步骤。 我们需要下载 php-4.3.2-Win32.zip 和 php-4.3.1-installer.exe 两个文件,许多人要问为什么都要下载。 这样做是让你偷懒,这样就可以不需要建立文件夹,不需要把文件夹名字从 php-4.3.1-Win32 改为PHP。我们先使用installer.exe来安装,它将为你建立PHP文件夹,你可以节省更多的时间。运行installer.exe,根据你的喜好安装PHP,完成后,解压zip文件,然后找到压缩包中的 sapi 文件夹。把该文件夹复制你刚才安装好的PHP目录。(例如:C:PHP)然后我们便可以删除php-4.3.2-win32文件夹,因为现在已经不再需要它了(有点卸磨杀驴的感觉,haha)。把 PHP文件夹中的php4ts.dll复制到你的系统目录:在XP下是WINDOWSSystem32,在2K下是WINNTsystem32。下面我们开始修改conf文件。 让 Apache 解析 php 页面 用你喜欢的文本编辑器打开httpd.conf文件,让我们加几行进去,这样我们Apache 就可以解析 .php 和.phps文件了。我们需要注意conf文件的两个部分,第一部分是 Dynamic Shared Object (DSO) Support list,第二部分是 cgi-bin directory 首先让我们找到如下所示的 DSO 列表. # Dynamic Shared Object (DSO) Support # # to be able to use the functionality of a module which was built as a DSO you # have to place corresponding `LoadModule lines at this location so the # directives contained in it are actually available _before_ they are used. # Statically compiled modules (those listed by `httpd -l) do not need # to be loaded here. # # Example: # LoadModule foo_module modules/mod_foo.so 这还有许多,一直找到最后一行: #LoadModule ssl_module modules/mod_ssl.so 上面一行是该列表的最后一行,按回车产生一个空的行,在这个空行内加入下面这行: LoadModule php4_module c:/php/sapi/php4apache2.dll 在关闭conf文件之前,我们需要再加入两行。找到CGI-BIN目录,为了节省时间,可以这样找:按CTRL+F,(译者注:如果你是在记事本而不是写字板里编辑这个文本,那么,应该用快捷键F3)查找
You are using the web browser.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

To set up a CGI directory in Apache, you need to perform the following steps: Create a CGI directory such as "cgi-bin", and grant Apache write permissions. Add the "ScriptAlias" directive block in the Apache configuration file to map the CGI directory to the "/cgi-bin" URL. Restart Apache.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

The steps to start Apache are as follows: Install Apache (command: sudo apt-get install apache2 or download it from the official website) Start Apache (Linux: sudo systemctl start apache2; Windows: Right-click the "Apache2.4" service and select "Start") Check whether it has been started (Linux: sudo systemctl status apache2; Windows: Check the status of the "Apache2.4" service in the service manager) Enable boot automatically (optional, Linux: sudo systemctl

To delete an extra ServerName directive from Apache, you can take the following steps: Identify and delete the extra ServerName directive. Restart Apache to make the changes take effect. Check the configuration file to verify changes. Test the server to make sure the problem is resolved.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

There are 3 ways to view the version on the Apache server: via the command line (apachectl -v or apache2ctl -v), check the server status page (http://<server IP or domain name>/server-status), or view the Apache configuration file (ServerVersion: Apache/<version number>).
