Как установить php 8 на windows 10

от admin

How to Install PHP 8 on Windows

In this post, we’ll learn how to install PHP 8 on Windows.

Why Developing with PHP?

PHP is one of the most popular server-side programming languages on the world. It is installed by most web hosts, has an easy learning curve, close ties with the MySQL database, and a good number of libraries to improve your productivity. PHP may not be perfect, but it should certainly be considered for your next web application. Both Yahoo and Facebook use it with great success.

Recently PHP 8 was released with many new features and improvements such as named parameters, attributes, union types, constructor properties,

Why Install PHP 8 Locally?

Having PHP 8 installed on your development machine enables you to create web applications without risking the production data or resources on your real-world website. This post will teach you how to install PHP 8 in the Windows version of Apache.

All-in-One packages

There are some excellent all-in-one Windows distributions that contain Apache, PHP 8, MySQL and other applications in a single installation file, e.g. XAMPP (including a Mac version), WampServer and Web.Developer. There is nothing wrong with using these packages, although manually installing Apache and PHP will help you learn more about the system and its configuration options.

The PHP Installer

Although an installer is available from php.net, I would recommend the manual installation if you already have a web server configured and running.

Manual Installation

Manual installation offers several benefits:

  • backing up, reinstalling, or moving the web server can be achieved in seconds and
  • you have more control over PHP 8 and Apache configuration.

Step 1: Download the files

Download the latest PHP 8 ZIP package from www.php.net/downloads.php

As always, virus scan the file and check its MD5 checksum using a tool such as fsum.

Step 2: Extract the files

We will install the PHP files to C:\php , so create that folder and extract the contents of the ZIP file into it.

PHP 8 can be installed anywhere on your system, but you will need to change the paths referenced in the following steps.

Step 3: Configure php.ini

Copy C:\php\php.ini-development to C:\php\php.ini . There are several lines you will need to change in a text editor (use search to find the current setting). Where applicable, you will need to remove the leading semicolon to uncomment these setting.

Define the extension directory:

Enable extensions. This will depend on the libraries you want to use, but the following extensions should be suitable for the majority of applications:

If you want to send emails using the PHP 8 mail() function, enter the details of an SMTP server (your ISP’s server should be suitable):

Step 4: Add C:\php to the path environment variable

To ensure Windows can find PHP 8, you need to change the path environment variable. Open Settings, type ‘environment variables’ into the search field and open the result. Select the “Advanced” tab, and click the “Environment Variables” button.

Scroll down the System variables list and click on “Path” followed by the “Edit” button. Click “Edit text” and add ;C:\php to the end of the Variable value line (remember the semicolon).

Now click OK until you’re out. You might need to reboot at this stage.

Build faster websites and apps

Learn the skills to boosting your data-driven web apps performance

Step 5: Configure PHP 8 as an Apache module

Ensure Apache is not running (use net stop Apache2.2 from the command line) and open its confhttpd.conf configuration file in an editor. The following lines should be changed:

On line 239, add index.php as a default file name:

At the bottom of the file, add the following lines (change the PHP file locations if necessary):

Save the configuration file and test it from the command line (Start > Run > cmd):

Как установить php 8 на windows 10

IIS является встроенным в Windows. На сервере Windows используйте Server Manager для добавления роли IIS. Убедитесь, что функция роли CGI включена. На рабочем столе Windows используйте панель "Установка и удаление программ" для добавления IIS. В документации Microsoft есть » подробные инструкции. Для настольных веб-приложений и веб-разработки можно также использовать IIS/Express или рабочий стол PHP.

Пример #1 Командная строка для настройки IIS и PHP

Apache

Существует несколько версий Apache2 для Windows. Мы поддерживаем ApacheLounge, но другие варианты включают XAMPP, WampServer и BitNami, которые предоставляют средства автоматической установки. Вы можете использовать mod_php или mod_fastcgi для загрузки PHP на Apache. Если вы используете mod_php, необходимо использовать TS-build Apache, Visual C той же версии и тот же процессор (x86 или x64).

Выберите сборку

Thread-Safe(TS) — для одного процесса веб-служб, как Apache с mod_php

Non-Thread-Safe(NTS) — для служб IIS и других FastCGI веб-серверов (Apache с mod_fastcgi) рекомендуется и для сценариев командной строки

Как установить php 8 на windows 10

Найти дистрибутив PHP можно по адресу https://windows.php.net/download#php-8.1 Выберите версию Thread Safe .

В папке c:\WebServer\WAMP\ создайте новую папку PHP и скопируйте туда содержимое архива php-8.1.5 — VS16 x64 Thread Safe (2022-Apr-12 18:12:52) .

Настройка конфигурационного файла php.ini

С помощью Notepad++ открываем php.ini-development в папке c:\WebServer\WAMP\PHP\ и сохраняем его как php.ini , и вносим в него следующие изменения .

Для этого находим строку – 768 :

И заменяем ее на :

Теперь найдите строки: Начинается со строки 920 .

И заменим их на :

Заменим строки: – начинаются со строки 950.

Указываем кодировку по умолчанию . Для этого находим строку – 720 :

Находим строку – 746:

Предварительно создадим папку includes в C:\WebServer\home\
Здесь будут хранится подключаемые файлы PHP .

Заменим строку – 970:

Сохраняем и закрываем файл php.ini .
Теперь необходимо вписать поддержку PHP в файл конфигурации сервера Apache . Открываем файл httpd.conf и в конец файла добавим строки :

Сохраняем и закрываем файл httpd.conf .

Настройка переменной среды

Далее необходимо добавить каталог с установленным интерпретатором PHP в переменную PATH операционной системы Windows 10 . Для этого нажмите кнопку Пуск на Windows 10 , начните набирать «Изменение системных переменных среды» и откройте соответствующее окно настроек.

Изменение системных переменных среды

В открывшемся окне выбираем в самом низу пункт переменные среды .

В следующем открывшемся окне :

path1.png

Выберем пункт path и нажимаем изменить .

В следующем открывшемся окне :

path2

Выбираем пункт создать и в открывшейся строке напишите C:\WebServer\WAMP\PHP\ и выбираем пункт вверх и подымаем нашу строку к вверху , и нажимаем кнопку Ok , как на рисунке ниже .

path3

Во всех открытых окнах нажимаем Ok , все окна переменной среды path закрываем . После данных изменений следует перезагрузить компьютер .

После перезагрузки компьютера , открываем Notepad++ и набираем следующий код :

Читать:
Adobe refresh manager что это за программа

Сохраняем файл в каталоге c:\WEbServer\home\www\ с названием i.php

В адресной строке Web – браузера набираем : http://localhost/i.php , если вы увидите данные о интерпретаторе PHP , как на рисунке , то значит все настройки сделали правильно и PHP работает .

Версия PHPВерсия PHP

Установка PHP завершена , если при выполнении примеров появляются ошибки ошибки , то проверяйте все в конфигурационные файлы , перезагружаем сервер и снова пробуем достичь желаемого результата.

И помните после каждого изменения конфигурационных файлов и исправлении ошибок , нужно чистить историю Web – браузера , может так получится вы нашли исправили ошибку , перезагрузили сервер , а Web – браузер выдает вам файлы из истории , и вы видите при загрузке опять ошибку .

How To Install PHP On Windows

It explains all the steps required to install PHP 8 on Windows 10 from the official site and get started with PHP development using the Hello World script.

This tutorial provides all the steps required to install PHP 8 on Windows 10. The steps should be similar on the other versions of Windows.

In some cases, we need to develop or test our application against a specific version of PHP or to install it separately. In such cases, we can download it from the official site instead of using a bundled package in the form of XAMPP or WAMP. Once installed, we can configure the latest PHP to work with the web servers including Apache and NGINX.

Step 1 — Download PHP 8 for Windows

Go to the official download link and download the required version of PHP 8 for Windows. The distributions are provided as tar and windows binaries. While writing this tutorial, PHP 8.0.3 is the most recent one, hence we will discuss the installation steps specific to PHP 8.0.3. Click the Windows Download Link and it will open the page having Binaries and Sources packaged for Windows.

We can see that PHP is available either as Thread Safe and Non Thread Safe. In simple terms, we can use Thread Safe PHP if we are using mod_php as worker MPM in Apache which spans multiple threads concurrently to process the requests and Non Thread Safe can be used for CGI. The Thread Safe version is required for web servers running in a multithreaded context.

The download page also provided binaries for both 32-bit and 64-bit Operating Systems. We will download the Zip Thread Safe version for 64-bit Operating System having the title as — VC15 x64 Thread Safe. As a regular user, we do not need the Debug Pack which is required for PHP developers.

Step 2 — Extract the Zip

Extract the downloaded zip at a specific location. It will look similar to the one having the PHP executable file as shown in Fig 3.

Step 3 — Verify Installation

Open the command prompt and type php —version to check the available version. It will look similar to Fig 4 in case existing PHP versions are available.

It will show the error ‘php’ is not recognized as an internal or external command, operable program or batch file., in case PHP is not installed on the system.

We need to configure the environment variable to access PHP from the command line. You can follow the below-mentioned steps to do so.

Right Click -> My Computer(This PC) -> Properties -> Scroll Down -> Advanced System Settings

The above steps will open the Windows Settings Panel as shown in Fig 5.

Now click the Environment Variables Button, select Path under either User variables or System Variables based on your preference, and click the Edit Button. We need to add/update the path of the installed PHP to the system Path.

Click the New/Edit Button and add/update the path to the PHP bin which is E:\tools\php\php-7.3.1 in my case. Press the OK Button 3 times to close all the windows. This sets the PHP 8 on system environment variables to access the same from the console.

Now again open the console and test the PHP version as shown in Fig 6.

These are the basic steps required to install PHP 8 on Windows 10.

Step 4 — Getting Started With PHP Development

In this step, we will write a simple program and print Hello World on the console using the PHP executable configured by us in the previous step. Open your favorite editor and write the program as shown below.

Now save the file as index.php and execute it using the command as shown below.

In this way, we can execute the PHP program on the console. Though PHP is meant for web development, we can also use it for console-based development. The latest PHP supports the modern programming concepts i.e. OOPS and it also supports strict typing.

Step 5 — Configure With Apache

You might have installed the Apache Web Server either independently or installed it as part of the bundled packages including WAMP, XAMPP, etc. In this step, we will simply configure the Apache Web Server to use the PHP installed by us in the previous steps.

Copy the file php.ini-development available at the path where we have extracted PHP and save it as php.ini at the same location.

Open the httpd.conf file of your Apache Web Server installation and search for the line having LoadModule php7_module or LoadModule php_module. Now comment on the line and add the path to your PHP as shown below.

You might not find the php7_module or php_module in case the Apache HTTP Server is installed without using any bundled software. If Apache 2 is installed directly as shown in How To Install Apache 2 On Windows, you just need to add the module to the httpd.conf as highlighted below.

Save the file and restart the webserver. Now create a file test.php at your webroot of the Apache server as shown below.

Save the file, open your browser, and open the link — http://localhost/test.php. It should show the PHP settings as shown in Fig 7.

You can also enable the PHP extensions required for your project. The most important one is the pdo_mysql. I have updated the php.ini file and enabled it as shown below.

You must also enable to extensions directory by updating the php.ini file as shown below.

Below mentioned is the output of phpinfo() before and after enabling the PDO extension.

We have successfully configured the latest PHP installed by us to work with the Apache Web Server.

Похожие статьи