Computer lessons

Installing and configuring PHP. Installing PHP for Windows OS Installing php 5 for windows 7

At htmlAcademy and I work there as a mentor. As part of the intensive course, students will have to improve their work environment and this note is aimed at simplifying this difficult task for a beginner. There are different ways to raise a full-fledged LAMP stack, but we will go the classic way. Let's configure all components separately (without using ready-made combines) and start with PHP (there will definitely be a note discussing ready-made LAMP assemblies). Since I plan to work as mentors at PHP intensives in the future, I am going to write similar instructions for repetition in other operating systems (Linux, macOS). As they say, it’s better to sweat once, but then it will become easier for everyone. So let's get started.

Download PHP for Windows

Go to the official website and download the current version of PHP. At the time of writing, this is - 7.1.4 . There are several distribution options available on the page. I have Windows 7 x64, so I choose a zip archive with VC14 x64 Thread Safe.

Please note that there are two distribution options available for download: Thread-Safe (TS) And Non-Thread-Safe (NTS). The choice depends on how you plan to use the interpreter. TS is recommended to be used for a single web services process (for example, configured via the mod_php module for Apache). NTS is recommended for using IIS (Internet Information Service) and alternative FastCGI web servers (for example, Apache with the FastCGI module) and command line.

Install PHP 7.1

Let's start preparing PHP for comfortable work from the command line. In the previous step, you downloaded the archive with the PHP distribution. Unlike most programs, PHP is supplied in a simple archive, and not as an installation package. Therefore, you will have to extract the files yourself to any directory convenient for you. I prefer to store such things in the root of the system drive. Create a directory in the root of the “C:” drive (or any other place) "php" and extract the contents of the downloaded archive into it.

Many files will appear in the directory, but we are most interested in:

  • go-pear.bat– script for installing PEAR. You can read more about PEAR in the official documentation.
  • php.exe– allows you to execute PHP scripts from the console;
  • php-win.exe- allows you to execute PHP scripts without using the console;
  • php-cgi.exe– required for executing PHP code in FastCGI mode;
  • php7apache2_4.dll– integration module with the Apache 2.4.X web server;
  • phpdbg.exe– debugger;
  • php.ini-development– example of a PHP configuration file for a development environment
  • php.ini-production– example of a PHP configuration file for a production environment

Connecting the configuration file

We have the unpacked distribution kit, let's connect the configuration file for it. We are going to do experiments, so we will take as a sample php.ini-development. Make a copy of this file to your php directory ( C:\php) With name php.ini. IMPORTANT! Make a copy, not a simple rename. During development, you may need to change the configuration file and there is every chance of making a mistake that will be difficult to detect.

In such cases, there is nothing better than returning to the reference settings. In our case, it will be enough to copy the file again php.ini-development V php.ini. So, at the end of the actions, the php.ini file should appear in the directory with php. In further notes we will definitely talk about its contents in more detail.

Testing PHP from the command line

At this step, the so-called “installation” is completed. Open your console ( cmd.exe, the shortcut is available in the Accessories menu) and enter the command:

C:\php\php.exe --version

The result will be something like this:

PHP 7.1.4 (cli) (built: Apr 11 2017 19:54:37) (ZTS MSVC14 (Visual C++ 2015) x64) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998 -2017 Zend Technologies

The result confirms that PHP is working. For example, try creating a new script file (I created the “test.php” file right in the root of the “C:” drive) and place the text in it:

Now try executing this file and see the result:

C:\php\php.exe –f test.php

Function phpinfo() displays PHP configuration information in a convenient form. We'll talk about this function later.

Simplifying access to php.exe

PHP is ready to work, but you must admit that entering the path to the PHP interpreter into the console every time is quite inconvenient. To make your life easier, let's make some small changes to the environment variables. Let's launch the applet in the control panel "System"(or just press the hotkey "Windows + Pause Break". Then click on the button "Change settings". In the window that appears "Properties of the system", let's go to the bookmark "Additionally". Find and click on the button "Environment Variables".

Find a variable in the list "PATH" and press the button "Change", the variable editing window will appear. In the “Variable value” field we need to add the path to the directory with PHP. Go to the very end of the line and, separated by semicolons, indicate the path to the directory with PHP: C:\php;

That's it, click "Ok". Now reboot the system (alas, you have to). After restarting Windows, you can access PHP simply: php. For example, to display the version name, just write:

Php –version

And to interpret the test.php file located in the root of the “C:” drive:

Php –f C:\test.php

Or even launch the built-in web server:

Php -t C:\ -S 127.0.0.1:8888 Listening on http://127.0.0.1:8888 Document root is C:\ Press Ctrl-C to quit.

To test, open a web browser and try going to http://127.0.0.1:8888/test.php. Please note that after the parameter –t we specify the path to the directory that will become the root directory of the web server. All scripts located in this folder will be available for request from the client. I have one file on drive “C:” 1.php and that is exactly what I am asking for.

Assoc .php=phpfile ftype phpfile="C:\php\php.ee" -f "%1" -- %~2

A little more about environment variables

Now let's talk about how PHP will look for the configuration settings file (remember, php.ini). The documentation provides a complete search chain. To avoid unnecessary complications, I recommend immediately adding a new one to the environment variables - "PHPRC" and as a value specify the path to the directory with the configuration file. My config is located in the same directory as the main php files, therefore I specify the value of the variable -

"C:\php". A reboot will be required after making the change.

That's all for me. The first part of the manual for beginners is ready.

Developer's website: http://www.php.net/
Distribution(VC9 x86 Thread Safe, Zip archive): http://windows.php.net/download/
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 “ 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.

Original article: http://php-myadmin.ru/learning/instrument-php.html

From the author: one acquaintance (also a “crooked craftsman”) decided to assemble the cabinet himself. As a result, after several hours of torment, he only got a table. Such a metamorphosis happened. To avoid finding yourself in a similar situation, let's look at how to install PHP correctly.

What PHP won't work without

– not a regular language, but a server language. Because of this, simply installing a language interpreter will not be enough. In order for you to be able to run the code on your personal computer, you will need a local server.

There is plenty of such goodness on the World Wide Web. We will not list the advantages and disadvantages of each server. Instead, we will describe the installation process of a time-tested option - Apache, which everyone has long associated with PHP development.

The history of this product is described in detail on Wikipedia. Since the reliability of Apache has been proven by many years of “ruthless” use, it will not waste its precious time proving it. Let's try to install a PHP server on a Windows PC ourselves.

Installing the “Indian”

Let's look at the step-by-step installation of a server from the Apache Indian tribe:

We go to Apache.org, in the menu on the right click on “Download”. After that, in the provided list of mirrors, select any one and download the installation with the extension .msi (native format for Windows) and version no lower than 2.2

Since the project is open source, many assemblies of this server have now been released. If you can't find the one listed, go to this address. Here on the mirror native versions of Apache are available for download.

After downloading, we launch the installation package for execution. The installation procedure is standard: we agree to the terms of use, indicate the domain and server name, and the administrator’s “soap”. Then "Next".

Specify the directory where the Apache PHP server should be installed.

And we wait for the software installation process to complete. Go to the directory where Apache was installed. In the configuration folder we find httpd.conf and open it. Find the line “Deny from all” and comment on this directive. This way we remove the built-in server protection, which is not needed for local use of Apache. That is, we open access to all folders, including virtual ones. If this is not done, the program will display a “403” error when trying to access any of the directories.

Save all changes and restart the server.

Let's move on to PHP

We go to php.net and download one of the “86” versions of the distribution (better protected). Then unpack it in a separate folder on the same drive as the server. I will not fully describe all the language settings that can be changed. You can read more about this in the accompanying technical documentation.

I would like to note that all PHP settings are specified in the php.ini file. It opens using any editor (including Notepad). Here is a description of several frequently used parameters that are set through this file:

post_max_size – sets the maximum amount of data that can be processed at a time using the POST method.

upload_max_filesize – the maximum size of files that can be uploaded.

default_charset – using this parameter you can set the default encoding in PHP to utf 8.

Now, for complete happiness, all that remains is to write a few lines in httpd.conf. With their help, we will connect PHP to the local server so that it works as an Apache module. This is quite enough for writing and testing code at home. These lines should be placed in the middle of the file:

LoadModule php5_module path to PHP installation/ php5apache2_2.dll – connects the library with which the distribution will be used as a module.

PHPIniDir “path to the php.ini/ file” (for example, PHPIniDir “F:/php-5.3.5/”) - it’s clear without words.

AddType application/x-httpd-php phtml php – configures the mapping between PHP files and the mime type (application/x-httpd-php).

So how? Setting up takes time, attention and skill. Have you ever thought that the easiest thing is an already assembled “cabinet”. Although in our case, a cabinet means a ready-made software package, which includes PHP, a server, and a DBMS. It is clear that we are talking about Denver. Thanks to him, no “cabinet” will be able to turn into some kind of “table” or “bedside table” under the “skillful” hands of a specialist.

PHP is a general-purpose scripting language primarily used in web application development.

Installation

The PHP interpreter comes in several variants for different interpreter launch modes.

CLI

To install PHP-CLI run:

sudo apt-get install php5-cli

CGI

To install PHP - CGI run:

sudo apt-get install php5-cgi

FastCGI

To install PHP -FPM run:

sudo apt-get install php5-fpm

Module for Apache

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

Do not install several PHP accelerators at once, this will not give any result.

Alternative PHP Cache

Since Ubuntu Saucy (13.10) package php-apc doesn't install the opcode cacher, instead it installs the package php-apcu with part of the functionality (caching user data).

Apt-get install php-apc

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

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

XCACHE

Apt-get install php-xcache

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

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

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

Xcache.count= 2

And today we will talk about PHP installation. As with Apache, there is nothing complicated here. If this is your first time borrowing installing and configuring PHP on your local machine, then you will find it helpful to read this guide with pictures. If you are already an experienced bison in these matters, then you can safely skip this note.

So, if you are reading this post, then either you are installing PHP for the first time, or you are having questions/problems during the process of installing or configuring PHP. I will try to describe this process in as much detail as possible.

First, we need a distribution with the latest version of PHP. It can be downloaded from the official website – www.php.net (9.5 Mb).

Download the distribution kit to your computer, choosing a mirror that is geographically closest to you

Extract the contents of the archive into a folder C:/php5. Again, if this is your first time installing the Apache -PHP-MySQL combination, I recommend installing it using the paths I specified.

So, in C:/php5 you should have the following:

The PHP installation is complete, now let's configure it.

Rename the file php.ini-recommended V php.ini:

  • select a file
  • press F2
  • remove -recommended
  • press Enter.

Now let's open the file in Notepad and get started PHP settings. The file contains quite a large number of PHP settings, but we don’t need them now. We'll only do the basic setup that will allow us to run PHP on our local machine.

A little about the description format in the settings file

The ';' symbol means that the lines are commented out (they will not be taken into account). For example:

; ignore_user_abort = On

As you may have noticed, the settings are divided into groups for ease of searching through the file. For example, resource limitation management settings:

;;;;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;;;;

max_execution_time = 30 ; Maximum execution time of each script, in seconds.
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB)

Format for describing parameters and their values:

variable_name = its_value

Setting up PHP modules.

Find a section Dynamic Extensions(dynamic extensions). There is a fairly large list of modules for PHP:

;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mbstring.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll

;extension=php_ming.dll
;extension=php_msql.dll
;extension=php_mssql.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
;extension=php_pdo.dll

;extension=php_pdo_mssql.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll

;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_soap.dll
;extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll

When each module is connected, it takes up a certain amount of operating memory. For work, we will connect only those modules that we definitely need, and the rest can be connected as needed.

In order to connect the module, you need to remove the ‘;’ symbol before the line. Thus, we will uncomment the line and the module will be used.

Let's enable the PHP extension for working with graphics - php_gd2.dll(we will need it in the future).

In order for PHP to find where the extensions are located, we indicate the path to them. Add the following line before or after connecting extensions. As a result, you should get the following:

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions;
;;;;;;;;;;;;;;;;;;;;;;
;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example, on Windows:
;
; extension=msql.dll
;
; ...or under UNIX:
;
; extension=msql.so
;
; Note that it should be the name of the module only; no directory information
; needs to go here. Specify the location of the extension with the
; extension_dir directive above.

; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.

extension_dir=”C:/php5/ext”

;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mbstring.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_msql.dll
;extension=php_mssql.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
;extension=php_pdo.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.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
;extension=php_snmp.dll
;extension=php_soap.dll
;extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_zip.dll

We save the changes we have made. For the settings we made to take effect, you need to restart Apache.

Installing and configuring PHP completed!

As you can see, nothing complicated. If during your work you need other extensions, simply uncomment the line with the extension you need (similar to php_gd2.dll) and restart Apache.

In the next post, I will tell you how to get PHP and Apache to work together.