I have just installed a new LAMP server inside Ubuntu server. This was done using tasksel, while login as root user. I want to move apache document root into /home directory. Please advice, should i create new user other than root or just go with root and place the document root under eg. /home/public_html ?
Related
Good Morning,
I am currently setting up and apache2 server on my raspberry pi. My index.html file is in the directory /var/www/html and the file is loading fine when I go to the IP address. However, the images located in /var/www/html/img are not loading. The html is like this: <img alt="image1" src="img/picture1.png">. When I right click on the alternative image icon, and select open image in new tab, I get:
You don't have permission to access /img/picture1.png on this server.
Server unable to read htaccess file, denying access to be safe
How can I prevent this and make the user able to access the image?
Many thanks,
Try
chmod -R 755 /img/
this will set the permission for all files in the folder readable and executable for all, and also writable by the owner.
The output will be in the form
-rwxr-xr-x 1 root root 0 Apr 5 12:38 picture1.jpg
I have apache2 server with a private IP.
Also, I have multiple applications that need to run on the same server.
Is there any solution to setup different document root for each application
Like ..
http://xx.xx.xx.xx/application to doc root /var/ww/html
http://xx.xx.xx.xx/application1 to doc root /var/www/html/app1/public
http://xx.xx.xx.xx/application2 to doc root /var/ww/html/app2/public
I can't access my apache server from outside the server or from ubuntu user rather than root user.
Could anyone help me ?
It's because wget is trying to write the index.html file on the /var/www directory (your current directory), and your user can't do it (whereas root user can write in this directory).
I'm using Ubuntu 14 server from DO, with LAMP stack installed, i followed the instruction here to install flask on ubuntu because my main purpose was to use Flask on my website.
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps
During the test, when user connects to "http:/myvpsip/createfile/" which creates a new file on the current folder /var/www/, I got error from Apache saying that the file cannot be created, "permission denied".
I tried again using PHP script that create a new file on the same directory /var/www/ but got the same problem. Both of the trials were done using root account. I tried to chmod the www folder to 755 or 777 and they are not working.
My question is, how do I set permission for apache2 that when users browse the website they will be able to create/edit file on the current directory?
Thank you
This is because when you installed your application, you did so as the root user. All your application files and directories are owned by root.
If you ls -l on /var/www and look inside the FlaskApp folder structure, you will likely see permissions set like this:
-rw-r--r-- 1 root root
When Apache runs, it runs on behalf of a main process owned by the user root and several child processes owned by the user www-data. So essentially, Apache is running as if logged in as user www-data.
When your application needs to do a file or folder operation (its running on behalf of Apache www-data user), the public/world permission bits are used since Apache child processes are not running as root user and not as root group.
Looking above, we see that only the read bit is set for the public/world permissions - no write. And that is where the problem lies.
One way to solve this is to make everything under /var/www/mywebsite owned by the user root and the group www-data. This sets things up so that only the root user can have full permissions and www-data (everyone else) can only read and execute (no write).
When you setup your website, you should set it up to be under its own separate folder. This way you can have multiple virtual domains (i.e. more websites) added later on. Assuming 'mywebsite' is where your domain is and you have already installed your application software (Flask) within it:
cd /var/www/mywebsite
chown -R root:www-data /var/www
You then as the system administrator, need to understand the application and go through the folders and files setting permissions. Apply permissions generally, then on a case by case basis.
For most directories (750)
- Only root can rwx directory
- www-data can only read and execute directory
- no public/world bits set as it makes no sense (*)
For directories that can be changed by web application (770)
- Root can rwx directory
- www-data can rwx directory
- no public/world bits set as it makes no sense (*)
- for uploading files, creating images, documents, etc by the users of the site
For most files (640)
- Never set the execute bit to avoid execution of misplaced shell or executable files
- PHP, Perl, etc. are just text files. They have nothing to do with exec permission
- No group write bit set
- Read must be set for owner and group else they cant see the web document
For special case where files need to be changed (660)
- Set group write bit if you want www-data users to create things
(*) Because all users who visit Apache are running on behalf of www-data
I have dedicated server and have root accesss via ssh putty - I have 1 account set up on the server but I'm trying to workout how i can access the public_html directory of this account from root#ds-44498 [~]# the public_html in the root is empty.
I'm trying to copy a file from the root to the account public_html folder
I have WHM - cpanel
Thanks
Have found answer: in /home/accountname/public_html/
thanks