Home >Backend Development >PHP8 >PHP 8 Installation Guide: Step-by-Step for Windows, macOS, and Linux
This guide provides a step-by-step process for installing PHP 8 on Windows, macOS, and Linux systems. The exact steps will vary depending on your operating system, but the general principles remain the same. We'll focus on the most common installation methods.
Windows:
C:php
). Ensure this directory is added to your system's PATH environment variable. This allows you to run PHP from the command line anywhere. To do this, search for "environment variables" in the Windows search bar, edit the PATH variable, and add the path to your PHP directory.php.ini
file by copying the php.ini-development
or php.ini-production
file (located in the extracted directory) and renaming it to php.ini
. Edit this file to configure PHP settings as needed (e.g., extensions, memory limits). Crucially, you'll need to uncomment the extension lines for any extensions you want to use (remove the leading semicolon ;
).php -v
. If PHP is installed correctly, you'll see the PHP version information displayed.macOS:
brew install php@8.1
(or a later version if available). Homebrew manages dependencies and keeps PHP updated.README
file. This usually involves using the ./configure
, make
, and make install
commands. This method requires more technical knowledge.php -v
. You should see the PHP version information.Linux (Example: Ubuntu/Debian):
sudo apt update
.sudo apt install php8.1
(or a later version if available). This command installs PHP 8.1 and its dependencies.php8.1-cli
, php8.1-common
, php8.1-fpm
, php8.1-mysql
, etc., depending on your needs. Install them using sudo apt install <extension_name>
.php -v
. You should see the PHP version information.The minimum system requirements for PHP 8 vary slightly depending on the operating system and the specific extensions you intend to use. However, a general guideline includes:
Note that these are minimum requirements. More RAM and disk space are recommended for better performance, especially when dealing with large projects or many extensions.
The configuration process differs depending on your web server (Apache or Nginx).
Apache:
libapache2-mod-php8.1
(adjust the version number as needed). On Windows, you'll need to enable the Apache module in your Apache configuration (httpd.conf
or apache2.conf
).LoadModule php8_module "path/to/php/php8apache2_4.dll"
(replace with the correct path) to your Apache configuration file. You also need to specify the PHP handler for .php
files. This usually involves adding a section like:<code class="apache"><FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch></code>
Nginx:
sudo apt install php8.1-fpm
on Ubuntu/Debian).php-fpm.conf
or a pool configuration file) to adjust settings like listening port and user/group..php
files and specify the PHP-FPM socket or port. A typical configuration looks like this:<code class="apache"><FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch></code>
php -v
to confirm PHP is installed and the correct version is displayed.error_log
in php.ini
) is also valuable.Remember to always back up your system before making significant changes. If you're unsure about any step, consult the official documentation for your operating system and web server.
The above is the detailed content of PHP 8 Installation Guide: Step-by-Step for Windows, macOS, and Linux. For more information, please follow other related articles on the PHP Chinese website!