Home  >  Article  >  Backend Development  >  How to install PHP on different operating systems

How to install PHP on different operating systems

PHPz
PHPzOriginal
2023-03-29 15:13:38964browse

Developing and managing a website requires countless components and tools. A very important part of it is PHP. PHP is a server-side scripting language that is an integral part of many websites, content management systems (CMS), and e-commerce platforms. In this article, we will show you how to install PHP on different operating systems.

  1. Installing PHP on Windows systems

For Windows, you can install PHP through the following methods:

  1. Download PHP
    from Download the required PHP version from the PHP official website. Please note that your Windows system version should be compatible with your PHP version. You can download PHP to any folder, such as C:\PHP.
  2. Configure PHP.ini file
    Open the C:\PHP folder. Change the name of the php.ini-development file to php.ini and open it. There are several important settings you need to edit, such as pointing extension_dir to the ext subfolder of your PHP installation folder, setting up error log files, and opening MySQL connections.
  3. Configure Server
    Configure a web server, such as Apache or Microsoft IIS Server. You need to install a web server and set a folder (for example, C:\xampp\htdocs) as the content path of the web server.
  4. Enable PHP extensions
    Open the php.ini file and uncomment the desired extension name in PHP. For example, if you need to enable the mysql extension, just remove semicolon and restart the web server.
  5. Install the Microsoft Visual C package
    The PHP runtime requires the Microsoft Visual C package. You can download this package from Microsoft and install it to make PHP run smoothly.
  6. Testing PHP
    Create a PHP script file (.php suffix) and add the following code to the top of the file:

phpinfo( );
?>

Save the file and place it in the content path of the web server. Launch a web browser and navigate to localhost/index.php, which should display the version of PHP enabled on your system and all settings configured through the php.ini file.

  1. Installing PHP on macOS system

For macOS, you can install PHP through the following methods:

  1. Install PHP through Homebrew
    You can install PHP through the package manager Homebrew. After installing Homebrew, simply enter the following command in the terminal to install PHP:

brew install php

  1. Configure PHP.ini file
    Open /usr/local /etc/php.ini file and edit it, you need to delete the copy of the file php.ini.default. Set required settings, such as extension_dir to point to the ext subfolder of the PHP installation folder, and to turn on the mysql and pgsql extensions.
  2. Testing PHP
    Create a PHP script file (.php suffix) and add the following code to the top of the file:

phpinfo( );
?>

Save the file and place it in the content path of the web server. Launch a web browser and navigate to localhost/index.php, which should display the version of PHP enabled on your system and all settings configured through the php.ini file.

  1. Installing PHP on Linux system

For Linux system, you can install PHP in the following way:

  1. Enter run in the command line The following commands:

sudo apt-get install php5 libapache2-mod-php5 -y

This will install PHP 5.x core as well as Apache 2.x and mod_php. You can upgrade it to PHP 7.x using the following command:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.2

  1. Configuring the PHP.ini file
    Open the /etc/php.ini file and edit it. Set required settings, such as extension_dir to point to the ext subfolder of the PHP installation folder, and to turn on the mysql and pgsql extensions.
  2. Testing PHP
    Create a PHP script file (.php suffix) and add the following code to the top of the file:

phpinfo( );
?>

Save the file and place it in the content path of the web server. Launch a web browser and navigate to localhost/index.php, which should display the version of PHP enabled on your system and all settings configured through the php.ini file.

Summary

These are a few ways to install PHP on different operating systems. In each case, you need to ensure that the PHP.ini file is configured correctly to enable the required PHP extensions. No matter which method you choose, just follow these steps and you can easily install PHP to power your next web project.

The above is the detailed content of How to install PHP on different operating systems. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn