I am interested in setting up a local php testing / development environment using the lamp stack.
I would like to use the php plugin for eclipse (I typically work with java and am very familiar with eclipse).
First of all, is it proper practice to develop my site locally directly within the apache /var/www directory?
If this is ok, can somebody describe how to properly set the permissions of the www directory so that eclipse (not being run as root) has access to read/modify php files within that directory?
This is strictly for local development so I assume security isn't as high of an issue.
It doesn't matter, I personally placed it in /var/www/ and put it under the www-data group, and placed my username into the www-data group.
You add yourself into the group with:
sudo usermod -a -G www-data <username>
Change the group to www-data just in case you haven't:
sudo chgrp -R www-data /var/www
Get new files to inherit the permissions (750)
sudo chmod -R 2750 www-data /var/www
Some people prefer to put it in /home/username/www/ which would be easier.
If you prefer to put it somewhere else, like your Eclipse workspace directory, you can change Apache's DocumentRoot (or create a VirtualHost with a different DocumentRoot). Edit Apache's httpd.conf file, and add this at the end:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mytestserver.localhost
DocumentRoot /path/to/project/dir
</VirtualHost>
The *s can be left as-is; that means they will work regardless of your IP address.
The ServerName can be anything you want, as long as you add a corresponding entry in your /etc/hosts file, e.g.:
127.0.0.1 mytestserver.localhost
I often make all my local servers end in ".localhost", just as a convention.
Finally, restart Apache. Then you can access the server at http://mytestserver.localhost. Repeat as necessary to use multiple virtual hosts, each pointing to a different project.
As long as the files can be read by everyone, which is usually the default, you should be fine.
It's definitely possible to work on your site directly in your server's /var/www/ directory. however, it's probably better practice to setup a local environment (using something like XAMPP) to edit your website on a development machine and then upload it to your live server when it's ready. that way you don't introduce any bugs or errors into the live site temporarily.
Related
I just launched a LAMP dropplet from Digital Ocean and am starting coding. When trying to create a new directory inside the web root it says
mkdir: cannot create directory ‘blog’: Permission denied
I can fix this by running chown -R user /var/www/html but I'm wondering if this will break things or if there's a better way of doing this. Thanks!
You have a variety of options on permissions, but essentially www-data needs read (and probably execute) permission.
I like to redefine the DocumentRoot in my VirtualHost definitions to use something other than /var/www/html, anyway.
For example, you could use /srv/www/sitename, and then assign permissions myuser:www-data to it.
There are also numerous threads on the DigitalOcean forums (and around the internet) about permissions schemes for web files. (e.g. Proper Permissions for Web Server Directory.)
I am trying to migrate a web application from a Slackware config of Apache to a CentOS 7 one. DocumentRoot set to /home/STORAGE and there is a simple index.html file in it for testing. Both /home/STORAGE and index.html have 777 permissions set, yet Apache reports :
access to /index.html denied ... because search permissions are missing on a component of the path.
On the other hand, phpMyAdmin works fine, configured with a separate .conf file in /etc/httpd/conf.d . I tried using their example to make a .conf file for my app, but it still reports the same error. I don't even know where to start looking here.
EDIT:
I think this has something to do with the user of Apache. It is set to a local user in httpd.conf not to root, but the only pages the server serves are those in directories owned by root.
It was not a permission error but a Selinux issue. I decided to use the default /var/www/html for the application but still, had to allow write access to some dirs. Here is what I typed:
sudo chcon -t httpd_sys_rw_content_t /some/dir/in/var/www/html -R
The first time I typed it without -R and the permissions didn't change (check with ls -Z /dir/path). Now it is fine.
I'm running dev server on Centos 6.4 with Apache 2.2. I just moved a site from the production to dev to perform upgrades. I modified file owner to apache:apache (httpd user) and set all directories to 755 and files to 644. I have few other sites in the DocumentRoot folder with similar settings and they run fine (using same CMS, PHP, MySQL versions etc).
I have no virtual hosts defined and Allow all on everything. httpd.conf is default.
I'm not able to make site working from the folder I just moved from the production. I'm getting 403 every time.
As suggested in
https://serverfault.com/questions/272947/apache-on-centos-5-6-gives-me-permissions-denied-error/272956#272956
Usually that comes from Selinux not giving access to the folder. do
ls -alZ /var/www
and if the html folder doesn't have the context system_u:object_r:httpd_sys_content_t, fix it with chcon
chcon -v -R --type=httpd_sys_content_t /var/www/html
http://wiki.centos.org/HowTos/SELinux
I'm just a newbie for Apache. I just installed apache 2.2 on the FreeBSD box at my home office. The instruction on FreeBSD documentation is that I can change the DocumentRoot directive in order to use the customized directory data. Therefore, I replaced...
/usr/local/www/apache22/data
with
/usr/home/some_user/public_html
but something is not right. There's index.html file inside the directory, but it seems that apache could not read the directory/file.
Forbidden
You don't have permission to access / on this server.
The permission of
public_html
is
drwxr-xr-x
I wonder what could be wrong here. Also, in my case, I am not going to host more than one website for this FreeBSD box, so I didn't look at using VirtualHost at all. Is this a good practice just to change the DirectoryRoot directive?
Somewhere in the apache config is a line like:
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/usr/local/www/apache22/data">
You must change this path too, to make it work. This directive contains for example:
Order allow,deny
Allow from all
Which give initial user access to the directory.
one possibility that comes to mind is SELinux blocking web process from accessing that folder. If this is the case, you would see it in selinux log. You would have to check the context for your original web root with:
ls -Zl
and then apply it to your new web folder:
chcon whatevercontextyousaw public_html
Or, instead, if its not a production server that requires security (like a development machine behind a firewall), you might want to just turn selinux off.
Just one idea. Could be a number of other things.
I am using this guide:
http://codingthis.com/platforms/linux/how-to-host-simple-content-with-amazon-elastic-cloud-computing-ec2/
I have a folder named public_html in my /home/ec2-user directory with a test.html file.
What I have done so far:
sudo yum -y install httpd php
sudo chkconfig httpd on
chmod 755 /home/ec2-user (I HAVE NO IDEA WHAT THIS DOES)
sudo nano /etc/httpd/conf/httpd.conf
(changed DocumentRoot to DocumentRoot /home/ec2-user/public_html)
TLDR: How do I make it load my content (my html file) instead of the apache test page
EXTRA:
I have a security group enabled for my instance with rules:
ICMP Allow ALL
TCP Allow ALL
UDP Allow ALL
TCP port 80 (Http)
isnt your document root public_html instead of www? so why did u put ur pages under www directory?
If you have no content in the DocumentRoot that you configured then the default Apache install will show you that page instead of yours. Also, check the DirectoryIndex configuration to make sure that if you're using index.php or default.html or something else that this is configured as well. It defaults to index.html
Chmod755/directory/directory/etc.. Will give access to that directory. So if your website is in the folder *home/ec2-user/public_html* you would then need to give access to that directory.
Example: chmod 755 home/ec2-user/public_html
I was having the same issue. I fixed it by changing the permissions on the ec2-user directory like so:
chmod +x home/ec2-user
This give execution permissions to everyone on your user directory.
I had the same problem. All I have to do was just restarting the ec2 to apply the changes. - takes me 2h :(