Installing php 5 3. Installation on older versions of Windows OS. Install PHP as a handler under Apache

Apache for Windows XP

Currently, all current versions of Apache run on Windows 7 SP1, Vista SP2, 8 / 8.1, 10, Server 2008 SP2 / R2 SP1, Server 2012 / R2, Server 2016.

Thus, it is currently not possible to run modern versions of Apache on Windows XP. Also Apache won't work on Windows Server 2003.

On Windows XP, only Apache 2.2 can be run. Moreover, your Windows XP system must have Service Pack 3.

Before proceeding, I recommend that you upgrade to a newer version of Windows - starting with 7 you can install any modern version of Apache and PHP. Older versions of Apache and PHP may contain bugs. If you plan to use local web server for learning web application administration and PHP programming, Windows XP is not the best platform - here you will be dealing with long outdated software.

If I haven't convinced you then follow this step by step instructions to run Apache on Windows XP.

Creating a web server structure

Let's create the directory structure of our server. The main idea is to share executable files and site files with databases. This is convenient for server maintenance, including backups.

At the root of the disk C: \\ create directory Server... In this directory create 2 subdirectories: bin (for executable files) and data.

Go to directory data and create subfolders there DB (for databases) and htdocs (for sites).

How to install Apache on Windows XP

Please select Custom installation:

Change the installation folder to C: \\ Server \\ bin \\ Apache2.2 \\:

After the installation is complete open http: // localhost /:

Go to directory C: \\ Server \\ bin \\ Apache2.2 \\ conf \\ and open the file httpd.conf any text editor.

In it, we need to replace a number of lines.

#ServerName localhost: 80

ServerName localhost: 80

DocumentRoot "C: /Server/bin/Apache2.2/htdocs"

DocumentRoot "C: / Server / data / htdocs /"

DirectoryIndex index.html

DirectoryIndex index.php index.html index.htm

# AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None

# AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride All

#LoadModule rewrite_module modules / mod_rewrite.so

LoadModule rewrite_module modules / mod_rewrite.so

We save and close the file. That's it, Apache configuration is complete! Restart the web server or restart your computer for the changes to take effect.

Place your sites in the folder C: \\ Server \\ data \\ htdocs \\.

How to install PHP on Windows XP

In Windows XP with this version of Apache, only PHP 5.4 will work, the latest version is PHP 5.4.9, and it is this file that we download from the archive.

Download and install the Microsoft Visual C ++ 2008 Redistributable Package (x86) file for this version of PHP.

In folder C: \\ Server \\ bin \\ create another folder named PHP, unpack the contents of the downloaded file into it php-5.4.9-Win32-VC9-x86.zip.

In file C: \\ Server \\ bin \\ Apache2.2 \\ conf \\ httpd.conf add lines at the very end

PHPIniDir "C: / Server / bin / PHP" AddHandler application / x-httpd-php .php LoadModule php5_module "C: /Server/bin/PHP/php5apache2_2.dll"

Now in the folder C: \\ Server \\ bin \\ PHP \\ find the file php.ini-development and rename it to php.ini.

Open this file php.ini in any text editor, looking for the line

; extension_dir \u003d "ext"

and replace it with

Extension_dir \u003d "C: \\ Server \\ bin \\ PHP \\ ext \\"

Now find the line group:

; extension \u003d php_bz2.dll; extension \u003d php_curl.dll; extension \u003d php_fileinfo.dll; extension \u003d php_gd2.dll; extension \u003d php_gettext.dll; extension \u003d php_gmp.dll; extension \u003d php_intl.dll; extension \u003d php_imap.dll; extension \u003d php_interbase.dll; extension \u003d php_ldap.dll; extension \u003d php_mbstring.dll; extension \u003d php_exif.dll; Must be after mbstring as it depends on it; extension \u003d php_mysql.dll; extension \u003d php_mysqli.dll; extension \u003d php_oci8.dll; Use with Oracle 10gR2 Instant Client; extension \u003d php_oci8_11g.dll; Use with Oracle 11gR2 Instant Client; extension \u003d php_openssl.dll; extension \u003d php_pdo_firebird.dll; extension \u003d php_pdo_mysql.dll; extension \u003d php_pdo_oci.dll; extension \u003d php_pdo_odbc.dll; extension \u003d php_pdo_pgsql.dll; extension \u003d php_pdo.dll; extension \u003d php_pdo.dll \u003d php_pgsql.dll; extension \u003d php_pspell.dll; extension \u003d php_shmop.dll

and replace it with:

Extension \u003d php_bz2.dll extension \u003d php_curl.dll extension \u003d php_fileinfo.dll extension \u003d php_gd2.dll extension \u003d php_gettext.dll; extension \u003d php_gmp.dll; extension \u003d php_intl.dll; extension \u003d php_imap.dll; extension \u003d php_interbase.dll; extension \u003d php_ldap.dll extension \u003d php_mbstring.dll extension \u003d php_exif.dll; Must be after mbstring as it depends on it extension \u003d php_mysql.dll extension \u003d php_mysqli.dll; extension \u003d php_oci8.dll; Use with Oracle 10gR2 Instant Client; extension \u003d php_oci8_11g.dll; Use with Oracle 11gR2 Instant Client extension \u003d php_openssl.dll; extension \u003d php_pdo_firebird.dll extension \u003d php_pdo_mysql.dll; extension \u003d php_pdo_oci.dll; extension \u003d php_pdo_odbc.dll; extension \u003d php_pdo_plgsql.dll extension \u003d php_pdo_sql.dll dll; extension \u003d php_pspell.dll; extension \u003d php_shmop.dll

now uncomment the lines from this group:

; extension \u003d php_soap.dll; extension \u003d php_sockets.dll; extension \u003d php_sqlite3.dll; extension \u003d php_sybase_ct.dll; extension \u003d php_tidy.dll; extension \u003d php_xmlrpc.dll; extension \u003d php_xsl.dll; extension \u003d php_zip.dll

it should look like this:

Extension \u003d php_soap.dll extension \u003d php_sockets.dll extension \u003d php_sqlite3.dll; extension \u003d php_sybase_ct.dll; extension \u003d php_tidy.dll extension \u003d php_xmlrpc.dll extension \u003d php_xsl.dll; extension \u003d php_zip.dll

Restart the web server:

In the catalog C: \\ Server \\ data \\ htdocs \\ create a file named i.php

Copy to this file:

Unzip the downloaded file into C: \\ Server \\ data \\ htdocs \\... Rename this folder (phpMyAdmin-3.5.8.2-all-languages) to phpmyadmin.

In the catalog c: \\ Server \\ data \\ htdocs \\ phpmyadmin \\ create a file config.inc.php and copy there:

Now in your web browser open the address http: // localhost / phpmyadmin /:

For Username enter rootand leave the password blank.

Conclusion

As you can see, although we selected the appropriate versions, you can run a full-fledged web server on Windows XP, even if not with the latest program components.

By the way, you can download a ready-made assembly created according to these instructions. You will find it.

PHP Is a general-purpose scripting programming language mainly used in the development of web applications.

Installation

The PHP interpreter comes in several flavors for different interpreter startup modes.

CLI

To install PHP-CLI run:

sudo apt-get install php5-cli

CGI

To install PHP - CGI run:

sudo apt-get install php5-cgi

FastCGI

To install PHP-FPM run:

sudo apt-get install php5-fpm

Apache module

Starting from Ubuntu Saucy (13.10) PHP is installed on the system with Zend OPcache preinstalled.

Do not install multiple PHP accelerators at once, it will not work.

Alternative PHP Cache

Since Ubuntu Saucy (13.10) package php-apc does not install the opcode cache, instead it installs the package php-apcu with part of the functionality (caching user data).

Apt-get install php-apc

Configuration file /etc/php5/apache2/conf.d/apc.ini.

extension \u003d apc.so realpath_cache_size \u003d 4096k apc.max_file_size \u003d 4M apc.shm_size \u003d 128M apc.mmap_file_mask \u003d /tmp/apc.XXXXXX apc.ttl \u003d 3600 apc.user_ttl \u003d 3600 apc.gc_ttl \u003d 3600

XCACHE

Apt-get install php-xcache

Configuration file /etc/php5/apache2/conf.d/xcache.ini.

realpath_cache_size \u003d 4096k xcache.size \u003d 40M xcache.slots \u003d 8K xcache.ttl \u003d 3600

You can also specify the number of cores for your processor:

Xcache.count \u003d 2

This section of the manual applies to Windows 98 / Me and Windows NT / 2000 / XP / 2003. PHP will not work on 16 bit platforms like Windows 3.1 and sometimes we refer to supported Windows platforms like Win32.

Comment:

Windows XP / 2003 are no longer supported for PHP 5.5.0.

Comment:

Windows 98 / Me / NT4 / 2000 are no longer supported for PHP 5.3.0.

Comment:

Windows 95 is no longer supported for PHP 4.3.0.

If you have a development environment such as Microsoft Visual Studio, you can also build PHP from source.

Once you have PHP installed on Windows, you may also want to download various extensions to provide additional functionality.

Manual Installation Guide

This section contains instructions for manually installing and configuring PHP on Microsoft Windows.

Selecting and downloading a PHP distribution package

Download the PHP distribution as a zip archive from. There are several different versions zip packages - select the version that suits your web server:

PHP package structure and content

Unpack the contents zip archive to a directory of your choice, for example C: \\ PHP \\. The structure of folders and files extracted from the archive will look like this:

Example # 1 PHP 5 package structure

c: \\ php | + - dev | | | | -php5ts.lib - version of php5.lib without multithreading support | + - ext - DLL modules for PHP | | | | -php_bz2.dll | | | | -php_cpdf.dll | | | | -... | + - extras - empty | + - pear is the initial copy of PEAR | | | -go-pear.bat - PEAR installation script | | -... | | -php-cgi.exe - CGI executable | | -php-win.exe - executes scripts without an open console | | -php.exe - PHP Command Line Executable (CLI) | | -... | | -php.ini-development - php settings.ini by default | | -php.ini-production - recommended php.ini settings | | -php5apache2_2.dll - available only in multi-threaded version | | -php5apache2_2_filter.dll - available only in multi-threaded version | | -... | | -php5ts.dll - core PHP DLL (php5.dll in the version without multithreading support) | | -...

Below is a list of modules and executables included in the PHP zip distribution:

    php-cgi.exe is a CGI executable file that can be used when running PHP on IIS via CGI or FastCGI.

    php-win.exe is a PHP executable file for executing PHP scripts without using the console (for example, PHP applications using the Windows GUI).

    php.exe is a PHP executable file for executing PHP scripts in the console (CLI).

    php5apache2_2.dll - Apache 2.2.X module.

    php5apache2_2_filter.dll - Apache 2.2.X filter.

Php.ini file change

After the content of the php package is extracted, create a copy of php.ini-production named php.ini in the same folder. If necessary, it is also possible to place php.ini in any other location of your choice, but this will require additional configuration, which is covered in the PHP Configuration section.

The php.ini file contains the PHP execution rules and instructions for working with the environment in which it runs. Below are some of the php.ini settings that can improve pHP work on Windows. Some of them are optional. There are many other directives that may be useful in your environment - see the php.ini list of directives for more information.

Mandatory directives:

    extension_dir \u003d <путь к директории модулей> - extension_dir specifies the directory where PHP modules are located. The path can be absolute (for example, "C: \\ PHP \\ ext") or relative (for example, ". \\ Ext"). Modules used in php.ini must be located in extension_dir.

    extension \u003d xxxxx.dll - For each plug-in, you must specify the "extension \u003d" directive. Modules from extension_dir marked with this directive are loaded at PHP startup.

    log_errors \u003d On - PHP has an error logging mechanism that can be used to save errors to a file or send them to a service (eg syslog). The mechanism also uses the value of the error_log directive. When PHP is executed by IIS, log_errors must be enabled with correct error_log.

    error_log \u003d <пусть к файлу лога ошибок> - error_log is needed to indicate the absolute or relative path to the file where PHP errors are logged. This file must be writable by the web server. The most common locations for this file are various temporary TEMP directories, for example "C: \\ inetpub \\ temp \\ php-errors.log".

    cgi.force_redirect \u003d 0 - This directive is required for execution under IIS. This is a directory protection mechanism required by many other web servers. However, enabling it under IIS will cause PHP core errors on Windows.

    cgi.fix_pathinfo \u003d 1 - Provides support for PATH_INFO according to the CGI specification. IIS FastCGI uses this setting.

    fastcgi.impersonate \u003d 1 - FastCGI under IIS supports the ability to identify the security tokens of the calling client. This allows IIS to define the security context under which the request is made.

    fastcgi.logging \u003d 0 - FastCGI logging must be disabled in IIS. If recording is enabled, then all messages of any class are recognized by FastCGI as errors, which will cause IIS to throw an HTTP 500 exception.

Optional directives

    max_execution_time \u003d ## - This directive specifies the maximum execution time for any PHP script. The default is 30 seconds. Increase this value if your PHP application needs to run longer.

    memory_limit \u003d ### M - The amount of memory available to the PHP process, in MB. The default is 128, which is sufficient for most PHP applications. Some complex applications may require more memory.

    display_errors \u003d Off - The directive determines which errors should be returned to the web server for further logging. If set to "On", PHP reports all kinds of errors that are listed in the error_reporting directive. For security reasons, it is recommended to set to "Off" on production servers to avoid sending error output end useras they may contain information that threatens the security of the application.

    open_basedir \u003d <пути к директориям, разделенные точкой с запятой> for example openbasedir \u003d "C: \\ inetpub \\ wwwroot; C: \\ inetpub \\ temp". This directive specifies the paths to directories in which PHP operations are allowed. file system... Any operation with files and directories outside the specified paths will result in an error. This directive is especially useful for preventing access to installed PHP in shared hosting environments to prevent PHP scripts from accessing any files outside the website root directory.

    upload_max_filesize \u003d ### M and post_max_size \u003d ### M - Maximum allowed size of uploaded file and sent data, respectively. The values \u200b\u200bof these directives must be increased if PHP applications need to handle large downloadable files such as images or video files.

After installing PHP on your system, the next step is to select a web server and configure it to work with PHP. Select a specific web server in the table of contents for this material.

Microsoft IIS 5.1 and IIS 6.0

This section contains instructions for manually setting up Internet Information Services (IIS) 5.1 and IIS 6.0 to work with PHP on Microsoft Windows XP and Windows Server 2003. For instructions on setting up IIS 7.0 and later versions on Windows Vista, Windows Server 2008, Windows 7 and Windows Server 2008 R2 refer to Microsoft IIS 7.0 and later.

Configuring IIS to process PHP requests

Download and install PHP in accordance to the instructions described in manual installation steps

Comment:

Non-thread-safe build of PHP is recommended when using IIS. The non-thread-safe builds are available at

Configure the CGI- and FastCGI-specific settings in php.ini file as shown below:

Example # 2 CGI and FastCGI settings in php.ini

Enabling FastCGI Support in IIS

FastCGI module is disabled by default when installing IIS. The methods to enable it differ depending on the version of Windows you are using.

To enable FastCGI support on Windows Vista SP1 and Windows 7:

    In the "Start" menu, select "Run", in the window that appears, enter "optionalfeatures.exe" from the keyboard and click "Ok";

    In the "Windows Components" window that opens, open the "Internet Information Services", "Internet Services", "Application Development Components" folder and check the box next to "CGI";

    Click OK and wait for the installation process to complete.


To enable FastCGI support on Windows Server 2008 and Windows Server 2008 R2:

    In Windows, open the Start menu, select "Run:", type "CompMgmtLauncher" from the keyboard and click "Ok";

    If the "Web Server (IIS)" role is not listed in the "Roles" tab, add it by selecting "Add Roles";

    If the "Web Server (IIS)" role is present, select "Select Role Service" and check the box next to "CGI" in the "Application Development Components" group;


Configuring IIS to handle PHP requests

Download and install PHP according to the instructions in the installation description

Comment:

Modify CGI and FastCGI settings in php.ini file as shown below:

Example # 8 CGI and FastCGI settings in php.ini

fastcgi.impersonate \u003d 1 fastcgi.logging \u003d 0 cgi.fix_pathinfo \u003d 1 cgi.force_redirect \u003d 0

Configure an IIS handler for PHP using the IIS Management Interface or command line.

Using the IIS Management Interface to Create a PHP Handler

The following steps will allow you to create an IIS handler for PHP in the IIS Management Interface:



Using the command line to create a PHP handler mapping

Use the commands below to create an IIS FastCGI process pool that will use the php-cgi.exe executed for PHP requests. Replace the value of the fullPath parameter with the absolute path to the php-cgi.exe file.

Example # 9 Creating an IIS FastCGI Process Pool

% windir% \\ system32 \\ inetsrv \\ appcmd set config /section:system.webServer/fastCGI ^ / +

Configuring IIS to handle specific PHP requests from the command line is shown below. Replace the scriptProcessor parameter value with the absolute path to the php-cgi.exe file.

Example # 10 Creating a PHP request handler mapping

% windir% \\ system32 \\ inetsrv \\ appcmd set config /section:system.webServer/handlers ^ / +

This command creates a handler mapping for * .php files for IIS that is generated and processed by the FastCGI module.

Comment:

This step completes the installation and configuration. Following instructions optional, but highly recommended for optimal PHP functionality and performance on IIS.

File system view and access

When using IIS, it is recommended to enable FastCGI view in PHP. This is controlled by the fastcgi.impersonate directive in the php.ini file. When impersonation is enabled, PHP will perform all file system operations under the account that was specified during IIS authentication. This ensures that with a common PHP process for all IIS sites, the PHP scripts of those sites will not have access to each other's files as long as IIS uses different accounts for each site.

For example, in the default IIS 7 settings, anonymous authentication is enabled under the standard IUSR user. This means that by giving IIS permission to execute the PHP script, you also need to give the IUSR account read permissions to this script. If a PHP application needs to write to some files or folders, then the IUSR account should be given write permissions to them.

You can use the following commands to decide which user is used for authentication in IIS 7. Replace "Default Web Site" with the name of the IIS site you are working with. In the output, in the XML configuration, see the userName attribute.

Example # 11 Determining the account used by IIS for anonymous authentication

% windir% \\ system32 \\ inetsrv \\ appcmd.exe list config "Default Web Site" ^ / section: anonymousAuthentication

Comment:

If the userName attribute is not present in the anonymousAuthentication element, or is set to the empty string, then the application pool identity is used as anonymous for this website.

To change the access settings for files or folders, use the user interface in Windows Explorer or the icacls command.

Example # 12 Configuring file permissions

icacls C: \\ inetpub \\ wwwroot \\ upload / grant IUSR: (OI) (CI) (M)

Setting index.php as default document in IIS

By default, IIS does not set the default document name to handle HTTP requests. In PHP applications, the index.php document is usually used by default. To add index.php to the default IIS docs sheet, use a command like this:

Example # 13 Setting index.php as the default document in IIS

% windir% \\ system32 \\ inetsrv \\ appcmd.exe set config ^ -section: system.webServer / defaultDocument / + "files." ^ / commit: apphost

FastCGI and PHP configuration with process re-creation

Configuring IIS FastCGI settings for recycling PHP processes using commands is shown below. The FastCGI instanceMaxRequests option sets the maximum number of requests that a single php-cgi.exe process can handle until IIS starts to disable them. PHP environment variable PHP_FCGI_MAX_REQUESTS sets how many requests a single php-cgi.exe process will process until it starts deleting them. Of course, the value set for FastCGI InstanceMaxRequests is less than or equal to PHP_FCGI_MAX_REQUESTS.

Example # 14 Configuring FastCGI and PHP re-creation

% windir% \\ system32 \\ inetsrv \\ appcmd.exe set config -section: system.webServer / fastCgi ^ /.instanceMaxRequests:10000% windir% \\ system32 \\ inetsrv \\ appcmd.exe set config -section: system.webServer / fastCgi ^ / + ". environmentVariables. ^"

Setting FastCGI timeout

Increasing the FastCGI timeout parameter is done if there is a long running PHP script. Two parameters control the timeout, they are: activityTimeout and requestTimeout. Use the commands below to change the timeout settings. Of course, you need to replace the value of the fullPath parameter with the full path to the php-cgi.exe file.

Example # 15 Configuring FastCGI timeout settings

% windir% \\ system32 \\ inetsrv \\ appcmd.exe set config -section: system.webServer / fastCgi ^ /.activityTimeout:"90 "/ commit: apphost% windir% \\ system32 \\ inetsrv \\ appcmd.exe set config -section: system .webServer / fastCgi ^ /.requestTimeout:"90 "/ commit: apphost

Changing the location of the php.ini file

There are two ways to configure PHP to work with Apache 1.3.x on Windows. The first is to use the CGI binary (php.exe for PHP 4 and php-cgi.exe for PHP 5), the second is to use the Apache Module DLL. In both cases, you need to edit httpd.conf to configure Apache to work with PHP and restart the server.

Currently, the SAPI module is more stable under Windows, so we recommend using it instead of CGI as it is more transparent and secure.

Although there are several options for configuring PHP for Apache, they are fairly straightforward for a beginner. Please refer to Apache documentation for further configuration instructions.

Remember to reboot the server after modifying the config file. For example, by the commands NET STOP APACHE and NET START APACHEif Apache is running as a Windows service, or using regular shortcuts.

Comment:

Install PHP as an Apache Module

You need to add the following lines to your Apache httpd.conf file:

Example # 17 PHP as an Apache 1.3.x module

This assumes PHP is installed in c: \\ php. Change the path if it is not.

# Add to the end of the LoadModule section # Don "t forget to copy this file from the sapi directory! LoadModule php4_module" C: /php/php4apache.dll "# Add to the end of the AddModule section AddModule mod_php4.c

# Add to the end of the LoadModule section LoadModule php5_module "C: /php/php5apache.dll" # Add to the end of the AddModule section AddModule mod_php5.c

For both versions:

# Add this line inside the conditional brace AddType application / x-httpd-php .php # For syntax highlighted .phps files, also add AddType application / x-httpd-php-source .phps

Installing as a CGI Binary File

If PHP is unpacked to C: \\ php \\ as described in the Manual Installation Steps section, you must add the following lines to your Apache config file:

Example # 18 PHP and Apache 1.3.x as CGI

Note that the second line in the list above is already in httpd.conf, but it is commented out. Also, don't forget to replace c: / php / with your actual PHP path.

Attention

"CGI Security"

When installing PHP as CGI, there is no such convenient option for syntax highlighting in PHP sources as when installing as a module. If you want to use it, you must use the function highlight_file ()... To do this, simply create a PHP script with the following code: .

Apache 2.x on Microsoft Windows

This section provides instructions for installing PHP for Apache 2.x on Microsoft Windows systems.

Comment: Apache 2.2 support

Apache 2.2 users should note that DLL file for Apache 2.2 it is named php5apache2_2.dll, not php5apache2.dll and it is only available for PHP 5.2.0 and later.

You are strongly encouraged to read the »Apache Documentation to get a basic understanding of Apache 2.x Server. Also, before reading this help, take a look at the »Windows Recommendations for Apache 2.x.

Apache 2.x is designed to run on server versions of Windows such as Windows NT 4.0, Windows 2000, Windows XP, or Windows 7. Although Apache 2.x can be used on Windows 9x, these platforms are not fully supported and some features will not work right. There are no plans to remedy this situation.

Download the latest version »Apache 2.x and the correct PHP version. Follow the Step by Step Installation Guide and come back to continue integrating PHP and Apache.

There are three ways to install PHP for Apache on Windows. You can run PHP as a handler, like CGI, or under FastCGI.

Comment: Remember that when specifying paths in Apache configuration files under Windows, all backslashes, for example, c: \\ directory \\ file.ext, must be changed to forward slashes: c: /directory/file.ext. Paths with directories may also need a trailing slash.

Install PHP as a handler under Apache

You need to add the following lines to your Apache configuration file httpd.conf to load the PHP module for Apache 2.x:

Example # 19 PHP as an Apache 2.x handler

# LoadModule php5_module "c: /php/php5apache2.dll" AddHandler application / x-httpd-php .php # configure path to php.ini PHPIniDir "C: / php"

Comment: Don't forget to include the actual path to the PHP directory instead of C: / php / in the above example. Make sure that either php5apache2.dll or php5apache2_2.dll is used in the LoadModule directive, and make sure that the specified file is actually in the path you specified in the directive.

The above configuration will allow PHP to parse any file that has a .php extension, even if there are other extensions. For example, a file named example.php.txt will be run by the PHP engine. To ensure that only files that have an extension .php will be launched, use the following configuration:

SetHandler application / x-httpd-php

Running PHP as CGI

You should refer to the »Apache CGI documentation for a more complete understanding of running CGI under Apache.

To run PHP as CGI, you need to place your php-cgi files in a directory designated as CGI directory using the ScriptAlilas directive.

After that you need to add the line #! in PHP files pointing to the location of the PHP executable.

Example # 20 PHP as CGI under Apache 2.x

#! C: /php/php.exe

Attention

By using a CGI installation, your server is exposed to several possible vulnerabilities. Please see the "CGI Security" section to learn how you can protect yourself from such attacks.

Running PHP under FastCGI

Running PHP under FastCGI has several advantages over running it as CGI. Installation is pretty simple:

NSAPI setup on Sun, iPlanet and Netscape servers

To install PHP with NSAPI, do the following:

  • Copy php4ts.dll to your systemroot (the directory where you installed Windows)
  • Make a file association from the command line. Type the following two lines:

    assoc .php \u003d PHPScript ftype PHPScript \u003d c: \\ php \\ php.exe% 1% *

  • In the Netscape Enterprise Administration Server create a new mime type (Category: type, Content-Type: magnus-internal / x-httpd-php, File Suffix: php).
  • Edit magnus.conf (for servers\u003e \u003d 6) or obj.conf (for servers< 6) and add the following: You should place the lines after mime types init.

    Init fn \u003d "load-modules" funcs \u003d "php4_init, php4_execute, php4_auth_trans" shlib \u003d "c: /php/sapi/php4nsapi.dll" Init fn \u003d "php4_init" LateInit \u003d "yes" errorString \u003d "Failed to initialise PHP! "

    (PHP\u003e \u003d 4.3.3) The php_ini parameter is optional but with it you can place your php.ini in your web server configuration directory.

    Configure the default object in obj.conf (for virtual server classes in their vserver.obj.conf): In the section, place this line necessarily after all "ObjectType" and before all "AddLog" lines:

    Service fn="php4_execute" type="magnus-internal/x-httpd-php"

    (PHP >= 4.3.3) As additional parameters you can add some special php.ini -values, for example you can set a docroot="/path/to/docroot" specific to the context php4_execute is called. For boolean ini-keys please use 0/1 as value, not "On","Off",... (this will not work correctly), e.g. zlib.output_compression=1 instead of zlib.output_compression="On"

    This is only needed if you want to configure a directory that only consists of PHP scripts (same like a cgi-bin directory):

    ObjectType fn="force-type" type="magnus-internal/x-httpd-php" Service fn=php4_execute

    After that you can configure a directory in the Administration server and assign it the style x-httpd-php... All files in it will get executed as PHP. This is nice to hide PHP usage by renaming files to .html.

  • Restart your web service and apply changes
  • Do it for each web server instance you want PHP to run
  • Comment:

    The stacksize that PHP uses depends on the configuration of the web server. If you get crashes with very large PHP scripts, it is recommended to raise it with the Admin Server (in the section "MAGNUS EDITOR").

    CGI environment and recommended modifications in php.ini

    Important when writing PHP scripts is the fact that Sun JSWS / Sun ONE WS / iPlanet / Netscape is a multithreaded web server. Because of that all requests are running in the same process space (the space of the web server itself) and this space has only one environment. If you want to get CGI variables like PATH_INFO, HTTP_HOST etc. it is not the correct way to try this in the old PHP way with getenv () or a similar way (register globals to environment, $ _ENV). You would only get the environment of the running web server without any valid CGI variables!

    Comment:

    Why are there (invalid) CGI variables in the environment?

    Answer: This is because you started the web server process from the admin server which runs the startup script of the web server, you wanted to start, as a CGI script (a CGI script inside of the admin server!). This is why the environment of the started web server has some CGI environment variables in it. You can test this by starting the web server not from the administration server. Use the command line as root user and start it manually - you will see there are no CGI-like environment variables.

    Simply change your scripts to get CGI variables in the correct way for PHP 4.x by using the superglobal $ _SERVER. If you have older scripts which use $ HTTP_HOST, etc., you should turn on register_globals in php.ini and change the variable order too (important: remove "E" from it, because you do not need the environment here):

    variables_order \u003d "GPCS" register_globals \u003d On

    Special use for error pages or self-made directory listings (PHP\u003e \u003d 4.3.3)

    You can use PHP to generate the error pages for "404 Not Found" or similar. Add the following line to the object in obj.conf for every error page you want to overwrite:

    Error fn \u003d "php4_execute" code \u003d XXX script \u003d "/ path / to / script.php"

    Where XXX is the HTTP error code. Please delete any other Error directives which could interfere with yours. If you want to place a page for all errors that could exist, leave the code parameter out. Your script can get the HTTP status code with $ _SERVER ["ERROR_TYPE"].

    Another possibility is to generate self-made directory listings. Just create a PHP script which displays a directory listing and replace the corresponding default Service line for type \u003d "magnus-internal / directory" in obj.conf with the following:

    Service fn \u003d "php4_execute" type \u003d "magnus-internal / directory" script \u003d "/ path / to / script.php"

    For both error and directory listing pages the original URI and translated URI are in the variables $ _SERVER ["PATH_INFO"] and $ _SERVER ["PATH_TRANSLATED"].

    This list describes the installation of the ISAPI module to work with the Sambar server under Windows.

      Find a file called mappings.ini (in the config folder) in the Sambar installation directory.

      Open mappings.ini and add the following line under :

      Example # 22 ISAPI configuration for Sambar

      # for PHP 4 * .php \u003d c: \\ php \\ php4isapi.dll # for PHP 5 * .php \u003d c: \\ php \\ php5isapi.dll

      (If PHP is installed in c: \\ php.)

      Restart Sambar for the changes to take effect.

    Comment:

    If you want to use PHP to communicate with resources on other computers on your network, you need to change the account that is used by the Sambar server service. By default, this is LocalSystem and remote resources will be unavailable. Account can be edited using the Services option of the Administration Utility from the Windows Control Panel.

    Xitami on Microsoft Windows

    This section contains notes and tricks specific to »Xitami on the Windows platform.

    This checklist describes how to install the PHP CGI library so that it works with Xitami on Windows.

    Comment: Important for CGI users

    Installing PHP Modules on Windows

    After installing PHP and web server on Windows OS, you may need to install some modules to add functionality. You can choose which modules will be loaded when PHP starts by modifying your php.ini file. Also you can load modules dynamically in your scripts using the function

    Apache2.2.2 distribution kit with an installer named apache_2.2.2-win32-x86-no_ssl.msi. You can find it at www.sai.msu.su/apache/dist/httpd/binaries/win32/

    Run the downloaded installer for execution. When the installer asks you where to install Apache, point it to the directory c: /Apache2.2

    Note

    All further instructions will be based on the assumption that Apache is installed in the c: /Apache2.2 directory. If you are installing Apache in a different directory, then you must adapt the instructions accordingly for your situation.

    Installing Apache from the installer is quite transparent and does not cause any particular difficulties, as a result of which it is not rational to provide its full description in this article. Here is just one dialog box that the user needs to fill in during the installation process. This is the server name selection window. In the "Network Domain" and "ServerName" fields, write down the name of the server that Apache will be configured with by default.


    Note

    This manual describes the installation of the Apache server on the assumption that it will be used only for local testing of sites and will not work on the Intranet and Internet. For the server to work on the Intranet and the Internet, you must enter the real domain nameto be used by the server.

    If the installation process was correct, then after its completion Apache2.2 should already be running as a service. To check if this is the case, open the list of Windows services (" Start "| "Control Panel" | "Administration" | "Services") and find the line Apache2.2. (or Apache2). Service status: up or down is displayed in the third column.

    If you cannot find the line Apache2.2 in the list of services, then the installation process probably failed and Apache was not installed as a service. In this case, you need to install Apache as a service yourself. To do this, you need a program with a console, such as FAR, WindowsCommander, TotalCommander, etc.

    Open the program with a console, change to the c: /Apache2.2/bin directory and run the command:

    C: /Apache2.2/bin/httpd.exe -k install

    In response, you should receive a message "The Apache2 service is successfully installed"... The appearance of the console window is shown in the figure.


    First start

    Apache management (start, stop, restart) is carried out either through the graphical management interface windows services, or in the console by executing the httpd.exe file with certain keys.

    Windows services are managed through the context menu opened by right-clicking on the service name. If Apache is not already running, then execute the "Start" command from the context menu.


    If you like to work in the console, the keys below are used to manage Apache.

    Commands for managing Apache via the console

    Httpd.exe -k start (Start service)
    httpd.exe -k stop (Stop service)
    httpd.exe -k restart


    By default, the server root directory is set to c: /Apache2.2/htdocs... This is where the index.html file is located, displayed by the name localhost. The directive is responsible for determining the root directory of the site DocumentRootin file c: /Apache2.2/conf/httpd.conf.

    DocumentRoot "C: /Apache2.2/htdocs"

    You can change it to make a different directory the root directory of the server.

    However, before doing this, you should make the minimum configuration of the httpd.conf configuration file. By default, Apache is configured to deny any access to site directories and permissions must be set explicitly for each directory, as is done for the C: /Apache2.2/htdocs directory. If you move the root directory of the server to another directory without setting the appropriate permissions, then in response you will receive a 403 Forbidden error and the page shown in the figure.


    Therefore, if you are NOT going to use your latest Apache to provide hosting services on the Internet or on a local network, then you should immediately remove the default protection.

    Find the following lines in the file С: /Apache2.2/conf/httpd.conf:


    Options FollowSymLinks
    AllowOverride None
    Order deny, allow
    Deny from all
    Satisfy all

    Pay attention to the line Deny from all.

    It prohibits all access to directories, including virtual host directories. Apache will respond with a 403 Forbidden error when trying to access them. It is counterbalanced by the "Allow from all" directive. Setting this directive overrides the "Deny from all" directive.

    You can set the Allow from all directive for each directory and for each virtual host, but you can do it easier and remove (or comment out) the “Deny from all” directive from the container.


    Options FollowSymLinks
    AllowOverride None
    Order deny, allow
    # Deny from all
    Satisfy all

    After completing these simple steps, restart Apache. How to do this is described above.

    Install PHP

    A modern web server is already unthinkable without the support of dynamically generated pages. In Russia, the leader among technologies for creating dynamic pages and web applications is PHP technology. Below we will consider the process of connecting PHP using the example of version 5.3.5. If you already have this version of PHP installed, you can skip to the section "Connecting PHP to Apache2.2.2".

    You can download the distribution kit with PHP from our website at. The link can also read the rules for choosing a distribution kit and why we took it upon ourselves to offer to download the distribution kit from our website, and not from the official php.net. When downloading the distribution from the link, it is assumed that you will be installing PHP as a module.

    Unpack the php zip file to the c: /php-5.3.5 directory. This completes the PHP installation. Next steps will deal with setting up the PHP + Apache bundle and configuring PHP itself.

    Note

    All further instructions will be based on the assumption that you are using php-5.3.5, which is installed in the c: /php-5.3.5 directory. If you have a different version of PHP or you are installing php in a different directory, then you must adapt the instructions provided to suit your situation.

    PHP connection to Apache2.2.2

    PHP connection issues with Apache2.2

    If you try to connect the standard php5apache2.dll module to Apache2.2.2, you will fail. Apache will not want to start with the message shown in the figure.


    And the following messages will appear in the system and application logs

    The Apache service named reported the following error:
    \u003e\u003e\u003e httpd.exe: Syntax error on line 115 of C: /Apache2.2/conf/httpd.conf:
    Cannot load C: /php-5.3.5/php5apache2.dll into server: \\ xcd \\ xe5 \\ xed \\ xe0 \\ xe9
    \\ xe4 \\ xe5 \\ xed \\ xf3 \\ xea \\ xe0 \\ xe7 \\ xe0 \\ xed \\ xed \\ xfb \\ xe9 \\ xec \\ xee \\ xe4 \\ xf3 \\ xeb \\ xfc.

    The php5apache2.dll library is intended for Apache 2.0.X, for Apache 2.2.X you need to include the php5apache2_2.dll library (it is located next to php5apache2.dll in the distribution).

    Configuring httpd.conf for PHP connection

    To connect php, as a module, you need to add only 3 instructions to the httpd.conf file

    Instructions for connecting PHP in httpd.conf

    LoadModule php5_module c: /php-5.3.5/php5apache2_2.dll
    AddType application / x-httpd-php phtml php
    PHPIniDir "c: /php-5.3.5/"

    These lines should be placed approximately in the middle of the httpd.conf file, for example, right after the LoadModule directives. The exact location of these directives does not really matter, but you cannot put them at the beginning, as well as at the very end of the httpd.conf file.

    • The first line loads the PHP module implemented in the php5apache2_2.dll library
    • The second line sets the correspondence between files with the php extension and the application / x-httpd-php mime-type, which is processed by the PHP module.
    • The third line allows you to explicitly specify the location of the php.ini configuration file.

    Note

    The PHPIniDir directive was badly lacking in Apache1.3, as often there was confusion in php configuration when there were multiple copies of the php.ini file, or when it was placed in an inappropriate directory.

    The next step is to create a config file for PHP. In httpd.conf in the PHPIniDir directive, the location of the php configuration file was specified in the c: /php-5.3.5 directory. The configuration file itself must be called php.ini

    The c: /php-5.3.5 directory contains several configuration file templates. Let's take the file as a basis c: /php-5.3.5/php.ini-recommended and rename it to php.ini... Thus, the PHP configuration file (php.ini) will be located in the c: /php-5.3.5 directory and all changes to the PHP configuration should be made there.

    After making changes to httpd.conf and creating php.ini file, restart Apache.

    Create a test php script named phpinfo.php that performs the function of the same name and save it to the directory c: /Apache2.2/htdocs.

    Phpinfo.php script

    echo phpinfo ();

    // Note that the full syntax is used
    // php script.?>

    Note

    The phpinfo.php test script uses the full syntax to define the PHP script. In recent PHP distributions, the short notation syntax is disabled by default. The directive is responsible for enabling the short recording mode short_open_tag in php.ini file. It needs to be set to the value On.

    Now refer to this script through the browser by entering in address bar http: //localhost/phpinfo.php... In response, you should see the well-known purple pages displaying php and its extensions settings.


    If the report of the phpinfo () function in the form of "purple tables" is displayed, then php is successfully executed by Apache.

    Possible mistakes

    Apache loads, but a blank page opens instead of purple tables.

    Check: is the test script written in full syntax or shorthand? Those.:

    Should be written
    echo phpinfo ();
    ?>
    instead
    echo phpinfo ();
    ?>

    This article describes how to install Apache 2.4 + PHP 5.6 + MySQL 5.6 on Windows 7/8 / 8.1 / 10 operating system

    Before you continue reading, pay attention to whether you really need to install and configure all this under Windows? Maybe you should pay attention to and not waste your time and nerves configuring the same thing directly in Windows? In any case, read the article on. Perhaps it will save you not only time, but also health.

    This manual will be useful for novice WEB developers who are going to install on their Windows PC the Apache WEB server with the latest PHP interpreter. Of course, it's much easier to install a build like Denwer, or resort to using installers and not worry about settings. However, every WEB developer must understand the process of the WEB-server, the process of its installation and configuration.

    If you want to install PHP 7, please refer to the article.

    If in the process of assembling the server according to this instruction you encountered problems and still consider yourself a WEB-developer, then it will be the right step to understand the problems that have arisen, and not write in the comments that the instruction is shit. Working instruction. Proven by time and hundreds of installations. Be careful when doing simple steps... Performing steps manually and analyzing situations, if not working, will add skill to you as a developer. If you are not a WEB-developer and do not plan to be one, then find an easy way to install on the Internet - this instruction not for you.

    Please note that under Windows XP these versions VC11 it will be impossible (or extremely difficult) to start.

    Preparatory work

    Make sure you have Windows 7 or newer. If you have Windows XP, this manual will not help you, since the version of Apache described here does not work under Windows XP.

    Remove all WEB servers that you installed before, go to services and make sure there are no Apache or IIS services there. If you already have a web server installed, the second one in parallel most likely will not work at all.

    If you have Skype, be sure to disable the use of port 80 in the settings. Ultimately, you must make sure that no service is using port 80.

    For work, it is highly desirable to have a file manager that allows you to create files with any extensions, or, even better, a code editor like Sublime Text or Notepad ++ or a full-fledged IDE.

    The folder structure can be different, but this instruction is written for a specific structure and if you follow it, everything is guaranteed to work.
    Before you start, create on disk D folder USR, inside which create 5 subfolders: apache, php, tmp, www, log... Exactly. Without specifying version numbers.

    In the catalog www create index files (using file manager or a code editor), which will be needed to verify that everything works:

    • index.html with content: It works!
    • index.php with content:

    If there is no file manager / code editor / IDE, download the archive with these two files. But, if you consider yourself a WEB-developer, you must acquire tools.

    Add to the system PATH variable:

    ; D: \\ USR \\ apache; D: \\ USR \\ apache \\ bin; D: \\ USR \\ php;

    Remarks!

    The line numbers given in the example config files may differ for other versions of apache and php.
    All commands, including editing files, must be carried out on behalf of the Administrator.

    Installing Apache 2.4

    Although for simple PHP development there is no need for a separate WEB-server (PHP has its own built-in WEB-server, which is almost always enough for developing one project), it is still recommended to install and configure the Apache WEB-server, if only because the programmer must know these subtleties. Ultimately, you will have to work with the WEB-server and have to deal with its configuration. So let's get started.

    1. Loading Apache 2.4 binaries VC11 for your system at the link http://www.apachelounge.com/download/VC11/ Most likely you have a 64-bit OS, so you need a file with a name like httpd-2.4. xx-win64-VC11.zip
    2. If you need any additional modules, you can download them there (there is no need for a basic installation)
    3. Unzip the contents of the folder Apache24 from the downloaded archive to D: \\ USR \\ apache... Please note that in D: \\ USR \\ apache you need to put not the Apache24 folder from the archive, but its contents. You don't need to install anything.
    4. Change the value in the file ServerRoot to "d: / usr / apache" ( line 37) and the value DocumentRoot (and Direcroty) to "d: / USR / www" ( lines 242 and 243). You should also uncomment line 218 and change it to: ServerName localhost: 80
    5. Change the parameters for storing logs in the same file (find the parameters and change them): ErrorLog "D: /USR/log/apache-error.log" CustomLog "D: /USR/log/apache-access.log" common
    6. Install the Apache service (on behalf of the Administrator). Open a command line as Administrator and paste the following line there: D: \\ USR \\ apache \\ bin \\ httpd.exe -k install
    7. Watch for error messages during the installation of the service. If everything is done correctly, there should be no mistakes. If after executing the line, the command line does not appear again, then you did something wrong. Just use the copy and paste functions to avoid mistakes when reprinting.
    8. Create a shortcut on the desktop for D: \\ USR \\ apache \\ bin \\ ApacheMonitor.exe and / or put it in startup (to open the startup window in WIN8, press WIN + R, then enter shell: Startup and click OK)
    9. Launch ApacheMonitor. A shortcut will appear in the system tray. Left-click on it, select Apache24 -\u003e Start.
    10. In the browser, go to http: // localhost / - you should see It works!
    11. If you haven't seen such an inscription, we figure out what went wrong (we read the logs, google, try to figure out the problem on our own, since we decided to understand the intricacies of the web server)

    Install PHP 5.6

    1. Download the latest version VC11 x86Thread Safe or VC11 x64Thread Safeat the link http://windows.php.net/download/. Please note that you need exactly VC11 and exactly Thread Safe... Bit depth should be like Apache. The file you need will most likely be named something like: php-5.6.11-Win32-VC11-x86.zip or php-5.6.11-Win32-VC11-x64.zip
    2. Extract the contents of the archive into D: \\ USR \\ php... As with Apache, you don't need to install anything.
    3. To file D: \\ USR \\ apache \\ conf \\ httpd.conf add the lines: LoadModule php5_module "d: /USR/php/php5apache2_4.dll" AddHandler application / x-httpd-php .php # Path to php.ini PHPIniDir "D: / USR / php"
    4. And change the value DirectoryIndex on index.html index.php (line 276)
    5. Using ApacheMonitor, restart Apache (Apache24 -\u003e Restart)
    6. Go to the browser http: //localhost/index.php and make sure that PHP is working.
    7. Making a copy of the file D: \\ USR \\ php \\ php.ini-development With name D: \\ USR \\ php \\ php.ini
    8. Using the search, we find, uncomment and change the parameters: extension_dir \u003d "D: / USR / php / ext" sys_temp_dir \u003d "D: / USR / tmp" extension \u003d php_mysql.dll extension \u003d php_mysqli.dll extension \u003d php_openssl.dll date.timezone \u003d Europe / Zaporozhye
    9. We execute on the command line php -m to view the list of plugins.
    10. Restarting Apache using ApacheMonitor

    Apache virtual hosts

    1. If you are debugging several projects on your computer, you may need virtual hosts (sites). For example, we will consider two virtual hosts: s1.localhost and s2.localhost... For convenience, we will create folders with the same names, which is not at all necessary in a real system.
    2. Please note that when using virtual hosts, the parameter DocumentRoot the Apache config file no longer makes sense. The main host of the server (which will be available at http: // localhost /) is now first virtual host in the virtual hosts config file!
    3. First, you need to add to the file c: \\ Windows \\ System32 \\ drivers \\ etc \\ hosts the following lines: 127.0.0.1 s1.localhost 127.0.0.1 s2.localhost

      This must be done on behalf of the Administrator. It is advisable to reboot after that, but in practice this was not required. If you cannot modify the file (permissions), you can copy it to your desktop, modify it, and then copy it back.

    4. Create folders for virtual hosts D: \\ USR \\ www \\ s1.localhost and D: \\ USR \\ www \\ s2.localhostwhere the files will be located. Create a file in each of the folders index.html with content S1 and S2 accordingly (to control that everything works as it should)
    5. Then we create folders for logs: D: \\ USR \\ log \\ s1.localhost and D: \\ USR \\ log \\ s2.localhost - the logs of each site will be stored here. Actually, logs can be stored in one folder, but I am used to doing this - it is more convenient for me.
    6. Next, you need to enable support for virtual hosts. In file D: \\ USR \\ apache \\ conf \\ httpd.conf uncomment the line Include conf / extra / httpd-vhosts.conf
    7. Next, edit the file d: \\ USR \\ apache \\ conf \\ extra \\ httpd-vhosts.conf - it should look like this (each virtual host has its own VirtualHost block): ServerAdmin [email protected] DocumentRoot "D: /USR/www/s1.localhost" ServerName s1.localhost ServerAlias \u200b\u200bwww.s1.localhost ErrorLog "D: /USR/log/s1.localhost/error.log" CustomLog "D: / USR / log / s1 .localhost / access.log "common ServerAdmin [email protected] DocumentRoot "D: /USR/www/s2.localhost" ServerName s2.localhost ServerAlias \u200b\u200bwww.s2.localhost ErrorLog "D: /USR/log/s2.localhost/error.log" CustomLog "D: / USR / log / s2 .localhost / access.log "common
    8. First virtual host s1.localhost will now be the main host of the system, since its block comes first in the configuration file, i.e. will be available at the entrance to