Download Russian version of php. Testing PHP from the command line

With this programming language, you can create websites and Web applications in local computer via Apache server. Most modern Internet sites are written in PHP. The pages of these sites are dynamic, unlike the old sites on HTML markup.

All information is stored in a MySQL database, from which the necessary information is retrieved. this moment. Experienced programmers can create websites from scratch, but for ordinary users it is better to use the services of ready-made engines (WordPress, Joomla or Drupal), where it is enough to add your own inscriptions - and your site is ready. To create your Web sites on your local computer, you need to download for free new version PHP. After that, the finished site can be uploaded to the Internet.

Capabilities:

  • creation and editing of Web-sites and programs;
  • dynamic site content management;
  • testing various engines for Web sites;
  • use of HTTP cookies.

Principle of operation:

Now let's understand how PHP works. First you need to download and install, for example, a virtual Apache server. To do this, you can use ready-made developer kits Denwer, XAMPP, OpenServer or any other program. After installing the local server, you need to copy the contents of the PHP archive to it. After that, you will be able to write sites from scratch on your virtual hosting or install the necessary site engines to create your Internet projects.

Having paid for hosting and a domain, you can upload your site to the Internet and start realizing your creative abilities. Using the PHP language will allow you to quickly and conveniently create and edit the content of your sites. For example, to change the design of the bottom of the site, you only need to edit one file, and the changes will be reflected on every page of your project. In HTML, you would have to edit each page individually.

Pros:

  • creation of dynamic sites in PHP;
  • use of databases;
  • the ability to download PHP for free on a computer
  • support for creating multiple databases and sites on the local computer;
  • widespread and popular programming language.

Minuses:

  • to work on a computer, you may need to install a virtual server.

Today, PHP is the most common programming language for websites and Web applications. Therefore, to create your own projects, you simply need to adapt your Windows system to this language. Also, for work, you will need to install a server for virtual hosting of your local sites. Using this programming language will allow you to create and run your Internet projects, so we advise you to download it for free latest version PHP.

PHP (English PHP: Hypertext Preprocessor - "PHP: Hypertext Preprocessor"; originally Personal Home Page Tools - "Tools for creating personal web pages") is a general-purpose scripting language that is intensively used for developing web applications.

Currently, PHP is supported by the vast majority of hosting providers and is one of the leading languages ​​used to create dynamic websites.

The PHP language and its interpreter are being developed by a group of enthusiasts as part of a project with open source. The project is distributed under its own license, which is incompatible with the GNU General Public License.

Scope of PHP

In the field of web programming, in particular the server side, PHP is one of the popular scripting languages ​​(along with JSP, Perl and the languages ​​used in ASP.NET).

Popularity in the field of building websites is determined by the presence of a large set of built-in tools for developing web applications. The main ones are:

  • automatic extraction of POST and GET parameters, as well as web server environment variables into predefined arrays;
  • interaction with a large number of different database management systems (, MySQLi, Oracle (OCI8), Oracle, Microsoft SQL Server, Sybase , ODBC, mSQL, IBM DB2, Cloudscape and Apache Derby, Informix, Ovrimos SQL, IBM Notes, DB++, DBM, dBase, DBX, FrontBase, FilePro, Ingres II, SESAM, / InterBase, Paradox File Access, MaxDB, PDO interface (PHP Data Objects));
  • automated sending of HTTP headers;
  • work with HTTP authorization;
  • work with cookies and sessions;
  • work with local and deleted files, sockets;
  • processing files uploaded to the server;
  • working with XForms.

PHP is currently used by hundreds of thousands of developers. According to TIOBE Corporation ranking based on data search engines, in September 2015, PHP was in 6th place among programming languages. The largest sites using PHP include

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

Downloading PHP for Windows

We 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 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 service process (for example, configured via the mod_php module for Apache). NTS is recommended for use with IIS (Internet Information Service) and alternative FastCGI web servers (such as 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 PHP distribution archive. Unlike most programs, PHP comes 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 in the root of the system drive. Create a directory in the root of the "C:" drive (or anywhere else) "php" and extract the contents of the downloaded archive into it.

A lot of files will appear in the directory, but we are most interested in:

  • go-pear.bat is a script to install 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 to execute PHP code in FastCGI mode;
  • php7apache2_4.dll– module for integration with Apache 2.4.X web server;
  • phpdbg.exe- debugger;
  • php.ini development– an example of a PHP configuration file for the developer environment (development)
  • php.ini-production– an example of a PHP configuration file for the production environment (production)

Connecting the config file

We have the unpacked distribution kit, let's connect the configuration file for it. We are going to experiment, so we will take as a sample php.ini development. Make a copy of this file in the 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 repeat the copying of the file php.ini development in php.ini. So, at the end of the gestures, 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 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 file “test.php” directly in the root of the “C:” drive) and put the text into it:

Now try to execute this file and see the result:

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

Function phpinfo() displays PHP configuration information in a convenient way. We'll talk more about this feature.

Simplify access to php.exe

PHP is ready to go, but you must admit, it is rather inconvenient to enter the path to the php interpreter in the console every time. To make our life easier, let's make some small changes to the environment variables. Launch the applet in the control panel "System"(or just press the hot key Windows + Pause Break. Then click on the button "Change settings". In the window that appears "Properties of the system", go to bookmark "Additionally". Find and click on the button "Environment Variables".

Finding a variable in a 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 specify the path to the PHP directory separated by a semicolon: c:\php;

Everyone, 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 at the root of the "C:" drive:

php -f C:\test.php

Or even start 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 try http://127.0.0.1:8888/test.php . Note that after the parameter -t we specify the path to a 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 the "C:" drive 1.php and that's what I'm asking for.

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

More about environment variables

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

C:\php. A reboot is required after making the change.

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