Installing and configuring PHP. Installing PHP under Windows OS Reinstalling php

Last update: 16.12.2017

Eat different ways installation of everything 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 setup and are already ready to create 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 operating system Linux systems. 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:

Usually, latest issue PHP 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 bases MySQL data, then 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.

This description is suitable for any edition of Windows 7/8/8.1.

Installing Apache Web Server

First of all, download the Apache distribution from the site: http://www.apachelounge.com/download/. In the list of distributions Apache 2.4 binaries VC11, we need to download "httpd-2.4.7-win64-VC11.zip".

After downloading, open the archive httpd-2.4.7-win64-VC11.zip

Extract the Apache24 folder from it to the C:\ drive partition

Now we need to tweak the config a little before installing Apache. Open the httpd.conf file (located here: C:\Apache24\conf) preferably via convenient editor, for example notepad++. Find the line (217) ServerName www.example.com:80 and change it to ServerName localhost:80

Here we need to specify the full path to the httpd.exe file, which is located in the Apache folder. In our case, this is C:\Apache24\bin\httpd.exe. Type the command C:\Apache24\bin\httpd.exe -k install and press Enter.

If when running the program you get the following error: failed to open the winnt service manager perhaps you forgot to log in as administrator, go to the following folder: C:\Users\Your_user_name here\AppData\Roaming\Microsoft\Windows\Start Menu\Programs \System Tools, run the command line as administrator

And repeat the installation command.

Installation completed. Open the bin directory (full path: C:\Apache24\bin\) and run the file: ApacheMonitor.exe. The Apache icon will appear in the system tray, with which you can quickly start/stop the Apache service, click start:

Now let's check the functionality. Open the browser and write http://localhost/ in the address bar (you can just localhost). If the installation was successful, a page should open that says It works!

PHP installation (manual)

Do we need Apache without PHP? Of course not, this is nonsense! Therefore, next we will look at manual (without using an installer) installation of PHP.

Download PHP (Zip archive) from the site: http://windows.php.net/download/. We need version: VC11 x64 Thread Safe.

We unpack the contents of the archive into the C:\PHP directory (we create the PHP folder ourselves). Next, in the C:\PHP folder we find two files php.ini-development and php.ini-production. These files contain basic settings. The first file is optimized for developers, the second for production systems. The main difference is in the settings: for developers, error display is allowed, while for production systems, error display is prohibited for security reasons.

Let's do a few things before we continue with the PHP installation. Open Control Panel → Appearance and Personalization → Folder Options → View tab, find the line “Hide extensions for known file types”, and if there is a checkmark there, uncheck it and click “Apply”.

We continue with the installation. And so, select the file you need (I chose php.ini-development). The selected file will just need to be renamed a little. Right click on the file → Rename → erase “-development”, leaving only php.ini

Now open php.ini, we need to make a few changes (be careful when making changes, if there is a semicolon at the beginning of the line, it will need to be removed):

  1. Find the extension_dir option (line 721) and change the ext folder path to match the PHP installation path. For me it looks like this:
    extension_dir = "C:\PHP\ext"
  2. Find the upload_tmp_dir option (line 791). Here you need to specify the path to the temporary folder. I chose c:\windows\temp. Together:
    upload_tmp_dir = "C:\Windows\Temp"
  3. Find the session.save_path option (line 1369). Here you also need to specify the path to the temporary folder:
    session.save_path = "C:\Windows\Temp"
  4. In the Dynamic Extensions section, you need to uncomment several lines (remove the semicolon at the beginning) corresponding to the PHP modules that may be needed for work: 866, 873, 874, 876, 886, 895, 900

Save the changes and close.

Now let's go back to the Apache settings. We will have to edit the Apache config a little. Go to the C:\Apache24\conf folder and open the httpd.conf file.

Go to the end of the file and add the following lines at the very bottom:

# Charset AddDefaultCharset utf-8 # PHP LoadModule php5_module "C:/PHP/php5apache2_4.dll" PHPIniDir "C:/PHP" AddType application/x-httpd-php .php

Specify the path to the php folder that you selected during the installation process (if you installed in a different directory).

In the same file we find the following lines (lines approximately 274-276):

DirectoryIndex index.html

Before index.html we add index.php separated by a space. The result is:

DirectoryIndex index.php index.html

For the changes to take effect, restart the Apache service (the tray icon is Apache monitor). If the service restarts, that's a good sign. If not (an error will pop up), look for errors in the configuration files. Check all paths especially carefully.

To make sure PHP is working, open the C:\Apache24\htdocs folder (this contains the default website files). Create a file index.php in this folder with the following content:

Now open http://localhost/ (or just localhost) in your browser. If everything went well, you will see a page similar to this:

If instead of a page with information about php, you see a page with the inscription “It works!”, then just click refresh page.

Installing MySQL

Open the distribution download page: http://dev.mysql.com/downloads/installer/5.6.html and download Windows (x86, 32-bit), MSI Installer 5.6.16 250.8M. After clicking on the Download button, you will see a registration form, you can skip it by clicking on the link below (“No thanks, just start my download!”).

We launch the installer, after a short download we see the following window:

Click Install MySQL Products, the following window appears in which we accept the license agreement (check the box) and click Next >

The next window asks us to check if there are more a new version MySQL, check the Skip... (skip) box and click Next >

In the next window we are asked to select the installation type, select Custom and click Next >:

In the next window we are given the opportunity to select the necessary components: uncheck MySQL Connectors, in Application uncheck MySQL Workbench CE 6.0.8 and MySQL Notifier 1.1.5, in MySQL Server 5.6.16 uncheck Development Components and Client C API library ( shared) and click Next >

The next window tells us what exactly will be installed, just click Execute

After successful installation, click Next >

The next window informs us that next we will configure our server a little, click Next >

In the first settings window, check the Show Advanced Options box, leave the rest as is and click Next >

In the next window we are asked to set an administrator (root) password. It's better not to lose this password! Set a password and click Next >

In the next window, erase the number 56 in the input field, leave the rest as is and click Next >

Click Next >

Click Next >

All that remains is to check whether the installation was successful. (win 8): Go to the start menu → go to applications (down arrow) → find MySQL5.6 Command Line Client (a terminal for working with MySQL on the command line) → open it. Next, enter the administrator password (root). If the password is correct, you will be taken to the command prompt (mysql>). Enter the command: show databases; (a semicolon at the end is required). As a result, you should see a list of databases (at least two - information_schema and mysql). This means the server is working correctly. Close the command line by executing the exit command.

Add the line to the file C:\Windows\System32\drivers\etc\hosts: 127.0.0.1 localhost. In the same file, delete or comment out (put a # sign at the beginning of the line) the line::1 localhost (if it was initially commented out, then you do not need to do anything with it).

Installation and basic setup of phpMyAdmin

Open the download page http://www.phpmyadmin.net/home_page/downloads.php and select to download the archive ending in *all-languages.7z or *all-languages.zip (at the time of writing latest version was phpMyAdmin 4.1.9). Create a phpmyadmin folder in C:\Apache24\htdocs and extract the downloaded archive files there.

Let's check how it works. Open the browser and go to the address http://localhost/phpmyadmin/. The following window should open:

Now we need to create configuration file for MySQL. Go to the phpmyadmin folder and create a config folder there. Open the following address in the browser: http://localhost/phpmyadmin/setup/

Now, to configure the connection parameters to MySQL, click on the “New Server” button, a new window opens, in the “Server Host” column localhost must be replaced with 127.0.0.1:

We save the settings (click Apply) and we will be automatically returned to the previous page. Select the default language - Russian, default server - 127.0.0.1, end of line - Windows. At the bottom, click Save and then Download.

The resulting file (config.inc.php) is saved to the root phpMyAdmin installations(C:\Apache24\htdocs\phpmyadmin). We close the page, we won't need it anymore.

That's all. We return to the page http://localhost/phpmyadmin/. Now you can log in to the system as the root user (enter the password you specified when MySQL setup for the root user). Testing connection to MySQL. If everything went well (you were able to log into phpMyAdmin), delete the config folder from the phpmyadmin folder.

PHP is one of the most popular programming languages ​​used to create Web sites.

Download the distribution kit from the official PHP website http://www.php.net ( I have - php 5.1.6 ). Unpack the archive into the C:\Program Files\php directory. Find the configuration file php.ini, containing the PHP interpreter settings, and make the following changes to it:

    register_globals directive php 5.1.6 enabled by default ( recommended):

    register_globals = on

    Set the maximum amount of data sent POST method, equal to 16M:

    post_max_size = 16M

    Find the line:

    ;include_path = ".;c:\php\includes"

    uncomment it ( why remove the semicolon symbol; at the beginning of the line) and correct it to:

    include_path = ".;C:\Program Files\PHP\PEAR"

    It is necessary to set the extension_dir parameter equal to the directory in which the PHP distribution is located:

    Extension_dir = "C:/Program Files/php/ext"

    Install maximum size uploaded files equal to 16M:

    upload_max_filesize = 16M

    The doc_root parameter must be passed the value of the DocumentRoot directive of the Web server:

    doc_root = "d:/main/html"

    If you need to use PHP extensions, remove the comment ( semicolon character ; ) at the lines:

    ; extension = php*.dll
    .
    .
    .
    ; extension = php*.dll

    The following extensions are sufficient for full PHP operation:

    Php_mbstring.dll – the library is designed to work with multi-byte encodings, which include the encodings of eastern languages ​​( Japanese, Chinese, Korean), Unicode ( UTF-8) and etc.

    php_bz2.dll – the extension is used to create and unpack archives in bzip2 format.

    Php_curl.dll – allows you to connect and work with servers using various Internet protocols.

    Php_gd2.dll – the extension allows you to work with graphics.

    Php_mysql.dll – the library is required to work with the MySQL server.

    Php_mysqli.dll – the library is an extension of php_mysql.dll. It contains additional PHP functions for working with MySQL server version 4.1.3 and higher.

    Parameter

    error_reporting = E_ALL & ~E_NOTICE

    allows you to display all errors except comments. This value is set by default, so we leave it.

    But PHP 5 ( Unlike previous versions ) does not display a number of errors in the browser window ( due to safety requirements).

    You can view all information about errors in log files. To place it in them, the log_errors parameter must be set to On :

    log_errors = On

    To debug Web applications with error messages displayed in the browser window, you should set the display_errors parameter:

    display_errors = On

    Setting the display_errors and log_errors parameters to off allows you to prevent error messages from being displayed in the browser window and log file, respectively.

    Directive

    e r r o r _l o g = syslog

    allows you to log errors in system log Windows.


    Find the line:

    session.save_path = "F:/main/tmp"

    and specify the path to the folder for storing temporary files. For me this is the Temp folder on drive C:

    session.save_path = "C:/Temp"

    To store temporary session files, you can create a separate Temp folder in the php directory. Then:

    session.save_path = "C:/Program Files/php/Temp"

    In the Apache web server configuration file httpd.conf Before the virtual host description block, you must add the following lines:

    AddType application/x-httpd-php phtml php

    OptionsExecCGI

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

Now you need to restart Apache server and check the operation of PHP.

To do this, create a file test.php in the d:/main/html directory. To create a PHP file you can use text editor Notebook, in which you should write any small script, for example:

e c h o ("H e l l o, RNR!");
?>

If, when you type the request http://localhost/test.php in the address bar of your browser, the line appears

Hello PHP!

The installation was successful!

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 lot a large number of PHP settings, but we don't need them now. We will only deal with basic setup, which will allow us to run PHP on the 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 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.

Installation and PHP setup 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.

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 current version 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 accordingly 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 keep things like this at the root system disk. 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 configuration PHP file for the developer environment (development)
  • 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 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.

Computer