Home > Article > Backend Development > How to set PHP permissions in CentOS 7 (Guide)
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:
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!