PHP programming language. Connecting the configuration file

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. Eat different ways raising 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 with consideration ready-made assemblies LAMP). 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 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.

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

All information is stored in a MySQL database, from which the information needed at the moment is retrieved. 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 you just need to add your own inscriptions and your website is ready. To create your own Web sites on your local computer, you need to download a free new PHP version. After this, the finished site can be uploaded to the Internet.

Possibilities:

  • creating and editing Web sites and programs;
  • dynamic management of site content;
  • 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, the virtual Apache server. To do this, you can use ready-made development 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 this, you will be able to write websites from scratch on your virtual hosting or install the necessary website engines to create your own Internet projects.

Having paid for hosting and domain, you can upload your website to the Internet and begin to realize 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 your 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 websites in PHP;
  • use of databases;
  • ability to download free PHP to your computer
  • support for creating multiple databases and websites on a local computer;
  • a common and popular programming language.

Minuses:

  • To work on your 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, to 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 own Internet projects, so we advise you to download the latest version of PHP for free.

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 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 developed by a group of enthusiasts as part of an open source project. 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 website building is determined by the presence of a large set of built-in tools for developing web applications. The main ones:

  • 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;
  • working with HTTP authorization;
  • working with cookies and sessions;
  • working with local and remote files, sockets;
  • processing files uploaded to the server;
  • working with XForms.

PHP is currently used by hundreds of thousands of developers. According to the TIOBE Corporation rating, based on search engine data, in September 2015, PHP was in 6th place among programming languages. Some of the largest websites using PHP include