How to configure and install php on Windows and Linux

王林
Release: 2023-05-15 16:55:06
forward
1248 people have browsed it

Configuring and Installing PHP on Windows Operating System

Step 1: Download PHP

First, we need to download it from php.net Windows version of PHP. Download the correct PHP version based on your computer architecture (32-bit or 64-bit).

Step 2: Install PHP

After the download is complete, unzip the downloaded zip file and place it in the C:\php\ directory. Then, create a new file called php.ini in the C:\php\ directory and add the following content to the file:

extension_dir = "C:\php\ext\"
Copy after login

This code tells PHP where to look for extension files.

Step 3: Configure PHP

In the php.ini file, uncomment the following:

extension=php_mysql.dll
extension=php_mysqli.dll
Copy after login

These codes tell PHP to enable support for the MySQL database.

Step 4: Configure environment variables

It is common to use PHP and Apache servers on Windows operating systems. To do this, the PHP and Apache server paths need to be added to the Windows environment variables. Use the following steps to configure environment variables:

  • Right-click This PC and select Properties.

  • Click "Advanced system settings" in the left panel.

  • Click the "Environment Variables" button.

  • Have found "Path" under system variables and click "Edit".

  • Click the "New" button in the pop-up window and add the PHP and Apache server paths. For example, add "C:\php\" and "C:\Apache24\bin\".

Step 5: Start the Web Server

If you are using the Apache server, open the "bin" folder in the Apache server installation directory and start it with the following command Apache Server:

httpd.exe -k start
Copy after login

Step 6: Test PHP

Now, PHP has been successfully installed and configured on your Windows computer. To test PHP, create a new file called phpinfo.php and add the following content to the file:

<code><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;?php phpinfo(); ?&gt;</pre><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div>

Enter "http://localhost/phpinfo.php" in the web browser. If you see the PHP information page, it means PHP is already installed on your computer.

Configuring and Installing PHP on Linux Operating System

Step 1: Download PHP

When installing PHP on Linux, we need to update the packages Manager and install the latest version of PHP. In most distributions, update the package manager using the following command:

sudo apt-get update
Copy after login

Install php command:

sudo apt-get install php
Copy after login

Step 2: Install the database

PHP supports most popular database management system. Before installing PHP, you need to install any database management system such as MySQL or PostgreSQL. In most Linux distributions, MySQL can be installed using the following command:

sudo apt-get install mysql-server
Copy after login

Step 3: Start the web server

Most Linux distributions come with an Apache or Nginx web server. Here we will use the Apache web server. Start the Apache server using the following command:

sudo service apache2 start
Copy after login

Step 4: Test PHP

To test that PHP is installed correctly, create a new file called phpinfo.php and add the following content to In this file:

<code><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;?php phpinfo(); ?&gt;</pre><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div>

Enter "http://localhost/phpinfo.php" in your web browser. If you see the PHP information page, it means that PHP has been successfully installed on your Linux computer.

The above is the detailed content of How to configure and install php on Windows and Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!