Centos – mkdir: cannot create directory ‘html’: No such file or directory

centos

I accidentally deleted the directory /var/www/html on a CentOS server, however the directory /var/www still exists. I cd'd into the directory /var/www and tried to create the directory html with the below command:

mkdir html

Unfortunately, this gives me this error:

mkdir: cannot create directory 'html': No such file or directory

I have searched for solutions to this, yet every Stack Overflow page I find says this is due to the parent folder not existing, such as the below. This is not my case however, as I am creating the child folder html from directly within www, with no parent folder being specified. I also tried the '-p' flag that is suggested, and get the same error.

https://askubuntu.com/questions/690702/no-such-file-or-directory-mkdir
mkdir: cannot create directory `../abc/2011-11-23: No such file or directory
I tried restarting the httpd service, yet get this error:

DocumentRoot '/var/www/html' is not a directory, or is not readable

I suspect it may be a permission issue, however I am logged in as root when doing this, and have full permission on the 'var/www' folder:

drwxr-xr-x  0 root www-data    0 Aug  8 11:42 www

Best Answer

I had a similar issue, and this was my checklist (for future reference):

  • (as you already said) parent directory not existent
  • you have no permissions to the file-system
  • the file-system is mounted read-only (this was it for me, even though I mounted it with -o rw)