Installing PHP. Installing and configuring PHP Installing and configuring PHP

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 only be used 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 start

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 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 provided to suit your situation.

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, you will fail. Apache will not want to start, giving the message shown in the picture.


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 greatly lacking in Apache1.3, as it often caused confusion in php configuration when there were multiple copies of the php.ini file, or when placing it 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 mistakes

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();
?>


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

Unpack the archive into 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), rename it php.ini and make the following changes.

Editing php.ini:

  1. Find the line:
    post_max_size = 8M
    Increase the maximum data size accepted by the POST method to 16 MB by changing it to:
    post_max_size = 16M
  2. Find the line:
    ;include_path = ".;c:\php\includes"
    Uncomment it by removing the semicolon before the line.
    (Attention exception! Backslashes when specifying path):
    include_path = ".;c:\php\includes"
    Create an empty directory "C:\php\includes" to store the included classes.
  3. Find the line:
    extension_dir = "./"
    Set the value of this directive to the path to the folder with extensions:
    extension_dir = "C:/php/ext"
  4. Find the line:
    ;upload_tmp_dir =
    Uncomment it and specify the following path in the value:
    upload_tmp_dir = "C:/php/upload"
    Create an empty folder "C:\php\upload" to store temporary files uploaded via HTTP.
  5. Find the line:
    upload_max_filesize = 2M
    Increase the maximum allowed file upload size to 16 MB:
    upload_max_filesize = 16M
  6. Connect, uncommenting, the extension library data:
    extension=php_bz2.dll
    extension=php_curl.dll
    extension=php_gd2.dll
    extension=php_mbstring.dll
    extension=php_mysql.dll
    extension=php_mysqli.dll
  7. Find the line:
    ;date.timezone=
    Uncomment and set the value to the time zone of your location (a list of time zones can be found in the documentation):
    date.timezone = "Europe/Moscow"
  8. Find the line:
    ;session.save_path = "/tmp"
    Uncomment and set the value of this directive to the following path:
    session.save_path = "C:/php/tmp"
    Create an empty folder "C:\php\tmp" to store temporary session files.
Save your changes and close the 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, follow the path "Start" -> "Control Panel" -> "System", open the "Advanced" tab, click the " button Environment Variables", in the "System Variables" section, double click on the "Path" line, add "Variable Value" to the field, to what is already there exists, the path to the directory with PHP installed, for example, "C:\php" (without quotes). Note that the semicolon character separates the paths. For the changes to take effect, restart your operating system.

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

Installation and configuration of the PHP interpreter is completed.

Description of connected libraries:

php_bz2.dll– Using 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! With PHP you can do almost anything, including drawing.

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

php_mysql.dll– The name of the library speaks for itself - it is necessary 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 the 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 won’t spoil the porridge with butter; in this case, an excessive number of connected libraries can noticeably slow down PHP.

«

Hello, my dear readers! I really hope that today’s article will be useful not only to inexperienced network users, but also to experienced users who are confused about the features of various hosting systems.

I want to tell you how to configure php on . In general, the setup process involves adjusting the data in the php.ini system file.

Basic Concepts

Рhp.ini– a file document that contains directives (configuration and settings) that determine the behavior of PHP (in particular a specific site).

Interpreter– a program that reads and executes program code line by line. First, it looks for settings in php.ini. And then it goes to the directory itself, specified in the PHP RC text variable.

After manually editing any PHP file, it is important not to forget to leave its name unchanged, otherwise the interpreter will not be able to find it!

This information is purely generalized; in practice it should be clearer.

Choose one of the options

Option number 1 for those who use cPanel as an administrative panel.

Look for the “Configuration” section in the menu, where the PHP parameters for hosting are published.

You can even change the PHP version here. There are providers that give almost unlimited opportunities to users for independent adjustment, but there are also those that very strictly control any changes, and you cannot act without their knowledge.

If your hosting allows you to configure PHP, then you are lucky. If not, then move on to option No. 2 - contact technical support for help.

Step-by-step instructions or redefine php.ini in your own way

We find the original settings file.htaccess and enter the following data into it:

chmod 755 php5.fcgi

Well, that's all, let's use it.

There are some clarifications to this step-by-step instructions. When creating the php5.fcgi file, you should use the current unix settings (line break), that is, write information in the file with the /n tag. And if error 500 occurs, you should check the php-error.log file, where you will most likely find the problem.

A couple more settings are important:

disable_functions– allows you to block calls to several functions within safe mode.

Note! The user indicates the list of such functions independently, separated by commas;

memory_limit– allows you to configure the parameters of the maximum amount of memory required to execute scripts.

And finally, I’ll add: in order to view the settings and find out the PHP version, you need to create a php file (the name doesn’t matter), in which you should write the following code:

That's all, go for it! Don't forget to tell your friends on social media. networks about new material you have read, and subscribe to the mailing list of notifications about the revision of the next article. See you!

With respect! Abdullin Ruslan

Last update: 12/16/2017

There are different ways to install all the necessary software. We can install components separately, or we can use ready-made assemblies like Denwer or EasyPHP. In such assemblies, the components already have initial configuration and are ready for creating websites. However, sooner or later, developers still have to resort to installing and configuring individual components and connecting other modules. Therefore, we will install all components separately. Windows will be used as the operating system.

What does installing PHP involve? First, we need a PHP interpreter. Secondly, we need a web server, for example, Apache, with which we can access the resources of the site we are creating. Third, since we will be using databases, we will also need to install some kind of database management system. MySQL was chosen as the most popular in conjunction with PHP.

To install PHP, let's go to the developers' website http://php.net/. On the downloads page we can find various distributions for the Linux operating system. If our operating system is Windows, then we need to download one of the packages from the page http://windows.php.net/download/.

Download the zip package of the latest PHP release:

Generally, the latest PHP release has two versions: Non Thread Safe and Thread Safe. We need to select the Thread Safe version. This version has options for 32-bit and 64-bit systems.

Let's unpack the downloaded archive into a folder called php. Let this folder be located at the root of drive C.

Now we need to do some minimal PHP configuration. To do this, go to the c:\php directory and find the file there php.ini-development. This is the initial configuration file for the interpreter. Let's rename this file to php.ini and then open it in a text editor.

Let's find the line in the file:

; extension_dir = "ext"

This line points to the directory with plug-in extensions for PHP. Let's uncomment it (removing the semicolon):

Extension_dir = "ext"

Since all extensions are in the ext directory.

Since we will be using MySQL databases, we need to specify the extension in php.ini. By default, it is already in the file, only it is commented out:

;extension=mysqli

Let's uncomment it by removing the semicolon:

Extension=mysqli

Now by default this library will be used when working with the database. We can also uncomment other extensions if necessary. But for starters, one is enough for us.

We will leave the rest of the file contents unchanged.

Now let's install the web server.

The article describes the installation of Apache 2.4 + PHP 5.6 + MySQL 5.6 on the Windows 7 / 8 / 8.1 / 10 operating system

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

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

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

If in the process of assembling the server according to these instructions you encountered problems and still consider yourself a WEB developer, then it would be the right step to understand the problems that have arisen, and not write in the comments that the instructions are crap. The instructions are working. Tested by time and hundreds of installations. Be careful when performing simple steps. Performing steps manually and analyzing situations, if it doesn’t work, will add skill to you as a developer. If you are not a WEB developer and do not plan to be one, then look for an easy installation method on the Internet - these instructions are not for you.

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

Preparatory work

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

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

If you have Skype, be sure to disable the use of port 80 in the settings. Ultimately, you need to make sure that no services are using port 80.

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

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

In the catalog www create index files (using a file manager or code editor) that will be needed to check that everything is working:

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

If you don't have a file manager/code editor/IDE, download the archive with these two files. But, if you consider yourself a WEB developer, you must acquire the tools.

Add to the PATH system variable:

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

Notes!

The line numbers given in the example configuration files may differ for other versions of apache and php.
All commands, including editing files, must be performed as Administrator.

Installing Apache 2.4

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

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

Installing PHP 5.6

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

Virtual Hosts in Apache

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

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

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