• Installation on older versions of Windows OS. Installing Apache, PHP, MySQL and phpMyAdmin on Windows XP Manual Installation Guide

    This article provides a step-by-step guide to install PHP to work with the Apache HTTP server on Windows. This procedure has been tested on both Windows XP and Vista. It is assumed that you have already completed the Apache installation.

    PHP 5 Setup Steps

    1. Download PHP 5

    Before you get started, download a copy of PHP 5 from download pages. Download the secure VC6 package from the "Windows Binaries" section - that is, do not download the installer. For example, select the package marked " PHP 5.2.5 zip package"if the current version is 5.2.5.

    Note: Please note that I have not tested the procedure below with PHP 5.3 versions, only with 5.2.5, which was the latest version at the time of writing. In theory, the same steps should be followed to install PHP 7.

    2. Install PHP 5

    Create a folder on your hard drive for PHP. I suggest c:php , although you could use a different folder name and location. Personally, I prefer not to use names with spaces.

    Extract all files from the downloaded archive into this folder. To do this, simply double-click on the zip file. And then drag all the files into the c:php folder.

    3. For those upgrading the package: Remove the old PHP.INI file from the Windows directory

    If you are migrating to PHP 5 from an older version, go to the Windows directory ( usually this is c:windows), and delete any php.ini files you previously placed there.

    4. PHP setup

    Go to the c:php folder and create a copy of the php.ini-recommended file. Name the new file php.ini. You should now have a c:phpphp.in file with content identical to the c:phpphp.ini-recommended file.

    Note: If you are using Apache 1 you need to either move the php.ini file to the Windows directory ( c:windows), or set your PATH environment variable to include c:php . If you don't know how to do this, just move the php.ini file to the c:windows folder. You don't need to do this if you are using Apache 2, as we will later specify a directive in the Apache 2 configuration file with the location of the php.ini file.

    To install PHP on Windows 7 using a text editor ( for example, such as Notepad, which can be found in the System section of the Start menu)? open the php.ini file. You may need to make the following changes to the file:

    a) Including short opening tags

    Find the following line:

    short_open_tag = Off

    If short_open_tag is set to off , tags like "

    Since many third party PHP scripts use the "

    short_open_tag = On

    b) Magic quotes

    When Apache PHP is installed by default, incoming data is not automatically slash escaped. If you want the input to be prefixed with a backslash (""), for example to reproduce hosting settings, find the following line:

    magic_quotes_gpc = Off

    and replace it with:

    magic_quotes_gpc = On

    It is not recommended to do this if this parameter is not set on the hosting. Even when set to Off, you can still use PHP function addslashes() to add slashes for specific pieces of data.

    c) Using global variables

    A number of older scripts, when executed, assume that all data submitted through a form will automatically have a PHP variable with the same name. For example, if a form has an input field named "something", older PHP scripts assume that the PHP processor will automatically create a variable called $something that contains the value specified through that field.

    If you use such scripts, you need to find the following line:

    register_globals = Off

    and change it to:

    register_globals = On

    Warning: When installing PHP on Windows, do not do this unless you have third party scripts that require this to work. When writing new scripts, it is best to always assume that the register_globals element is set to " Off«.

    d) Error display

    On a live site, errors in the script are usually logged without appearing in the PHP error file. But on a local machine, while you are testing and debugging a PHP script, it is more convenient to send error messages when they are detected directly to the browser window. This way you won't miss errors even if you forget to check the error log file.

    To have PHP display error messages directly in the browser window, look for the following line:

    display_errors = Off

    and change it to:

    display_errors = On

    This setting should always be set to Off on a running site.

    e) Session path

    If the script uses sessions, find the following line:

    ;session.save_path = "/tmp"

    session.save_path specifies the folder where PHP saves session files. Since the /tmp folder does not exist in Windows, you need to install another folder. One way is to create a folder called c:tmp ( as previously we created c:php) and specify this folder for this parameter. If you do this, change this line as follows:

    session.save_path = "c:tmp"

    Note that in addition to changing the path, I also removed the semicolon prefix (";") from the string.

    You can also use the current TEMP folder on your computer. Or create a tmp folder in your PHP directory, such as c:phptmp and configure the config file accordingly. There can be many possible options. If you can't decide which one to choose, just create c:php and do as I said above.

    f) SMTP Server

    If you have installed PHP 55, 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:

    ; For Win32 only. SMTP = localhost smtp_port = 25 ; For Win32 only. ;sendmail_from= [email protected]

    Change it to include your SMTP server address and email account. For example, if your SMTP server mail.example.com, and the email address [email protected], change the code like this:

    SMTP = mail.example.com smtp_port = 25 sendmail_from = [email protected]

    Please note that after this, when the script tries to use the mail() function, it will need to connect to your ISP for it to work successfully. If you do not change the above lines and try to use the mail() function in a script, the function will return a failure code and display an error message.

    How to configure Apache for PHP 5

    There are two ways to install Apache PHP. First: set it to download PHP interpreter as an Apache module. Second: configure it to run the interpreter as a CGI binary. Only one of them needs to be used. Select the module method if PHP is also installed on the hosting, like the Apache module, or use the CGI method if it is implemented on the hosting.

    a) Running PHP 5 as an Apache module

    To configure Apache to load PHP as a module for parsing PHP scripts, use an ASCII text editor to open the Apache configuration file, httpd.conf.

    If you are using Apache 1.x, the file is located in the folder c:Program FilesApache GroupApacheconf. Apache 2.0.x users can find it in the folder C:Program FilesApache GroupApache2conf, and Apache 2.2.x users are in the folder C:Program FilesApache Software FoundationApache2.2conf. Typically, it is located in the conf folder of the directory where Apache is installed.

    Locate the section of the file with LoadModule statements. Declarations preceded by the hash symbol "#" are considered commented out.

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

    LoadModule php5_module "c:/php/php5apache.dll"

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

    LoadModule php5_module "c:/php/php5apache2.dll"

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

    LoadModule php5_module "c:/php/php5apache2_2.dll"

    Note that this example PHP installation uses the forward slash character (“/”) instead of the traditional Windows backslash (“”). This is not a typo.

    If you are using Apache 1.x, find the "AddModule" series of statements and add the following after all the lines.

    AddModule mod_php5.c

    Then find the AddType block in the file and add the following line after the last AddType statement. This needs to be done no matter what version of Apache you are using. For Apache 2.2.x you need to find the AddType lines in the section . Add a line just before closingfor this section.

    If you need support for other file types, such as ".phtml", add them to the list, for example like this:

    For those using one of the Apache 2 versions, you need to specify the location of the PHP ini file. Add the following line to the end of httpd.conf.

    PHPIniDir "c:/php"

    If you used a different directory, you will need to change c:/php to the correct path. Don't forget to use a forward slash ("/").

    If you are using Apache 1, you have already placed the php.ini file in your Windows folder or somewhere in your PATH. So PHP will have to find it on its own.

    Running PHP 5 as a CGI binary

    If you have configured PHP 5 to load as an Apache module, you can skip this section. It is intended for those who want to configure PHP to run as a CGI binary.

    The procedure for doing this when installing PHP 7 is the same for both Apache 1.x and all versions of the 2.x series.

    Locate the part of the Apache configuration file that contains the ScriptAlias ​​section. Add the line below immediately after the ScriptAlias ​​line for " cgi-bin" If you are using Apache 2.2.x, make sure the line is before closingfor section .

    Please note: If you installed PHP in another location, for example c:Program Filesphp , you need to specify the appropriate path instead c:/php/ (for example, c:Program Filesphp). Don't forget that here we are using the forward slash ("/") instead of the Windows backslash ("").

    ScriptAlias ​​/php/ "c:/php/"

    Apache needs to configure the PHP MIME type. Find the AddType comment block explaining its use and add the following line below it. For Apache 2.2.x, find the AddType lines under . Add the below line just before closing for this section.

    AddType application/x-httpd-php .php

    As with installing PHP as an Apache module, you can add any extensions to make Apache recognize them as PHP scripts, for example:

    AddType application/x-httpd-php .phtml

    Then you need to tell the server to execute the PHP executable every time it encounters a PHP script. Add the following code to the file, for example, after a block of comments explaining " Action«.

    If you are using Apache 2.2.x, then add the code immediately after the AddType statement described above; Apache 2.2.x does not have a comment block " Action«.

    Action application/x-httpd-php "/php/php-cgi.exe"

    Note: The "/php/" part will be recognized as a ScriptAlias, a kind of macro that will be expanded by Apache to "c:/php/" ( or "c:/Program Files/php/" if you installed PHP there). In other words, do not put the path "c:/php/php.exe" or "c:/Program Files/php/php.exe", but use “/php/php-cgi.exe” .

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

    Add the lines below right after the section you just found.

    AllowOverride None Options None Order allow,deny Allow from all

    c) Setting the default index page

    This section applies to the option of installing PHP on Windows as both an Apache module and a CGI binary.

    If you create an index.php file and want Apache to load it as the site's home page, you will have to add another line to the httpd.conf file. Find the line that starts with " DirectoryIndex", and add " index.php" to the list of files. For example, if you had code like this:

    DirectoryIndex index.html

    Apache2.2.2 distribution in the form of 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. When the installer asks you where to install Apache, tell him 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, you must adapt the instructions accordingly to 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 out 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 to work with by default.


    Note

    This instruction 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 Intranet and Internet networks. To operate the server on Intranet and Internet networks, you must enter the real domain name that will be used by the server.

    If the installation process was completed correctly, then upon completion you should already have Apache2.2 running as a service. To check if this is so, open the list of Windows services (“ Start" | "Control Panel" | "Administration" | "Services") and find the line Apache2.2 in it. (or Apache2). Service status: running or not 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 will need a program with a console, such as FAR, WindowsCommander, TotalCommander, etc.

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

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

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


    First launch

    Managing Apache (starting, stopping, restarting) is carried out either through the graphical interface for managing Windows services, or in the console by executing the httpd.exe file with certain keys.

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


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

    Apache commands via console

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


    By default, the root directory of the server is set to the directory c:/Apache2.2/htdocs. It is in it that the index.html file is located, displayed under the name localhost. The directive is responsible for determining the root directory of the site DocumentRoot in the file c:/Apache2.2/conf/httpd.conf.

    DocumentRoot "C:/Apache2.2/htdocs"

    You can change it and make another directory the server's root directory.

    However, before doing this, you should make minimal adjustments to the httpd.conf configuration file. By default, Apache is configured to deny all 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 server root directory to another directory without setting the appropriate permissions, you will receive a 403 Forbidden error and the page shown in the figure.


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

    Find the lines in the file C:/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. When you try to access them, Apache will respond with a 403 Forbidden error. Its counterbalance is 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 simpler and remove (or comment out) the Deny from all directive from the container.


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

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

    Installing PHP

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

    You can download the PHP distribution from our website at . By following the link you can also familiarize yourself with the rules for choosing a distribution and why we took the liberty of offering to download the distribution from our website, and not from the official php.net. When downloading the distribution provided at the link, it is assumed that you will install PHP as a module.

    Unpack the zip archive with php into the c:/php-5.3.5 directory. This completes the PHP installation. Further actions will concern setting up the PHP+Apache combination 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 are installing php in a different directory, you should adapt the instructions given to your situation accordingly.

    Connecting PHP to Apache2.2.2

    Problems connecting PHP to Apache2.2

    If you try to connect the standard php5apache2.dll module to Apache2.2.2, then you will fail. Apache will not want to start, giving 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:
    >>> 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 to 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, immediately after the LoadModule directives. The exact location of these directives is not critical, but they should not be placed at the beginning or 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 severely lacking in Apache1.3, as there was often confusion in php configuration when there were multiple copies of the php.ini file, or when it was placed in the wrong directory.

    The next step is to create a configuration file for PHP. In httpd.conf, the PHPIniDir directive specified the c:/php-5.3.5 directory as the location of the php configuration file. The configuration file itself should 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 this is where all PHP configuration changes should be made.

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

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

    Script phpinfo.php

    echo phpinfo();

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

    Note

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

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


    If the report of the phpinfo() function in the form of “purple tables” is displayed, it means that php is successfully executed by Apache.

    Possible errors

    Apache loads, but instead of the "purple tables" it opens to a blank page.

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

    Must be recorded
    echo phpinfo();
    ?>
    instead of
    echo phpinfo();
    ?>

    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.

    Therefore, it is currently not possible to run modern versions of Apache on Windows XP. Also, Apache will not work on Windows Server 2003.

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

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

    If I haven't convinced you, then follow these 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 separate executable files and website files with databases. This is convenient for server maintenance, including backups.

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

    Go to the directory data and create subfolders there D.B.(for databases) and htdocs(for websites).

    How to install Apache on Windows XP

    Select Custom installation:

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

    Once the installation is complete, open http://localhost/ :

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

    We need to replace a number of lines in it.

    #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

    Save and close the file. That's it, Apache setup is complete! Restart your web server or reboot your computer for the changes to take effect.

    Place your sites in a 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, this is the file we download from the archive.

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

    In a 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, look for the line

    ; extension_dir = "ext"

    and replace it with

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

    Now find a group of lines:

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

    and replace it with:

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

    Now uncomment the lines from this group:

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

    it should look like this:

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

    Restart the web server:

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

    Copy to this file:

    Unpack 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 it there:

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

    For Username, enter root, and leave the password blank.

    Conclusion

    As you can see, although we selected suitable 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.

    This section of the manual applies to Windows 98/Me and Windows NT/2000/XP/2003. PHP will not run on 16 bit platforms such as Windows 3.1 and sometimes we refer to Windows supported platforms as 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 install PHP 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 of zip packages - choose the version that suits the web server you are using:

    PHP package structure and contents

    Unpack the contents of the zip archive into 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 -- initial copy of PEAR | | |-go-pear.bat -- PEAR installation script | |-... | |-php-cgi.exe -- CGI executable file | |-php-win.exe -- executes scripts without an open console | |-php.exe -- PHP executable file for the command line (CLI) | |-... | |-php.ini-development -- default php.ini settings | |-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 that can be used while 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 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.

    Changing the php.ini file

    Once the php package contents are 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 provided in the section Configuring PHP.

    The php.ini file contains 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 performance on Windows. Some of them are optional. There are many other directives that may be useful in your environment - see the list of php.ini directives for more details.

    Mandatory Directives:

      extension_dir = <путь к директории модулей> - 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 = xxxxx.dll- For each plug-in, you must specify the "extension=" directive. Modules from extension_dir marked with this directive are loaded when PHP starts.

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

      error_log = <пусть к файлу лога ошибок> - error_log is needed to indicate the absolute or relative path to the file into which 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 = 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 = 1 - Provides PATH_INFO support according to the CGI specification. IIS FastCGI uses this setting.

      fastcgi.impersonate = 1 - FastCGI under IIS supports the ability to identify the calling client's security tokens. This allows IIS to determine the security context under which the request is being made.

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

    Optional Directives

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

      memory_limit = ###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 = Off- The directive defines which errors should be returned to the web server for further logging. When set to "On", PHP reports all types of errors that are specified in the error_reporting directive. For security reasons, it is recommended to set this to "Off" on production servers to prevent error output from being passed to the end user, as they may contain information that threatens the security of the application.

      open_basedir = <пути к директориям, разделенные точкой с запятой> , for example openbasedir="C:\inetpub\wwwroot;C:\inetpub\temp". This directive specifies the paths to directories in which PHP is allowed to operate on the 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's root directory.

      upload_max_filesize = ###M and post_max_size = ###M- The maximum allowed size of the uploaded file and sent data, respectively. The values ​​of these directives should be increased if PHP applications need to handle large file uploads, such as image or video files.

    After installing PHP on your system, the next step is to select a web server and further 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 with 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

    The FastCGI module is disabled by default when installing IIS. How to enable it varies 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, expand the folder "IIS Services", "Internet Services", "Application Development Components" 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 present 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 given in the installation description

    Comment:

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

    Example #8 CGI and FastCGI settings in php.ini

    fastcgi.impersonate = 1 fastcgi.logging = 0 cgi.fix_pathinfo=1 cgi.force_redirect = 0

    Configure the IIS handler for PHP using the IIS Management Interface or via the 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 php-cgi.exe to execute PHP requests. Replace 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 value of the scriptProcessor parameter 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 IIS for files with a *.php extension, which is the result and processed by the FastCGI module.

    Comment:

    At this step, installation and configuration are complete. The following instructions are optional but highly recommended to achieve optimal PHP functionality and performance on IIS.

    File system representation and access

    When using IIS, it is recommended to enable the 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 if there is a common PHP process for all IIS sites, the sites' PHP scripts will not have access to each other's files as long as IIS uses a different account for each site.

    For example, in the default settings of IIS 7, anonymous authentication is enabled under the standard IUSR user. This means that while giving IIS permission to execute a PHP script, you also need to give the IUSR account permission to read 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.

    To decide which user is used for authentication in IIS 7, you can use the following commands. Replace "Default Web Site" with the IIS name of the site you are working with. On the output, in the XML configuration, look at 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 missing from the anonymousAuthentication element, or is set to the empty string, the application pool identity is being used as anonymous for this website.

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

    Example #12 Setting file access permissions

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

    Setting index.php as default document in IIS

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

    Example #13 Setting index.php as 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 the commands is given below. The FastCGI instanceMaxRequests option sets the maximum number of requests that can be processed by one php-cgi.exe process before IIS starts disabling them. The PHP environment variable PHP_FCGI_MAX_REQUESTS sets how many requests one 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 Setting up FastCGI and PHP recreated

    %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 timeout parameter for FastCGI is done if there is a long-running PHP script. Two parameters control the timeout: 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 under Apache, they are quite simple for a beginner. Please refer to the Apache documentation for further configuration instructions.

    Don't forget to reboot the server after changing the configuration file. For example, teams NET STOP APACHE And NET START APACHE, if Apache is running as a Windows service, or using regular shortcuts.

    Comment:

    Installing PHP as an Apache module

    You need to add the following lines to the 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 this is not the case.

    # 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

    Installation as a binary CGI file

    If PHP is unpacked to C:\php\ as described in the Manual Installation Steps section, you need to add the following lines to the Apache configuration 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 Safety"

    When installing PHP as CGI, there is no such convenient option for syntax highlighting of PHP sources as when installing as a module. If you want to use it, you need to 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 contains instructions for installing PHP for Apache 2.x on Microsoft Windows systems.

    Comment: Apache 2.2 support

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

    You are strongly encouraged to review the » Apache Documentation to gain a basic understanding of Apache 2.x Server. Also, before reading this help, please note the » Windows Best Practices 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 correct this situation.

    Download the most current version of » Apache 2.x and the appropriate version of PHP. Follow the Step-by-Step Installation Guide and come back to continue the PHP and Apache integration.

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

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

    Installing PHP as a handler under Apache

    You need to add the following lines to your Apache httpd.conf configuration file 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 # configuring the path to php.ini PHPIniDir "C:/php"

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

    The above configuration will allow PHP to process 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 handler. 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 documentation » Apache CGI 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 the CGI directory using the ScriptAlilas directive.

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

    Example #20 PHP as CGI under Apache 2.x

    #!C:/php/php.exe

    Attention

    By using a CGI installation, your server is open 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 a number of advantages over running it as CGI. Installation is quite 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=PHPScript ftype PHPScript=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 >= 6) or obj.conf (for servers< 6) and add the following: You should place the lines after mime types init.

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

      (PHP >= 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 = "GPCS" register_globals = On

      Special use for error pages or self-made directory listings (PHP >= 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="php4_execute" code=XXX script="/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="magnus-internal/directory" in obj.conf with the following:

      Service fn="php4_execute" type="magnus-internal/directory" script="/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 for working with the Sambar server under Windows.

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

        Open mappings.ini and add the following line under :

        Example #22 ISAPI configuration for Sambar

        #for PHP 4 *.php = c:\php\php4isapi.dll #for PHP 5 *.php = 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 will need to change the account that is used by the Sambar server service. By default this is LocalSystem and remote resources will not be accessible. The account can be edited using the Services option of the Administrative 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 OS

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

      We continue to build a local WAMP server on a local machine (personal computer). In this article, we install the PHP interpreter, also known as the [P] in the WAMP acronym.

      Let me remind you that the Apache+MySQL+PHP assembly is necessary to work on creating a website on your computer as a local server. The task is interesting to many and often used for working on projects. Self-assembly of AMP is a complex task associated with setting up the computer and making sure it is always in good working order. For many, this is easier than working with remote servers, because computer help is always at hand. In addition, working with a local server is free.

      In previous articles I talked about how, how. We are building a local server running Windows 7. It's time to install PHP.

      We will install PHP in the php folder created on the system drive: C:\Program Files\PHP.

      Where to get PHP

      We download the latest version of php only from the official website, here is the link: https://php.net/downloads.php. another one: https://windows.php.net/download#php-7.0. We won’t take the latest version of php7.0; we’ll take the not so “revolutionary” PHP 5.6 (5.6.20). I take an assembly for the 32-bit architecture of Windows 7 with a built-in Windows installer.

      Installing PHP with installer (MSI)

      Latest PHP with installer and most importantly with Apache 2.2 module. this is php-5.3.10-nts-Win32-VC9-x86.msi. Let's take it here: https://windows.php.net/downloads/releases/archives/ we’ll put it there.

      Note: We choose with the Apache 2.2 module, since we are building WAMP on Apache 2.2, which we have already installed.

      Installing PHP using the installer (MSI) is simple, in several windows:

      1. Run the downloaded file php-5.3.10-nts-Win32-VC9-x86.msi.

      The first php-5.3.10 installation window

      2. We get acquainted with the license and, having agreed with it, move on by clicking the “Next” button.

      3. On this page we specify the folder in which we install PHP. Let this be a directory:

      4. On the next page, select the web server to use. In our build this is Apache2.

      5. On this page you need to select the PHP modules that we will need. To be on the safe side, we choose everything.

      6. Click “Install”


      Click Install to install php-5.3.10
      We see the php-5.3.10 installation window process

      All! The installation of PHP on your local computer is complete.