This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Apache vhost for Symfony 2.2.1 on Ubuntu 13.04

Discuss installing Symfony 2 here

Apache vhost for Symfony 2.2.1 on Ubuntu 13.04

by stevec » Tue May 14, 2013 12:41 am

I've been doing PHP for a while, but this is my first time trying to work with Symfony.

I'm trying to follow along with the book, but Apache and/or Symfony is causing me issues trying to get to where I can actually load the configuration page (or any page for that matter).

Here is my virtual host in /etc/apache2/sites-enabled/project:
Code: Select all
<VirtualHost *:80>
        ServerName dev.machine/project
        ServerAdmin webmaster@localhost

        DocumentRoot /home/user/project/web
        <Directory /home/user/project/web/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error-project.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel info

        CustomLog ${APACHE_LOG_DIR}/access-project.log combined

</VirtualHost>


For some reason Apache isn't letting this get anywhere. The error.log shows:
[Mon May 13 18:36:45 2013] [error] [client 127.0.0.1] File does not exist: /var/www/project
[Mon May 13 18:36:45 2013] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico

Now this alone is frustrating enough, because from what I know of Apache the DocumentRoot and Directory calls *should* make it look in the project directory and not /var/www. However since I want to get this running so I can actually use symfony, I went ahead and made a symlink from /var/www/project => /home/user/project/web and now I just get a list of the files in project/web.

I thought this was the correct place to point symfony? What am I missing? I've looked at multiple tutorials and they seem to think it should work from there, but most of them aren't using vhosts so they're using the default apache www directory.

Thanks for any help!
stevec
Junior Member
 
Posts: 3
Joined: Mon May 13, 2013 11:49 pm

Re: Apache vhost for Symfony 2.2.1 on Ubuntu 13.04

by stevec » Thu May 16, 2013 11:28 pm

Still plugging away at this, with only limited success.

I've modified the virtual host, and the current config follows at the end.

Currently I can:
1. Go to http://server.com/project/app_dev.php and get the Symfony2 Welcome/Congratulations page.
2. Use the app_dev.php front controller to configure the database.
3. Create a bundle using app/console and get to that bundle via http://server.com/app_dev.php/bundle/
4. Use app/console to connect my bundle to my (remote) database via Doctrine (yay!).

What I cannot do but would like to:
1. Go to http://server.com/project/app.php and get to my bundle. Right now it gives me what I think is Symfony's default 404 error message.
2. Go to http://server.com/project/ and get to my bundle. This is presumably the exact same problem as above, but ultimately I want hide the app.php for prettier URLs.
3. Access http://server.com/project/ from machines other than the one I'm developing on (which is running apache, but is a different machine than the production server this will eventually land on). If I'm reading correctly, this may be a security feature of the app_dev.php front controller and this problem will go away once app.php front controller is working properly.
These three points seem likely to be related.

And last but not least
4. Be able to develop using PHPStorm and preview on the web server at the same time. This may or may not be related to the 3 above points. I think this may have something to do with permissions on the filesystem. Apache has a special user, www-data, which reads and writes data to render the web pages, however I'm developing with my user account. To get to the point where I could see the app_dev.php front controller, I had to do the following:
Code: Select all
$ chown -R www-data:www-data app/cache app/logs
$ chmod -R 775 app/cache app/logs


This is not ideal. I develop multiple sites, several hosted on the same server and some hosted on others. Changing ownership and/or permissions is extra work and potentially introduces security concerns as well as making it harder for me to access parts of my project via PHPStorm.

I've tried adding both my user account to the www-data group and adding www-data to my user's group. I've tried using the trick recommended in the book (which was really interesting to read and I hoped it would've worked--I would've learned a new trick), but it did not seem to change anything at all until I used the chown/chmod above.
Code: Select all
$ sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX app/cache app/logs
$ sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs


I'm not a novice at linux nor PHP, and I swear I'm trying to find my own answers as much as possible, but a little guidance would be fantastic. One of my reasons for picking Symfony as the framework I'd like to learn is because I've heard that it has the best community support available for PHP frameworks.

Thanks again for any help! I'll post updates if I figure anything else out.

Code: Select all
<VirtualHost *:80>
   ServerName server.com/project
   ServerAdmin webmaster@localhost

   DocumentRoot /home/user/project/web
   <Directory /home/user/project/web/>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all

      DirectoryIndex app_dev.php app.php index.php index.html
      <IfModule mod_rewrite.c>
         AllowOverride None         

         RewriteEngine On
         RewriteCond %{REQUEST_FILENAME} !-f
         RewriteRule ^(.*)$ app_dev.php [QSA,L]
      </IfModule>
   </Directory>

   ErrorLog ${APACHE_LOG_DIR}/error-project.log

   # Possible values include: debug, info, notice, warn, error, crit,
   # alert, emerg.
   LogLevel info

   CustomLog ${APACHE_LOG_DIR}/access-project.log combined

</VirtualHost>
stevec
Junior Member
 
Posts: 3
Joined: Mon May 13, 2013 11:49 pm

Re: Apache vhost for Symfony 2.2.1 on Ubuntu 13.04

by regisflo » Tue Jun 11, 2013 7:55 pm

You should use mod_ruid2 for your development. This mod allow to wear user suits.
Code: Select all
sudo apt-get install libapache2-mod_ruid2


For example
Code: Select all
<VirtualHost *:80>
   # Config Here
    <IfModule mod_ruid2.c>
        RUidGid user group
    </IfModule>
    # Other config here
</VirtualHost>

Where user and group is your username and groupname.

This is very confortable to develop quietly without juggle with user permissions.

I use successfully this method on my server to restrict web app permissions.
regisflo
Junior Member
 
Posts: 1
Joined: Tue Jun 11, 2013 7:45 pm

Re: Apache vhost for Symfony 2.2.1 on Ubuntu 13.04

by stevec » Thu Jun 13, 2013 12:24 am

That little trick just helped my web development so much. Thank you!
stevec
Junior Member
 
Posts: 3
Joined: Mon May 13, 2013 11:49 pm