Changing the name of the public_html folder - apache

I have two folders for a particular web site. There is the main www.mysite.com site which is at home/user/public_html and then I have a sub domain -> dev.mysite.com for the latest under development version of the site at /home/user/dev_html
Maybe because of laziness in the past when moving the new site to the main directory, I have just backed up the current site, downloaded it via ftp, erased the site files and then uploaded the new site. However, ftp is so slow and unreliable that this is a ridiculously slow and error prone way of doing it - especially for big sites.
So I was thinking of just logging in via ssh and then moving all the files out of public_html and then copying the new files from dev_html but then it struck me. Can't I just change the name of the public_html folder to something like public_html_old and then change dev_html to public_html? Will Apache go mental if I do this?
Forgive me if this is a stupid question.

What you propose is fine. In fact, you can do it in one line from the CLI.
mv public_html public_html_old && mv dev_html public_html
You can also try the following...
Create a symbolic link to the current main site, eg (assuming the current site resides in a v1_html directory)
ln -s v1_html public_html
Then, to switch document roots...
rm public_html && ln -s v2_html public_html

If you can access the server in SSH, you can use cp command to copy your directory files to public_html or rename the folder as you suggested.
Be sure to stop the Apache service first.

Related

How can I fix my homepage showing a 403 error?

I keep getting a 403 error on my homepage, despite having all my permissions set to allow public to read. I'm not using any plugins, I'm not using Wordpress, and though my site is routed through Cloudflare it goes through to my hosting provider's 403 page (I haven't created my own). I've tried 755 and 644 and I keep getting the same thing. How can I fix this?
(The website is alexbelman.com)
There are several possible reasons depending on your hosting environment and a bit more detailed info from you about your hosting setup would help. For example - is your site on a server running Linux? cPanel?
But maybe this info can help you in the meantime:
If you're sure you have the correct permissions on folders (in most cases your public_html folder should be 750, all folders within the public_html folder in most cases should be 755, and files should be 644) then probably the first two things I would check would be:
Make sure you have an index file in your public_html folder - some examples would be index.html , index.htm , index.php , or on some hosts a default.html is used. If there is no index file in the folder that serves your site, server security configs will often present a 403 while protecting the sensitive contents of your hosting account from being viewed.
If you're sure you have an index file in your public facing folder, then check the contents of the .htaccess file in your public_html folder, since an errant rule or line of code in your htaccess is a common cause for a 403
If you can post the contents of your .htaccess file here someone here or possibly myself can spot anything that shouldn't be there or is incorrect.
Also, since you're using CloudFlare you should take a look at their Quick Fix suggestions here - https://community.cloudflare.com/t/community-tip-fixing-error-403-forbidden/53308

"This webpage is not available" error after altering /www directory

I built the login functionality for a website on an AWS ec2 ubuntu with LAMP setup and it was working fine. The PHP files for this were located in /var/www/html. Then, to also allow login from an android device, I added and began working on the directory android_login_api in the /www folder. After adding several files and directories to this I noticed the website was no longer working and displayed "This webpage is not available" when I attempted to reach it. Despite completely removing android_login_api and attempting to revert the directory /www to just the way it was when it worked, this error remains.
I have spent a few days searching for a solution, but most answers pertain to the setup of apache which was already working fine for me. I tried restarting apache but neither index.php nor any other files I specify can be reached. I have also spent a lot of time trying to edit apache .conf files but with no luck.
Any ideas about what may have happened or if there is a specific path I need but may have accidentally altered would be greatly appreciated.
Most of access problems are caused by incorrect configuration of Virtual Hosts which seems like the problem here.
As you mentioned, the readable directory was /var/www/html and then you tried to access /var/www/android_login_api, which is not accessible by default and is specified in your virtual host file for the website. Location: /etc/apache2/sites-available
If you have done it different to this article, it will be difficult for anyone to help you. Don't create hosts in apache.conf. Read it before reading my answer further.
When you make changes to the virtual host, don't forget to use sudo a2ensite yoursite.com.conf as well as restarting apache service with sudo service apache2 restart after enabling the site.
The last thing that you should know about setting up websites is www directory owner. When you done making changes to files via FTP or SSH, run sudo chown www-data:www-data /var/www -R. www-data is the username like root used by Apache to allow external access. Otherwise the fiels will be accessible only with 0755 permissions by any other user and not 0644.
This is just a bunch of things essential to make changes and work with HTTP servers. Though my answer is not clear and I'm unable to point out your issue, I believe I've given you additional knowlege/consideration points to troubleshoot your issue. Drop a comment for more specifics.

XAMPP: How to make apache webserver owner of folder /htdocs

I am using XAMPP and apache as webserver. I have permission problems with a website of mine that requires write access to a temporary folder in the project folder /htdocs/myProject/tmp
It think my problem is that my site runs on my localhost and I copied the project with my regular desktop user into the htdocs folder. Apache seems to lack write permissions.
My question is now: How do I found out which user group apache belongs to in order to make that group owner of the folder? That should fix my permission problem, shouldn't?
As far as I understand, the Apache (Webserver) has an own user called "www-data". Maybe an already answered question on SO has a solution, which you can use.
The used command relies on a linux-based system and that you navigated in a terminal to a directory, where /htdocs is located.
This command in the answer of the link below allows you as a humanoid user to write and work in this specified directory.
You add www-data (Apache) to use this directory, too.
New files of that chown'ed directory will 'inherit' the owners.
The Link and further descriptions can be found here on Stackoverflow.com:
www-data permissions

apache and File system permissions

the default install of apache in CentOS or RHEL, looking at file system permissions for html directory in /var/www/
drwxr-xr-x. 2 root root 4096 Aug 13 2013 html
My website works, and I have no issues with it, however I would like to know why and when do we need to set the directory to apache:apache?
Thank you
Since Apache is not running as root (presumably, hopefully), it only has read permissions on the directory as part of the last o=rx. This is a good default, since it means that it cannot alter the directory, only passively read and serve files from it. Everything running under an Apache process (e.g. mod_php) thereby has the same restrictions. That prevents a lot of common rookie exploits, like allowing uploads of .php files into a public web folder; because Apache/PHP cannot write into the web folder.
You should assign directories that Apache/PHP/CGI should explicitly be able to write into to apache/www-data (depending on your OS/configuration). It's not typically a good idea to do this with any directory under /var/www, you should leave that read-only as much as possible. However, adding an application-specific folder to something like /usr/local/var/<my website> with write permissions for Apache and selectively sym-linking or mod_rewriting to it is fine.
When your website need permission to modify direction/file on web app folder, you have 2 choices: 1) chmod folder to 777/666 or 2) change owner of these folders/files to apache
Sometimes, change owner is prefer to chmod because of security reason.

Just messed up a server misusing chown, how to execute it correctly?

I'm moving from an old shared host to a dedicated server at MediaTemple. The server is running Plesk CP, but, as far as I can tell, there's no way via the Interface to do what I want to do.
On the old shared host, running cPanel, I creative a .zip archive of all the website's files. I downloaded this to my computer, then uploaded it with FTP to the new host account I'd set up.
Finally, I logged in via SSH, navigated to the directory the zip was stored in (something like var/www/vhosts/mysite.com/httpdocs/ and ran the unzip command on the file sitearchive.zip. This extracted everything just the fine. The site appeared to work just fine.
The problem: When I tried to edit a file through FTP, I got Error - 160: Permission Denied. When I Get Info for the file I'm trying to edit, it says the owner and group is swimwir1.
I attemped to use chown at this point to change owner - and yes, as you may be able to tell, I'm a little inexperienced in SSH ;) luckily the server was new, since the command I ran - chown -R newuser / appeared to mess a load of stuff up. The reason I used / on the end rather than /var/www/vhosts/mysite.com/httpdocs/ was because I'd already cded into their, so I presumed the / was relative to where I was working. This may be the case, I have no idea, either way - Plesk was no longer accessible, although Apache and things continued to work. I realised my mistake, and deciding it wasn't worth the hassle of 1) being an amateur and 2) trying to fix it, I just reprovisioned the server to start afresh.
So - what do I do to change the owner of these files correctly?
Thanks for helping out a confused beginner!
Jack
Your command does indeed specify an absolute path to the root of the filesystem. Any path that begins with a '/' is absolute. You need:
chown -R newuser .
or:
chown -R newuser /var/www/vhosts/mysite.com/httpdocs