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

How to set PHP permissions in CentOS 7 (Guide)

Apr 24, 2023 am 10:52 AM

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

OWASP Top 10 PHP: Describe and mitigate common vulnerabilities. OWASP Top 10 PHP: Describe and mitigate common vulnerabilities. Mar 26, 2025 pm 04:13 PM

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

PHP 8 JIT (Just-In-Time) Compilation: How it improves performance. PHP 8 JIT (Just-In-Time) Compilation: How it improves performance. Mar 25, 2025 am 10:37 AM

PHP 8's JIT compilation enhances performance by compiling frequently executed code into machine code, benefiting applications with heavy computations and reducing execution times.

PHP Secure File Uploads: Preventing file-related vulnerabilities. PHP Secure File Uploads: Preventing file-related vulnerabilities. Mar 26, 2025 pm 04:18 PM

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

PHP Encryption: Symmetric vs. asymmetric encryption. PHP Encryption: Symmetric vs. asymmetric encryption. Mar 25, 2025 pm 03:12 PM

The article discusses symmetric and asymmetric encryption in PHP, comparing their suitability, performance, and security differences. Symmetric encryption is faster and suited for bulk data, while asymmetric is used for secure key exchange.

PHP Authentication & Authorization: Secure implementation. PHP Authentication & Authorization: Secure implementation. Mar 25, 2025 pm 03:06 PM

The article discusses implementing robust authentication and authorization in PHP to prevent unauthorized access, detailing best practices and recommending security-enhancing tools.

PHP API Rate Limiting: Implementation strategies. PHP API Rate Limiting: Implementation strategies. Mar 26, 2025 pm 04:16 PM

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

PHP CSRF Protection: How to prevent CSRF attacks. PHP CSRF Protection: How to prevent CSRF attacks. Mar 25, 2025 pm 03:05 PM

The article discusses strategies to prevent CSRF attacks in PHP, including using CSRF tokens, Same-Site cookies, and proper session management.

PHP Input Validation: Best practices. PHP Input Validation: Best practices. Mar 26, 2025 pm 04:17 PM

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

See all articles