SFTP (SSH/Secure File Transfer Protocol) is a network transmission standard used to transfer, access, and manage files over a remote network. It contains SSH (Secure Shell), making it a lot more secure than the FTP protocol.
cPanel’s Domains page lists all domains on your account, including aliases, addon domains and subdomains. You can also use the interface to create and manage domains. The main things you can do are:
- Add an alias, addon domain or subdomain.
- Remove an alias, addon domain or subdomain.
- Force website traffic to be redirected to HTTPS. This option is only available if you got a SSL certificate for a domain.
It is worth noting that the Domains page doesn’t do anything that can’t be done elsewhere in cPanel. It simply combines all domain-related sections in a single interface.
- Prerequisites
- Step 1 – Update Document Root in cPanel
- Step 2 – Changes Document Root for SSL
- Step 3 – Rebuild and Restart Apache
- Change/Share Document Root?
- Минуточку внимания
- Step 1 – Installing SSH (Secure Shell)
- Adding a subdomain
- Step 5 – Adding SFTP User to www-data Group
- Step 6 – Setting Document Root Directory Permission
- Step 2 – Configuring SSH to use the SFTP Server Code
- Domains list
- Adding an addon domain
- Adding a domain alias
- Step 4 – Creating Match User Directive in the SSH configuration file
- Aliases, addon domains, subdomains and redirects
- Step 3 – Creating a User(SFTP User)
- Managing domain settings
- Final thoughs
Prerequisites
Step 1 – Update Document Root in cPanel
vim /var/cpanel/userdata/USERNAME/DOMAINNAME.COM
After editing file, search for text documentroot and change path as per your requirements.
documentroot: /home/USERNAME/public_html/NEW_PATH
Step 2 – Changes Document Root for SSL
Edit file in text editor
vim /var/cpanel/userdata/USERNAME/DOMAINNAME.COM_SSL
and apply the same changes as above.
documentroot: /home/USERNAME/public_html/NEW_PATH
Step 3 – Rebuild and Restart Apache
/scripts/rebuildhttpdconf service httpd restart
Your changes will be permanently updated. Check your site for reflecting changes.
Read this: Install and Secure cPanel from DDOS Attack with CSF
Thanks You! for using this article.
- Home
- Forums
- Support
- Help! (Home for newbies)
- Change/Share Document Root?
Thu, 09/17/2015 — 19:37
Change/Share Document Root?
It does not seem like it is possible.
What I am trying to do is set up this WordPress mulitblog ‘hack’;
I’ve done it in the past on Kloxo, cPanel and at least one other by simply changing the Document Root.
Is there anyway to do this via Virtualmin/Cloudmin in a click and type fashion OR am I going to have to create SymLinks via SSH. I tried PHP SymLinks with no luck.
Fri, 09/18/2015 — 10:44
Would it be possible to setup the new domain as an alias?
Fri, 09/18/2015 — 14:46
Hey Eric, so I actually tried that.
Additionally, the alias/domain does not resolve.
- Dan
Fri, 09/18/2015 — 15:09
Is that what you’re after?
If so, then it sounds like we may just need to figure out why the domain name wasn’t resolving.
It sounds like you’re seeing a DNS issue of some sort, which is definitely solvable.
Mon, 09/21/2015 — 22:13
Here is what I’ve got.
domain.com (where the WordPress Multiblog is installed and working properly)
What I am after is either
This is how I created the symlink
I’ll take either version. I just need it to work.
i got it to work.
Thanks for your help!
Thu, 09/24/2015 — 10:47
Nuts, I didn’t get a chance to respond to your comment on Monday. But I am glad you’ve figured it out, that’s excellent!
Как такое могло случиться? Куда копать? Подскажите, товарищи!
-
Вопрос заданболее трёх лет назад
-
3632 просмотра
Не знаю как сейчас, но лет эдак 5 назад, я помню, у Apache’а было 2 режима работы на эту тему:
а) Нормальный режим
б) Режим автоматического создания поддоменов на основе файловой системы (т.е. создаёте папку — она становится поддоменом)
В режиме «Б» была такая особенность, что при создании поддомена таким образом, физически в конфигурации сервера этого поддомена не присутствовало, вернее будет сказать, он наследовал все настройки родительского домена, от того и DOCUMENT_ROOT и некоторые другие настройки, могли туда попасть из домена-родителя.
Переменная $_SERVER
заполняется на основе информации, полученной от сервера.
В случае Nginx это встроенные переменные, которые задаются через директиву fastcgi_param.
$document_root — значение директивы root или alias для текущего запроса.
$realpath_root — абсолютный путь, соответствующий значению директивы root или alias для текущего запроса, в котором все символические ссылки преобразованы в реальные пути.
В вашем случае нужно переопределить DOCUMENT_ROOT
на уровне location: (пример)fastcgi_param DOCUMENT_ROOT $realpath_root;
Из-за таких особенностей на DOCUMENT_ROOT
обычно не завязываются, задавая директорию для ROOT иначе.
Добрый день.
Из официальной документации
‘DOCUMENT_ROOT’
Директория корня документов, в которой выполняется текущий скрипт, в точности та, которая указана в конфигурационном файле сервера.
‘SCRIPT_FILENAME’
Абсолютный путь к скрипту, который в данный момент исполняется.
‘HTTP_HOST’
Содержимое заголовка Host: из текущего запроса, если он есть.
04 июл. 2023, в 22:15
15000 руб./за проект
04 июл. 2023, в 21:50
50000 руб./за проект
04 июл. 2023, в 21:49
50000 руб./за проект
Минуточку внимания
I installed the ubuntu 12.04 server edition for my server pc . i had installed lamp server. i need to change the var/www location to my secondary hard disk location. i was configured so many time to at gedit /etc/apache2/sites-available/default here is my code
<VirtualHost *:80>
ServerAdmin webmaster@localhost
#DocumentRoot /var/www
DocumentRoot /media/myserver/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
#<Directory /var/www/>
<Directory /media/myserver/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
and also used
sudo chown -R var/www /media/myserver/
chmod -R 755 /media/myserver/
Forbidden
You don't have permission to access / on this server.
Please tell anyone how to mount myserver at my var/www, thanks advance
16 gold badges78 silver badges101 bronze badges
asked Aug 27, 2013 at 12:38
You’ll have to edit apache2.conf
and 000-default.conf
to change the document root of apache.
The Apache server is installed on /var/www/html
.This is the default root directory of apache.
Either change the root directory of Apache or move the project to /var/www/html
.
To change Apache’s root directory, run:
cd /etc/apache2/sites-available
Then open the
000-default.conf
file using the command:nano 000-default.conf
Edit the
DocumentRoot
option:DocumentRoot /path/to/my/project
Then restart the apache server:
sudo service apache2 restart
Find the
apache2.conf
located in/etc/apache2
and open it using:nano apache2.conf
Use Ctrl+W and search for Directory (It should be in line 153)
It should look like this
<Directory /> Options Indexes FollowSymLinks AllowOverride All Require all denied </Directory>
Change it to
<Directory /> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Require all granted </Directory>
sudo service apache2 restart
I made a script that changes apache root in a single command. You can find it on my github.
7 gold badges70 silver badges94 bronze badges
answered Feb 24, 2016 at 13:23
Maybe a little bit late. But still..
You should edit your directory permissions in apache.conf under /etc/apache2
Search for this
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
and add this code under of it, which gives the permission to access your directory
<Directory /media/myserver/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
answered Feb 15, 2014 at 12:10
Simply change the document root in your activated configuration. /etc/apache2/sites-enabled/000-default
and then Make sure reloading your apache.
So try with this:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /media/myserver/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /media/myserver/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then the proper permission should be given like this:
sudo adduser <username> www-data
sudo chown -R www-data:www-data /media/myserver/
sudo chmod -R g+rw /media/myserver/
answered Aug 27, 2013 at 13:06
16 gold badges78 silver badges101 bronze badges
you modify
apache2.conf
. Replace/var/www/
with/your/path
:<Directory /your/path/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
Modify the
000-default.conf
file:DocumentRoot /your/path/
Change the ownership of the directories to yourself from file manager or terminal (e.g.
sudo chown pi: path
). Without this you will get this error message:You don't have permission to access / on this server.
answered Apr 25, 2019 at 21:41
As a quick workaround (safe and quick) you can make the mounting point of your external hard driver to the default root directory ( /var/www by default).
Assigning the mounting point to a per-existing directory is safe but the old content can’t be reached unless you unmounted the driver.
answered May 27, 2017 at 9:24
in virtual configuration :/etc/apache2/sites-available/site.conf
ServerAdmin anilrmg@localhost.com
ServerName anilrmg.localhost.com
ServerAlias www.anilrmg.localhost.com
DocumentRoot /home/anilrmg/projects/code/anilrmg
sudo a2dissite 000-default.conf
7 gold badges29 silver badges45 bronze badges
answered Mar 17, 2015 at 10:59
For those who use VirtualBox guest additions and get you don't have permission to access /on this server
despite of everything mentioned above:
sudo usermod -a -G vboxsf www-data
answered May 27, 2016 at 16:01
I had to make sure the whole path was granted Apache.
chown www-data /media;
chown www-data /media/MNT/;
chown www-data /media/MNT/DISK;
chown www-data /media/MNT/DISK/www-root;
answered Dec 6, 2020 at 16:07
1 silver badge8 bronze badges
Step 1 – Installing SSH (Secure Shell)
SFTP is a very secure file transfer protocol because of the encryption that SSH provides for the data as it is transferred over the network. SSH is mainly installed on Linux distributions by default, but if it is not pre-installed in your system, then you can use the below-given command to install it:
sudo apt install ssh
If already installed, the command will upgrade OpenSSH packages.
Adding a subdomain
Image: creating the subdomain shop.example.net
In the above image I created the subdomain shop.example.net. The subdomain’s document root is automatically created. Again, you can change the name of the directory where the website files are stored. However, you normally don’t need to do so. The default option is sensible.
Step 5 – Adding SFTP User to www-data Group
sudo usermod -a -G www-data sftpuser
On a successful run, no output will be displayed.
Step 6 – Setting Document Root Directory Permission
- We will start by checking the current permissions and ownership of var:
sudo ls -ld /var/
- The permissions should be 755 and the owner should be root by default. If not, then execute the command given below to set the proper permissions:
sudo chmod 755 /var/
- Now use this command to set the correct ownership:
sudo chown root:root /var/
- Since we have set “/var/www/” to the chroot directory. Now set the right ownership of the chroot directory:
sudo chown root:root /var/www/
- To allow a group to write to the document root directory, set its permission to 755:
sudo chmod 755 /var/www/html/
- To grant the ownership of the “/var/www/html” document root and its further directories and files to the www-data group, use the below-given command:
sudo chown -R www-data:www-data /var/www/html*
- Now give 755 permissions to the content placed in the “/var/www/html” document root using the command:
sudo find /var/www/html/ -type d -exec chmod 775 {} \;
- The above command will grant the SFTP user read, write, and executable permissions of the directories.
sudo find /var/www/html/ -type f -exec chmod 664 {} \;
- Now for the last step, make certain that all the new files and directories acquire the www-data group that are created the newly created SFTP user:
sudo find /var/www/html -type d -exec chmod g+s {} \;
Similarly, apply the same permissions to the chroot:
sudo chmod 755 /var/www/
Step 2 – Configuring SSH to use the SFTP Server Code
Now open the configuration file of SSH in a text editor to modify it for SFTP server code. Here we will use the nano editor to edit the configuration file.
sudo nano /etc/ssh/sshd_config
Locate the line starting from “Subsystem sftp”.
Subsystem sftp internal-sftp
The SSHD will use the SFTP server code instead of running the SFTP server by changing the above line.
Once you have changed the configuration file, save the file and exit from it using the keyboard shortcut keys CTRL+S and CTRL+X.
After changes, we need to restart the SSHD daemon to let the changes work.
sudo systemctl restart sshd
Domains list
The main Domains page lists all domains on your account. In the below image I got only one domain: example.net.
Image: cPanel’s Domains page.
- Document Root is the location where the website files are stored. Clicking on the link opens cPanel’s file Manager.
- Redirects To shows if the domain redirects to another domain (and if so which domain).
- Force HTTPS Redirect can be set to ‘On’ or ‘Off’. Setting the option to ‘On’ will redirect traffic from http://example.net to https://example.net. This option is disabled if a domain doesn’t have an SSL certificate.
- The Action column provides links to more options for managing the domain.
Adding an addon domain
Image: creating the addon domain example.co.uk
When you create an addon domain cPanel automatically creates a subdomain. The subdomain is created because an addon domain is simply a subdomain with an alias. It seems a little odd but it is how cPanel works its magic in the background.
Adding a domain alias
Image: creating an alias (by leaving the checkbox ticked).
After hitting the Submit button you should see a Success message. The notification doesn’t explicitly say that the new domain is an alias. However, you can tell by looking at the information about the domain: example.com has the same document root as the main domain. In other words, the domain example.com shows the content of the domain example.net.
Image: the domain example.com has been added as an alias.
Step 4 – Creating Match User Directive in the SSH configuration file
sudo nano /etc/ssh/sshd_config
Match User sftpuser ForceCommand internal-sftp ChrootDirectory /var/www/ PasswordAuthentication yes X11Forwarding no AllowTcpForwarding no
Once the above content is added to the SSH configuration file, save and exit using CTRL+S and CTRL+X shortcut keys.
To check the syntax and verify if everything went well, you can execute the command:
sudo sshd -t
If no error occurred, we could reload the SSH service for the changes to work.
sudo systemctl restart sshd
Aliases, addon domains, subdomains and redirects
Aliases, addons domains, subdomains and redirects are discussed in detail in other articles. However, here is a brief summary of what they are:
- Aliases or parked domains display the content of another domain.
- An addon domain is an additional domain on your cPanel account. Addon domains are independent from your primary domain.
- Subdomains are child-domains, such as shop.example.net or dev.example.net.
- Redirects sends traffic for one URL to another URL. You can redirect a whole domain (for instance, you can redirect example.com to example.net) or individual pages.
Step 3 – Creating a User(SFTP User)
sudo adduser sftpuser
Managing domain settings
You can click the Manage button to view basic information about a domain. In the below image you can see details about the domain example.co.uk.
Image: managing the example.co.uk domain.
The page is mainly a summary of the domain. You can change the document root, but that is about it. However, there are a few handy quick links to other cPanel pages:
- Create an email address opens the Email interface.
- Modify the zones opens the Zone Editor.
- Modify the redirects takes you the Redirects page.
Final thoughs
The Domains page is a relatively new cPanel feature. While some people find it convenient to have a single page for any type of domain, others find the page rather confusing. The main thing to remember is that you don’t have to use the Domains page. There is nothing wrong with creating an addon domain via the Addon Domains page. Similarly, it is perfectly fine to create a subdomain via the Subdomains section.
If you are new to the various types of domains then it is useful to try to understand the information shown on the page. It is a good place to learn about domains.