Home >Backend Development >PHP Problem >How to set PHP permissions in CentOS 7 (Guide)

How to set PHP permissions in CentOS 7 (Guide)

PHPz
PHPzOriginal
2023-04-24 10:52:35628browse

On CentOS 7, if you want to enable PHP on your website, you need to set the appropriate permissions for it. Here are some basic guidelines on how to set PHP permissions in CentOS 7.

Step 1: Install PHP

When setting up PHP, you first need to make sure that PHP is installed on CentOS 7. PHP can be installed with the following command:

sudo yum install php

Select Y in the menu listed by the installer to confirm the installation. This will install PHP from the CentOS 7 repository.

Step 2: Install the php-mysql package (if necessary)

If your PHP application needs to use the MySQL database, you also need to install the php-mysql package. Install using the following command:

sudo yum install php-mysql

Again, select Y in the menu listed by the installer to confirm the installation.

Step 3: Configure PHP

Next, you need to set some options in the PHP configuration file. Open the php.ini file to configure it. Open the following command. This file may be stored in other locations due to different locations:

sudo nano /etc/php.ini

The configuration file will be opened in the nano text editor. Find the following options in the file and make sure they are correct.

max_execution_time = 60
max_input_time = 60
memory_limit = 256M
post_max_size = 64M
upload_max_filesize = 64M

These options control the settings used by PHP when running. Some common settings include:

  • max_execution_time: Maximum time in seconds to run the script. If the script takes longer than this setting, a timeout error will occur. Under normal circumstances, this value can be set higher than the 60 seconds above.
  • max_input_time: Set the maximum time the script can wait to receive POST, GET and other requests. This value can be set higher than 60 seconds.
  • memory_limit: Set the memory limit (in MB) that a PHP script can use. Set this value higher than 256MB depending on your application needs.
  • post_max_size: Set the maximum number of bytes sent in a POST request. Set this value higher than 64MB depending on your application needs.
  • upload_max_filesize: Set the maximum size of files uploaded to the server (in MB). Set this value higher than 64MB depending on your application needs.

After completing the modification, please press Ctrl X, then press the y key to save and close the file.

Step 4: Set the correct folder permissions

Finally, you need to make sure that PHP can access all the folders it needs. If your PHP application writes files in certain folders, such as logs, cache, etc., you need to ensure that these folders are writable by the PHP user. It is recommended to place these folders outside the web root.

In CentOS 7, the default user used when the Apache web server runs is apache. Run the following command in a folder to change the ownership of the folder (make sure to replace the my_folder name with the name of the folder you want to modify):

sudo chown -R apache:apache /path/to/my_folder

If you need to run Apache as a different user, you will need to use The user's name replaces the values ​​on either side of the apache arrow.

Once all settings are complete, restart the Apache web server:

sudo systemctl restart httpd.service

This will ensure that all settings are applied and are ready for you to run PHP applications on CentOS 7.

Summary

It is easy to enable PHP on CentOS 7 by ensuring that PHP is installed and the appropriate options are set, the correct folder permissions are set and the Apache server is restarted. Please note that this is not a comprehensive PHP setup guide, but it can get you started and ensure your PHP applications run correctly on CentOS 7.

The above is the detailed content of How to set PHP permissions in CentOS 7 (Guide). 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