Home > Backend Development > PHP Problem > How to change port 80 in php5

How to change port 80 in php5

zbt
Release: 2023-07-25 11:20:53
Original
1391 people have browsed it

How to change port 80 in php5: 1. Edit the port number in the Apache server configuration file; 2. Edit the PHP configuration file to ensure that PHP works on the new port; 3. Restart the Apache server and PHP application The program will start running on the new port.

How to change port 80 in php5

The operating environment of this tutorial: Windows 10 system, PHP8.1.3 version, Dell G3 computer.

PHP is a popular server-side scripting language commonly used to develop web applications. By default, PHP uses port 80 of the Apache server to receive HTTP requests. However, sometimes we may need to change PHP's port to another port to meet specific needs. In this article, we will explore how to change the port of PHP5 from 80 to another port.

1. We need to edit the configuration file of the Apache server to change the PHP port. On most Linux systems, Apache's configuration files are located in the `/etc/apache2` or `/etc/httpd` directory, depending on your system. You need to open the `httpd.conf` file in this directory with administrator rights.

In the `httpd.conf` file, we need to look for the following lines of code:

Listen80
Copy after login

This is the default port that the Apache server listens on. Change the number 80 on that line to the new port number you wish to use. For example, if you want to change the PHP port to 8080, you need to change the line to:

Listen8080
Copy after login

After saving and closing the file, you need to restart the Apache server for the changes to take effect. On most Linux systems, you can restart the Apache service using the following command:

sudoserviceapache2restart
Copy after login
Copy after login

On Windows systems, you can open a command prompt and execute the following command:

net stop apache2

net start apache2

After restarting, the Apache server will start listening on the new port you specified.

2. We need to ensure that PHP also works on the new port. You need to edit PHP's configuration file. On most Linux systems, PHP's configuration files are located in the `/etc/php` directory. The specific path depends on your system and PHP version. You need to open the file in this directory corresponding to the PHP version you are currently using with administrator rights, such as `php.ini`.

In the `php.ini` file, you need to look for the following lines of code:

;cgi.fix_pathinfo
;FastCGIunderIIS(onWINNTbasedOS)supportstheabilityto
impersonate
…
Copy after login

Below these lines, you will see a line of code that looks like:

;extension=php_curl.dll
Copy after login

Find this line and remove the semicolon at the beginning so that it becomes:

extension=php_curl.dll
Copy after login

This is done to ensure that the PHP Curl extension is enabled because in some versions of PHP the extension is disabled by default of.

After saving and closing the file, you need to restart the Apache server for the changes to take effect. On a Linux system, you can use the following command to restart the Apache service:

sudoserviceapache2restart
Copy after login
Copy after login

On a Windows system, you can use the following command:

netstopapache2
netstartapache2
Copy after login

After restarting, PHP will start on the new port you specified Work.

After changing the port, you will need to ensure that the port number in any links and configuration files in your web application is updated correctly. Otherwise, your application may not work properly.

To summarize, to change PHP5's port from 80 to another port, you need to edit the port number in the Apache server's configuration file, then edit PHP's configuration file to ensure that PHP works on the new port, and Finally restart the Apache server. After completing these steps, your PHP application will start running on the new port.

Note: Changing PHP ports requires security attention and ensuring that firewalls and other network configurations have been updated to allow new port access. Also, ensure that only users with access can make changes to prevent potential security risks .

The above is the detailed content of How to change port 80 in php5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template