Home > Article > Backend Development > How to change the port PHP listens on
PHP is a popular server-side programming language, and many developers use PHP for web development. When the PHP service runs on your local computer or server, it usually listens on port 80 and provides some web services.
However, sometimes you may need to change the port PHP listens on to allow other applications to occupy port 80, or as a means of privacy and security protection. In this article, we’ll cover how to change the port PHP listens on.
First, you need to open the php.ini file. This file is usually located in the "conf" or "etc" directory under your PHP installation directory.
After opening the php.ini file, you need to find the following:
[Web] ;接受的连接端口号 ;listen = 127.0.0.1:80
Notice the line ";listen = 127.0.0.1:80" in the comments. This is the port that PHP listens on by default. To change the port PHP listens on, you need to remove the semicolon (;) and specify the new port number.
For example, if you want to change the PHP listening port to 8080, you should edit the php.ini file as follows:
[Web] ;接受的连接端口号 listen = 127.0.0.1:8080
When you are done editing, save the file and close the editor.
Next, you need to restart the PHP service for the changes to take effect. There are two ways to accomplish this task, let's take a look at each method.
Method 1: Use the command line
If you have administrator rights, you can use the "Command Prompt" to stop and start the PHP service.
First, open the command prompt window. In the window, enter the following command and press Enter:
net stop Apache2.4
Where "Apache2.4" is the name of your web server running PHP. If you're running PHP on your local computer, you'll typically use the Apache web server. If you are using a different web server, this should be replaced with the web server name.
Once the PHP service is stopped, use the following command to start the service:
net start Apache2.4
Method 2: Use the XAMPP Control Panel
If you are running PHP on a Windows operating system, you also You can use the XAMPP control panel to stop and start PHP services.
First, open the XAMPP control panel. In the panel, find the PHP service and click the Stop button.
After waiting for the PHP service to stop, click the "Start" button to restart the service. Note the port number that appears on the XAMPP control panel page at this point.
If the above operations have been completed, congratulations, you have successfully changed the port that PHP listens on!
Summary:
In this article, we introduced how to change the listening port in PHP. It only requires a few simple steps, but is very quick and easy for you to use in developing web projects. In practice, you should also consider other network and security factors to ensure the security and reliability of your PHP service.
The above is the detailed content of How to change the port PHP listens on. For more information, please follow other related articles on the PHP Chinese website!