Connecting php 7 to apache. How to install local Apache server with Php, MySQL, phpMyAdmin on Windows machine


At htmlAcademy and I work as a mentor on it. Within the framework 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 are different ways to bring up 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 considering ready-made LAMP assemblies). Since I plan to work as mentors on PHP intensives and beyond, I am going to write similar instructions for review in other OS (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 PHP version. At the time of this writing, this is - 7.1.4 ... There are several distributions 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 for a single web service process (for example, configuring via mod_php for Apache). NTS is recommended for use by IIS (Internet Information Service) and alternative to FastCGI web server (for example, Apache with 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, not an installation package. Therefore, you will have to extract the files yourself to any directory convenient for you. I prefer to store this sort of thing at the root of the system drive. Create a directory in the root of the "C:" drive (or any other location) 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- 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 to execute PHP code in FastCGI mode;
  • php7apache2_4.dll- module for integration with the Apache 2.4.X web server;
  • phpdbg.exe- debugger;
  • php.ini-development- an example of a PHP configuration file for the development environment
  • php.ini-production- an example of a PHP configuration file for a production environment

We connect the configuration file

We have the unpacked distribution kit, we will include 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 exactly 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 setting. In our case, it will be enough to repeat copying the file php.ini-development v php.ini... So, at the end of the gestures, the php.ini file should appear in the php directory. 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 "Standard" 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 to create a new script file (I created a file “test.php” right in the root of the “C:” drive) and put 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 way. We'll talk about this function later.

Making php.exe easier to access

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

Find a variable in the list "PATH" and press the button "Change", a window for editing a variable 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 directory with PHP separated by semicolons: 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 file test.php located at 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.

For testing, open a web browser and try to visit http://127.0.0.1:8888/test.php. 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 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

A little 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 a complete search chain. 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". After making the change, a reboot is required.

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

// echo get_the_post_thumbnail (get_the_ID (), "relatedthumbnail"); // display my thumbnail size?>

In the first article, we looked at how to install Apache on Windows7. Now let's look at how to connect the php language to our server.

Install PHP

1) Download the zip archive with php from the site http://windows.php.net/download/. I selected Thread Safe - php-5.3.5-Win32-VC6-x86.

2) Unzip php to c: /php-5.3.5/ folder

3) Connect php to Apache. Opening the file httpd.conf... It is located in the folder conf where you installed Apache. I have it C: Program Files (x86) Apache Software FoundationApache2.2conf .

To connect php as a module, you need to add only 3 instructions to the httpd.conf file:

(codecitation)
LoadModule php5_module c: /php-5.3.5/php5apache2_2.dll
AddType application / x-httpd-php phtml php
PHPIniDir "c: /php-5.3.5/"
(/ codecitation)

These lines should be placed approximately in the middle of the httpd.conf file, for example, right after the LoadModule directives. I have them end on line 128 of the file. The exact location of these directives is not critical, but you cannot put them at the beginning, as well as at the very end of the httpd.conf file.

Note.

  • 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.

4) Creating a config file in php. 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-production 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 all changes to the PHP configuration should be made there.

After making changes to httpd.conf and creating php.ini file, restart Apache.

5) Check. In the C: Program Files (x86) Apache Software Foundation Apache2.2htdocs folder, create an index.php file with the code:

(codecitation)

(/ codecitation)

Now go to your browser at http: //localhost/index.php. If everything is done correctly, you will see a purple table with php settings.

Php advanced settings

Enable php short notation support, find short_open_tag function in php.ini, and enable it: short_open_tag = On

In php.ini, specify the path to the php extensions, for this uncomment and fill in the extension_dir line. Here's how it looks for me:

(codecitation)
extension_dir = "c: /php-5.3.5/ext"
(/ codecitation)

(codecitation)
extension = php_mbstring.dll
(/ codecitation)

and the line extension = php_mysqli.dll for working with MySql databases:

(codecitation)
extension = php_mysqli.dll
(/ codecitation)

In the past, there was a great tutorial on how to set up a LEMP stack on a server from scratch. Unfortunately, this material has sunk into oblivion during the transfer of articles, and I had no desire to write it again.

UPD: The new version of the language, - PHP 7.3, -.

The stable version 7.2 was released at the end of November. There are quite a few changes, but now it's not about them. Below is a simple way I used to update my existing one PHP 7.1 FPM to PHP 7.2 FPM.

1. Add the repository.

sudo add-apt-repository ppa: ondrej / php sudo apt update

2. Install packages.

sudo apt install php7.2 php7.2-common php7.2-cli php7.2-fpm php7.2-gd php7.2-mysql php7.2-curl php7.2-simplexml php7.2-zip

Dpkg -l | grep php | tee packages.txt

The current packages will be saved in packages.txt... After installing the new PHP version, open the file and compare the list of installed packages.

3. PHP configuration.

We open /etc/php/7.2/fpm/pool.d/www.conf, change the value of the parameter listen:

Listen = 127.0.0.1:9000

4. NGINX configuration

If you already have the FPM package installed, there is no need to make any changes. Otherwise, add \ change in the site config:

Location ~ \ .php $ (try_files $ uri = 404; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; fastcgi_index index.php; include fastcgi_params;)

5. Delete old PHP files.

If everything went well and php -v claims that you are using the required version of PHP, we delete old files as unnecessary with the command:

Sudo apt purge php7.1 *

5. Well, everyone.

Do not forget to restart the services after all the changes.

Service nginx restart service php7.2-fpm restart

That's all. Enjoy the new PHP 7.2 :)

In this article, I will describe the process of installing PHP 7 on Ubuntu from a PPA repository. This post will be written in the format of a small manual, so I will try to summarize the technical technical side of the process. Additionally, in my previous posts you can read how to install PHP 7 in and. And there is also a description of the process from the source in Debian, this option is more laborious, but it has obvious advantages in terms of optimization.

Install PHP 7 on Ubuntu

PHP 7 is not officially available for installation on Ubuntu at this time. But we can install PHP 7 on Ubuntu using the PPA - apt personal repository hosted on the Launchpad site. With PPAs, third-party developers have the ability to create and distribute packages for Ubuntu outside of the official channels.

Add the PHP 7 repository to Ubuntu using the command below:

Add-apt-repository ppa: ondrej / php

After installing the PPA, update the local package cache:

Apt-get update

Now that we have access to the new packages, we can complete the PHP 7 installation on Ubuntu. In this article, I will describe the process of configuring PHP 7 to use it in conjunction with the Nginx web server. To do this, we need to install PHP-FPM:

Apt-get install php7.0-fpm

If your scripts use MySQL in the process, run the command:

Apt-get install php7.0-mysql

Configuring PHP 7 to Work with Nginx

PHP 7 and Nginx processes communicate with each other using a unix socket. By default in PHP 7, the unix socket has the following location:

/var/run/php/php7.0-fpm.sock

Open the default config file in nano text editor:

Nano / etc / nginx / sites-enabled / default

Completely delete all contents of the default file, and then copy the lines from the example below:

Server (listen 80 default_server; root / var / www / html; index index.php index.html; server_name _; location / (try_files $ uri $ uri / /index.php?q=$uri&$args;) location ~ \ .php $ (try_files $ uri = 404; fastcgi_pass unix: /var/run/php/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; include fastcgi_params;))

Close the file and save your changes. To use the new settings, you need to restart Nginx:

Nginx -t service nginx restart

Verifying PHP 7 is Working

To check that PHP 7 is installed and configured correctly on Ubuntu, create a file in the root directory of the site:

Nano /var/www/html/info.php

Of the following content:

Open the file in your browser:

Http: //server_ip/info.php

If you have correctly installed and configured PHP 7 on Ubuntu, you should see a page containing information about its configuration.

And so we installed the nginx server now it's the turn of the installation php 7.1 on ubuntu. The nginx + php7 bundle has proven itself very well, saving money and server resources.

Php 7.1 installation

First, let's add a repository from which we will download and install php 7.1.

Sudo add-apt-repository ppa: ondrej / php

Note: If the system encoding is different from utf-8, then there may be problems when adding the php 7.1 repository. Therefore, we will execute these two commands

sudo apt install -y language-pack-en-base sudo LC_ALL = en_US.UTF-8 add-apt-repository ppa: ondrej / php

Update the list of repositories

Sudo apt update

If everything is ok, let's proceed with the installation ..

Apt install php7.1 php7.1-fpm php7.1-opcache php7.1-zip php7.1-xmlrpc php7.1-xsl php7.1-mbstring php7.1-mcrypt php7.1-mysql php7.1-odbc php7.1-pgsql php7.1-pspell php7.1-readline php7.1-recode php7.1-snmp php7.1-soap php7.1-sqlite3 php7.1-sybase php7.1-tidy php7.1-xml php7.1-json php7.1-ldap php7.1-intl php7.1-interbase php7.1-imap php7.1-gmp php7.1-gd php7.1-enchant php7.1-dba php7.1-bz2 php7.1-bcmath php7.1-phpdbg php7.1-cgi php7.1-cli

We agree with the installation, we wait until everything is completed.

And so everything is ready - php 7.1, and the extensions are installed. If other versions of php5 were installed on the system, then you can remove them by running the command:

Apt autoremove php5 * -y && apt purge php5 * -y && apt clean php5 *

Php 7.1 setup

The php setup will be as follows:

  • Eliminating vulnerabilities
  • Increase the size of the download file
  • Increasing script runtime
  • Configuring opcache

Open php.ini

Sudo nano /etc/php/7.1/fpm/php.ini

looking for a line

; cgi.fix_pathinfo = 1

uncomment the line and put 0 in place of the unit

Cgi.fix_pathinfo = 0

Let's increase the size of the uploaded files. Find post_max_size and bring it to the form

Post_max_size = 100M

Let's increase the processing time of the script, look for max_execution_time by setting 300 seconds - usually needed to work with large mysql tables

Opcache.enable = 1 opcache.enable_cli = 1 opcache.memory_consumption = 64 opcache.interned_strings_buffer = 4 opcache.max_accelerated_files = 7963 opcache.revalidate_freq = 20

We save the file. Restart php7.1-fpm

Service php7.1-fpm restart

Install MySQL server and phpmyadmin

sudo apt install mysql-server-5.7

During installation, we will be asked to set a password for the mysql server administrator. Follow the request.
Everything is ready. Now let's install the database manager

Sudo apt install phpmyadmin

During installation, it will most likely ask you to select a web server, select any, if asked to set a password for the database, set it.
Now let's make a symbolic link to the directory where our site will be located

Ln -s / usr / share / phpmyadmin /var/www/html/my.site.ru

You can go to the base manager at

My.site.ru/phpmyadmin/

In the future, you can create your own nginx configuration file for the phpmyaadmin database manager, and transfer it to a subdomain like mysql.my.site.ru, and set server authorization.

If you have any questions, write in the comments.







2022 gtavrl.ru.