Changing the directory name of web home directory

Hello… I would like to change the place where I put the root files of my virtual web directory from public_html to just public. I’ve tried moving the directory to a new location but it always creates a public_html as where I need to put my files.

How can I specify public rather than public_html

Dan Lewis

In Virtualmin/System Settings/Server Templates, select the template for Apache website. There are two places to make the change.

  1. Directives and settings for new websites - edit the line
    <Directory ${HOME}/public_html>

  2. Users’ website subdirectory to create

That did create the main web directory in public rather than public_html, but when I went to preview it the web browser gave me a 403 forbidden

The template change will be hassle-free for new virtual servers. But it’s not a fully automatic change if you’re updating the document root for existing virtual servers.

First check the Apache config for references to the old DocumentRoot. If the file needs updating restart Apache server and see if that works. For testing make sure there’s at least an index.html file in the public directory that displays something.

Second thing to check for is a leftover public_html directory with content still in it. If public is empty but public_html contains files, move the files to public.

If it’s still not working, your path with least resistance (no pun intended) may be to delete the virtual server and re-create it from scratch.

I deleted the virtual servers and I make the changes you suggested. The files were created in the public directory as expected. When I ran the preview to see how it looked I got a 403 forbidden You don’t have permission to access this resource.

Any idea why that happened?

You’ll get a 403 error if the directory is empty. Is there an index.html or index.php file?

Yes… I put an HTML file in it

I"m still getting the forbidden error

Did you check the ownership and permissions on the /public directory and the index.html file you planted in it?

Did you, perchance, create (or upload) said html file while root?

Is there an .htaccess file in the /public directory? If so, what does it contain?

Richard

@danwtsa, I think @RJM_Web_Design has narrowed it down, although I’ll bet Virtualmin got the directory permissions right.

Hello Richard… I thought of all those things too. I checked the permissions (the same as the files in the public_html directory and the ownership too. In fact, just to make sure I redid the ownership. I know a file or directory created and owned by root can’t be seen. I’ll double check again in the morning (it’s getting late here in Florida). But I thought the same thing… rights issues. In fact I deleted the existing virtual servers before I changed the location of the directory, and then I recreated the virtual servers. As a result, everything was created by the system not me (including the sample html file) I thought that way I couldn’t go wrong. But when I was all done access to the directory was forbidden. There is no htaccess file in it… it contains all the normal files you get when you create a new virtual server… index.html, awstats etc.

I figured it out! Other people may want to know!

Actually I just found the solutions. The solution is to edit the server template in two place in the first section

Go to Sever Templates Then select Apache Web Server (I’m using Ubuntu)

There are three changes you need to make

Two in this section
ServerName ${DOM}
ServerAlias www.${DOM}
ServerAlias mail.${DOM}
DocumentRoot ${HOME}/public
ErrorLog /var/log/virtualmin/${DOM}_error_log
CustomLog /var/log/virtualmin/${DOM}_access_log combined
ScriptAlias /cgi-bin/ ${HOME}/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory ${HOME}/public>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch

<Directory ${HOME}/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch

Users’ website subdirectory to create Default (public_html) Directory under home - name this the same as the others… in my case public

Then when you generate a new domain the entire directory structure will be exactly right but the name of the directory where the website code goes is changed from public_html to whatever you want to call it. In my case I called it public

2 Likes

Sorry I left out the DocumentRoot line above. Glad you found it.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.