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.
- Installing PHP on Windows systems
For Windows, you can install PHP through the following methods:
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- Installing PHP on macOS system
For macOS, you can install PHP through the following methods:
- 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
- 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.
- 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.
- Installing PHP on Linux system
For Linux system, you can install PHP in the following way:
- 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
- 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.
- 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!