Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I know this question has popped up a couple times, but I can't seem to find a definitive answer to my issue, so please bear with me. I have Ubuntu Server 12.04 setup in VirtualBox for PHP development and testing (Drupal plus other PHP sites using Yii framework). My question is in 3 parts...

1) If I create a public_html folder under /home/myuser, do I need to give ownership of that folder to the Apache www-data group? If so, are there any specific permissions I should be setting? 755? (Btw, I am following this guide to create the public_html directory and set up multiple virtual hosts per site I create and test)

I previously had all of my sites under /var/www, but ran into massive permission denied errors whenever I tried to sFTP to it, either through FileZilla or PhpStorm. This is what I had previously done:

sudo chgrp www-data /var/www
sudo chmod -R 775 /var/www
sudo chmod -R g+s /var/www
sudo usermod -G www-data [my_ftp_user]

2) The second part of my question is this: If I create my PHP project and files in Windows through PhpStorm, and then upload via sFTP, will permissions get affected?

3) Once I am satisfied with my developed project, would it be advisable to move and test them under /var/www to see how it would fair in a production-ish environment?

I would really appreciate the help and advice here. I'm learning more as I go along, but dealing with Linux files and permissions is a bit of a new ballgame for me! Thank you

share|improve this question
    
Linode, provides a great guide for a person that's new to apache. You can do the same thing on your own machine for local development too. library.linode.com/hosting-website –  Brandon Bertelsen Dec 10 '12 at 23:05
    
great guide, thanks! So I don't need to worry about www-data? –  maGz Dec 10 '12 at 23:35
1  
It depends on if you're managing your server directly or not. If you have shell access, www-data becomes a little over kill for a development environment. But if you're distributing the software - others will have permission issues as well, so you'll have to figure them out. –  Brandon Bertelsen Dec 10 '12 at 23:36
    
yes, I have shell access, and its just for me developing and configuring the different sites before I publish them to a production server. –  maGz Dec 10 '12 at 23:43
    
In that case, I recommend just disabling the default apache site, and following the linode guide. If this is what you plan on doing, I'll port the linode guide to an answer so that we don't have stray links. –  Brandon Bertelsen Dec 10 '12 at 23:45

1 Answer 1

up vote 3 down vote accepted

I usually use this guide from linode for creating a local development environment: http://library.linode.com/hosting-website

The only personal addition I make to this is that sometimes, I want to test URL paths and things of that nature so I trick my computer into thinking localhost is www.example.com

sudo nano /etc/hosts

Add: 127.0.0.1 example.com Don't forget to remove it when you go live!

Note: DIRECTLY COPIED

  1. Disable the default Apache virtual host by entering the following command: ::

    sudo a2dissite default

  2. Navigate to your home directory by entering the following command: ::

    cd ~

  3. Create a folder to hold your website by entering the following command: ::

    mkdir public

  4. Create a set of folders inside public to store your website's files, logs, and backups. Enter the following command, replacing example.com with your domain name: ::

    mkdir -p public/example.com/{public,log,backup}

  5. Set your home directory to be readable and accessible to all users on the system by entering the following command: ::

    sudo chmod a+rx ~

  6. Set the public directory (and all of the files in it) to be readable and accessible to all users on the system by entering the following command: ::

    sudo chmod -R a+rx ~/public

  7. Create the virtual host file for your website by entering the following command. Replace example.com with your domain name: ::

    sudo nano /etc/apache2/sites-available/example.com

  8. Now it's time to create a configuration for your virtual host. We've created some basic settings to get your started. Copy and paste the settings shown below in to the virtual host file you just created. Replace example_user with your username, and example.com with your domain name.

.. colorize:: apache

# domain: example.com
# public: /home/example_user/public/example.com/

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin [email protected]
  ServerName  www.example.com
  ServerAlias example.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /home/example_user/public/example.com/public

  # Log file locations
  LogLevel warn
  ErrorLog  /home/example_user/public/example.com/log/error.log
  CustomLog /home/example_user/public/example.com/log/access.log combined
</VirtualHost>
  1. Save the changes to the virtual host configuration file by pressing Control + x and then pressing y.

  2. Create a symbolic link to your new public directory by entering the following command. Replace example.com with your domain name: ::

    sudo a2ensite example.com
    
  3. Restart Apache to save the changes. Enter the following command: ::

    sudo service apache2 restart
    
  4. Repeat steps 1-11 for every other website you want to host on your Linode.

share|improve this answer
    
thanks brandon! You said before ...still need to chmod individual folders...from within your user directory. Do u mean that I'll have to do a sudo chmod 755 or 777 on these? –  maGz Dec 11 '12 at 0:09
    
For example, if you're installing drupal, you may have to chmod 777 a cache folder. You would still have to do that. –  Brandon Bertelsen Dec 11 '12 at 0:27
    
thanks! okay, this makes sense now. Just needed to wrap my head around permissions for owners, groups and others. Am I assuming correctly that Apache will automatically take on the group permissions for any sites under public_html? –  maGz Dec 11 '12 at 0:33
    
No, but you have setup permissions using the instructions above so it won't matter. www-data (apache user) will have access. –  Brandon Bertelsen Dec 11 '12 at 0:34
    
i understand. Thanks again brandon for your help and patience. I'm sure I'll be able to work out the other minor issues –  maGz Dec 11 '12 at 0:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.