search
HomeBackend DevelopmentPHP Tutoriallinux - chmod命令之后安装php应用提示文件依然不可写

我想要在自己的Linux系统下安装一些开源的php应用,譬如phpFreeChat,我把它放在/var/www/html/freechat底下,然后对freechat下的data文件夹中的public和private文件夹使用了chmod 777命令,然后使用ls -al data命令可以看到这样的结果:

drwxr-xr-x. 4 root root 4096 Jun 17 15:07 .
drwxr-xr-x. 13 root root 4096 Jun 17 15:22 ..
drwxrwxrwx. 2 root root 4096 Jun 17 15:07 private
drwxrwxrwx. 3 root root 4096 Jun 17 15:07 public

但是在浏览器里输入http://localhost/freechat 却会得到这样的错误:

phpFreeChat cannot be initialized, please correct these errors:

/var/www/html/freechat/src/../data/private is not writeable
/var/www/html/freechat/src/../data/private/cache can't be created
/var/www/html/freechat/src/../data/private/cache is not writeable
/var/www/html/freechat/src/../data/private/cache is not readable
cannot create /var/www/html/freechat/src/../data/public/themes/default
cannot create /var/www/html/freechat/src/../data/public/themes/default
/var/www/html/freechat/src/../data/private/chat can't be created
/var/www/html/freechat/src/../data/private/chat is not writeable
/var/www/html/freechat/src/../data/private/chat is not readable
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada can't be created
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada is not writeable
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada is not readable

还尝试过用递归的chmod命令,错误依旧。

利用代码

<?php echo exec('whoami'); ?>

发现用户名是apache,然后在/etc/httpd/conf/httpd.conf里发现User和Group都是apache。请问之所以显示文件不可写是因为这个用户的设置问题吗?如果是的话我该怎么修改?如果不是的话又是什么问题导致的呢?

回复内容:

我想要在自己的Linux系统下安装一些开源的php应用,譬如phpFreeChat,我把它放在/var/www/html/freechat底下,然后对freechat下的data文件夹中的public和private文件夹使用了chmod 777命令,然后使用ls -al data命令可以看到这样的结果:

drwxr-xr-x. 4 root root 4096 Jun 17 15:07 .
drwxr-xr-x. 13 root root 4096 Jun 17 15:22 ..
drwxrwxrwx. 2 root root 4096 Jun 17 15:07 private
drwxrwxrwx. 3 root root 4096 Jun 17 15:07 public

但是在浏览器里输入http://localhost/freechat 却会得到这样的错误:

phpFreeChat cannot be initialized, please correct these errors:

/var/www/html/freechat/src/../data/private is not writeable
/var/www/html/freechat/src/../data/private/cache can't be created
/var/www/html/freechat/src/../data/private/cache is not writeable
/var/www/html/freechat/src/../data/private/cache is not readable
cannot create /var/www/html/freechat/src/../data/public/themes/default
cannot create /var/www/html/freechat/src/../data/public/themes/default
/var/www/html/freechat/src/../data/private/chat can't be created
/var/www/html/freechat/src/../data/private/chat is not writeable
/var/www/html/freechat/src/../data/private/chat is not readable
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada can't be created
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada is not writeable
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada is not readable

还尝试过用递归的chmod命令,错误依旧。

利用代码

<?php echo exec('whoami'); ?>

发现用户名是apache,然后在/etc/httpd/conf/httpd.conf里发现User和Group都是apache。请问之所以显示文件不可写是因为这个用户的设置问题吗?如果是的话我该怎么修改?如果不是的话又是什么问题导致的呢?

问题解决了,竟然是SELinux从中作梗。使用setenforce 0以后便成功了。

应该是这个原因,你用chown -rf apache.apache /var/www/html/freechat/data/试试

chmod 777 -R /var/www/html/freechat/data

递归修改权限
或者向 @joyqi 说的把目录owner改成apache

chown -R apache:apache /var/www/html/freechat

Rpm系一定要记得setenforce 0,暂时关闭selinux后再测试

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
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

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 Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.