Installing php 5 3. Installing on older versions of Windows

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 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 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 of the zip packages - choose the version that suits your web server:

PHP package structure and content

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 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 - default php.ini settings | | -php.ini-production - recommended php.ini settings | | -php5apache2_2.dll - only in multi-threaded version | | -php5apache2_2_filter.dll - only in multithreaded 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 contents of the php package have been 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 performance 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 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 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 caller's security tokens. 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 that this be set to "Off" on production servers to prevent the transmission of error output to the end user, as they may contain information that could threaten 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 with the file system are allowed. 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 then configure it to work with PHP. Select a specific web server in the table of contents for this article.

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 executable 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. The following instructions are optional, but highly recommended for achieving optimal PHP functionality and performance on IIS.

File system view and access

When using IIS, it is recommended that you 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 settings of IIS 7, 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 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 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.

While 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 need to 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 real PHP path.

Attention

"CGI Security"

When installing PHP as a 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 the Apache 2.2 DLL is called php5apache2_2.dll, not php5apache2.dll, and 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 on 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 put 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

Using a CGI setup, 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. The 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

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

    Let me remind you that the assembly of Apache + MySQL + PHP is necessary to work on creating a website on your computer, as a local server. The task is interesting to many and often used to work on projects. Self-assembly of AMP is a complex task associated with setting up a computer and its permanent health. For many, this is easier than working with remote servers, because computer assistance is always at hand. Besides, working with a local server is free.

    In previous articles I told you how, how. We build the local server under 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 take the latest version of php only on the official website, here is the link: https://php.net/downloads.php... another one: https://windows.php.net/download#php-7.0. We will not take the latest version of php7.0, let's take the not so "revolutionary" PHP 5.6 (5.6.20). I am taking an assembly for Windows 7 32-bit architecture with built-in Windows installer.

    Install PHP with Installer (MSI)

    Latest PHP with installer and most importantly with Apache 2.2 module. it is php-5.3.10-nts-Win32-VC9-x86.msi. We take it here: https://windows.php.net/downloads/releases/archives/ and put it.

    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.

    First window of php-5.3.10 installation

    2. Get acquainted with the license and agreeing with it, go further by clicking the "Next" button.

    3. On this page, set the folder where PHP is installed. Let it be a directory:

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

    5. On this page, you need to select the PHP modules that we will need. For safety reasons, we choose everything.

    6. Click "Install"


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

    All! PHP installation on your local machine is complete.

    PHP is an abbreviation for Hypertext Processor (Hypertext Processor). It is a general-purpose open-source scripting language that is widely used in web development due to its ability to be embedded in HTML. Used to write pre-written programs that are later used to automate tasks. PHP scripts are commonly used on Linux, Unix, Windows, Mac OS and other operating systems. When you use PHP in web development, you can choose your web server and main operating system.

    Here's a step-by-step procedure for installing PHP 5.6 versions on Ubuntu 18. The commands and procedures mentioned in this article are executed on Ubuntu 18.06 LTS.

    This article uses the Ubuntu command line, Terminal. You can open the Terminal application through the system menu or the keyboard shortcut Ctrl + Alt + t.

    PHP can be downloaded from the official site http://php.net/releases/ in source form and compiled. We will describe the installation of PHP through the Ondrej PPA repository as a ready-made package.

    Installation

    To install PHP 5.6, you need to add to the system Personal Package Archive (PPA) - a repository with unofficial packages from developers who want to publish their own packages.

    To work with PPA, you need to install the following software:

    Sudo apt-get install software-properties-common

    After that, you can add the ondrej / php repository.

    Sudo add-apt-repository ppa: ondrej / php

    This repository contains all current PHP versions at the moment.

    After adding the Ondrej repository, you need to update the index of the repositories on your system. This is required to install the latest available software version. Enter the following command:

    sudo apt-get update


    Direct link: php-5.3.10-Win32-VC9-x86.zip
    At the same time, download the documentation in Russian in the .chm format right away, you will need it when studying and working: php_enhanced_ru.chm

    Unpack the archive to the desired directory (initially "C: \\ php" is suggested). Open the configuration file containing the recommended settings - "php.ini-development" (located in the root of the distribution kit), rename it to php.ini and make the following changes.

    Php.ini revision:

    1. Find the line:
      post_max_size \u003d 8M
      Increase the maximum size of data accepted by the POST method to 16 MB by changing it to:
      post_max_size \u003d 16M
    2. Find the line:
      ; include_path \u003d ".; c: \\ php \\ includes"
      Uncomment it by removing the semicolon in front of the line.
      (Warning exception! Backslashes when specifying a path):
      include_path \u003d ".; c: \\ php \\ includes"
      Create an empty directory "C: \\ php \\ includes" to store the included classes.
    3. Find the line:
      extension_dir \u003d "./"
      Set the value of this directive to the path to the folder with extensions:
      extension_dir \u003d "C: / php / ext"
    4. Find the line:
      ; upload_tmp_dir \u003d
      Uncomment it and specify the following path in the value:
      upload_tmp_dir \u003d "C: / php / upload"
      Create an empty folder "C: \\ php \\ upload" to store temporary files uploaded via HTTP.
    5. Find the line:
      upload_max_filesize \u003d 2M
      Increase the maximum allowed upload size to 16MB:
      upload_max_filesize \u003d 16M
    6. Connect, uncommenting, the extension library data:
      extension \u003d php_bz2.dll
      extension \u003d php_curl.dll
      extension \u003d php_gd2.dll
      extension \u003d php_mbstring.dll
      extension \u003d php_mysql.dll
      extension \u003d php_mysqli.dll
    7. Find the line:
      ; date.timezone \u003d
      Uncomment and set the value to the time zone of your location (see the documentation for a list of time zones):
      date.timezone \u003d "Europe / Moscow"
    8. Find the line:
      ; session.save_path \u003d "/ tmp"
      Uncomment and set the value of this directive to the following path:
      session.save_path \u003d "C: / php / tmp"
      Create an empty folder "C: \\ php \\ tmp" to store temporary session files.
    Save changes and close php.ini file.

    Next, you need to add the directory with the installed PHP interpreter to the PATH of the operating system. To do this, go to "Start" -\u003e "Control Panel" -\u003e "System", open the "Advanced" tab, click the " Environment Variables ", under" System Variables "double click on the" Path "line, add in the" Variable Value "field, in addition to exists, the path to the directory with PHP installed, for example, "C: \\ php" (without quotes). Note that the semicolon character separates the paths. Restart your operating system for the changes to take effect.

    Example of a Path string:
    % SystemRoot% \\ system32;% SystemRoot%;% SystemRoot% \\ System32 \\ Wbem; C: \\ php; C: \\ Program Files \\ MySQL \\ MySQL Server 5.5 \\ bin

    Installation and configuration of PHP interpreter - completed.

    Description of the connected libraries:

    php_bz2.dll - With this extension PHP will be able to create and unpack archives in bzip2 format.

    php_curl.dll - A very important and necessary library that allows you to connect and work with servers using a huge number of Internet protocols.

    php_gd2.dll - Another indispensable library that allows you to work with graphics. Did you think you can only generate HTML pages in PHP? But no! You can do almost anything with PHP, including drawing.

    php_mbstring.dll - The library contains functions for working with multi-byte encodings, which include encodings of oriental languages \u200b\u200b(Japanese, Chinese, Korean), Unicode (UTF-8) and others.

    php_mysql.dll - The name of the library speaks for itself - it is required to work with the MySQL server.

    php_mysqli.dll - This library is an extension of the previous one and contains additional PHP functions for working with MySQL server version 4.1.3 and higher.

    These libraries should be enough for PHP to work properly. Over time, if the need arises, you will be able to connect additional libraries, but you should not connect them all at once with the thought that you will not spoil the porridge with butter, in this case, an excessive number of connected libraries can significantly slow down PHP's work.

    «

    This article provides a step-by-step guide to installing PHP to work with 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 configuration steps

    1. Download PHP 5

    Before getting started, download a copy of PHP 5 from download pages... Download the protected VC6 package from the Windows Binaries section - that is, don't 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, only 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 for PHP on your hard drive. I suggest c: php, although you can use a different folder name and location. I personally prefer not to use names with spaces.

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

    3. For those who update the package: Delete the old PHP.INI file from the Windows directory

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

    4. PHP configuration

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

    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 do not need to do this if you are using Apache 2, since later we will specify the directive with the location of the php.ini file in the Apache 2 configuration 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 php.ini file. You may need to make the following changes to the file:

    a) Including short open tags

    Find the following line:

    short_open_tag \u003d Off

    If short_open_tag is set to off, tags like “

    Since many third party PHP scripts use the “

    short_open_tag \u003d On

    b) Magic quotes

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

    magic_quotes_gpc \u003d Off

    and replace it with:

    magic_quotes_gpc \u003d On

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

    c) Using global variables

    A number of old 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”, old PHP scripts assume that the PHP processor will automatically create a variable named $ something that contains the value specified through that field.

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

    register_globals \u003d Off

    and change it to:

    register_globals \u003d On

    Warning: when installing PHP on Windows, don't do this unless you have third-party scripts that need it to work. When writing new scripts, it is always best to assume that the register_globals element is set to “ Off«.

    d) Error Display

    On a live site, script errors are typically logged without being displayed 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, find the following line:

    display_errors \u003d Off

    and change it to:

    display_errors \u003d On

    This parameter should always be set to Off on a live site.

    e) Session path

    If the script uses sessions, find the following line:

    ; session.save_path \u003d "/ 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 a different folder. One way is to create a folder named c: tmp ( as previously we created c: php) and specify this folder for this parameter. If you do, change this line as follows:

    session.save_path \u003d "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 like c: phptmp and adjust the config file accordingly. There are 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

    When installing PHP 5 5, if the script uses the mail () function and you want the function to successfully send mail on the local machine, find the following section:

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

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

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

    Note that after that, 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 the script, the function will return a failure code and display an error message.

    How to set up Apache for PHP 5

    There are two ways to install Apache PHP. First: set it up to boot PHP interpreter as an Apache module. Second, configure it to run the interpreter as a binary CGI. Only one of them needs to be applied. Select the module method if PHP is also installed on the hosting as an 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 GroupApache2confand 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.

    Find the section of the file with the LoadModule statements. Declarations preceded by a 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 PHP installation example 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 regardless of which 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 closing for this section.

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

    For those using one of the versions of Apache 2, you need to specify the location of the PHP ini file. Add the following line to the end of your 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 the forward slash ("/").

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

    Running PHP 5 as a CGI Binary

    If you 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 this when installing PHP 7 is the same for both Apache 1.x and all versions of the 2.x series.

    Find the portion of the Apache config file that contains the ScriptAlias \u200b\u200bsection. Add the below line just after the ScriptAlias \u200b\u200bline for “ cgi-bin". If using Apache 2.2.x make sure the line is before the close for section .

    note: if you installed PHP in a different location, for example c: Program Filesphp, you need to specify the appropriate path instead of c: / php / (e.g. c: Program Filesphp)... Remember that we're using a simple forward slash ("/") here instead of the Windows backslash ("").

    ScriptAlias \u200b\u200b/ php / "c: / php /"

    Apache needs to configure the PHP MIME type. Find the AddType comment block explaining its usage and add the following line below it. For Apache 2.2.x find the AddType lines under ... Add 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 so that Apache recognizes 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 the comment block explaining “ Action«.

    If you are using Apache 2.2.x, add the code right after the AddType statement 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 ScriptAlias, a kind of macro that Apache will expand 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" in this directive or "C: / Program Files / php / php.exe"and 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 refers to the option to install PHP on Windows as both an Apache module and a binary CGI.

    If you are creating an index.php file and you want Apache to load it as the home page of your site, you will need to add another line to your 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