Home  >  Article  >  Backend Development  >  How to avoid the problem that the php configuration file does not take effect in centos7

How to avoid the problem that the php configuration file does not take effect in centos7

PHPz
PHPzOriginal
2023-03-23 16:53:141392browse

If you are using the CentOS 7 operating system and are trying to configure PHP, but the configuration file does not take effect, then this article will provide a solution. In this article, we will discuss how to configure PHP on CentOS 7 to avoid the problem of configuration files not taking effect.

  1. Confirm PHP version

You need to confirm the PHP version you are using. Enter the following command at the command line to view the PHP version:

php -v

If you have multiple PHP versions installed, you need to confirm that you are using the correct version. If you want to install a new PHP version, you can do so via the following command:

sudo yum install php-version
  1. Find a running PHP interpreter

on CentOS 7, the system default PHP interpreter location is /usr/bin/php. You can find the location of the PHP interpreter by typing the following command at the command line:

which php

If you have multiple versions of PHP installed, you will also need to confirm that you are using the correct version of PHP. You can switch PHP versions by typing the following command on the command line:

sudo alternatives --config php

It will list all available PHP versions and you need to select the correct version.

  1. Confirm the location of the PHP configuration file

On CentOS 7, the PHP configuration file is located in /etc/php.ini. You can confirm the location of the configuration file by entering the following command at the command line:

php -i |grep php.ini

If you are using a different PHP version, you need to confirm that you are using the correct configuration file.

  1. Confirm whether the PHP configuration is effective

By default, the PHP configuration file must be included in your web server configuration file to take effect. For example, when using Apache, you need to add the following code to your virtual host configuration file:

php_value disable_functions "exec,passthru,shell_exec,system"

Make sure to restart the Apache web server for the configuration file to take effect.

If you are using Nginx, you need to add the following code to your Nginx configuration file:

location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
    fastcgi_param PHP_VALUE "disable_functions=exec,passthru,shell_exec,system";
}

Make sure to restart the Nginx web server for the configuration file to take effect.

  1. Confirm that PHP has the necessary modules and extensions installed

On CentOS 7, you may need to install some PHP modules and extensions, these Modules and extensions may be required for your PHP application, for example, the MySQL module and the GD module. You can install these modules and extensions using the following command:

sudo yum install php-mysql php-gd

Make sure to restart the web server for the modules and extensions to take effect.

Summary

By following the above steps, you can avoid the problem that the configuration file does not take effect when configuring PHP. If you still have problems, seek professional help.

The above is the detailed content of How to avoid the problem that the php configuration file does not take effect in centos7. 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