Repoint global DocumentRoot, still run PHP - php

I have a server which is serving up a web page for a project.
The project is stored in a user directory on the server. (/home/user/theproject/webstuff).
Originally, I was using the userdir module to make this accessible via http://theserver/user and a symbolic link from /home/user/public_html to /home/user/theproject/webstuff to indicate the location of the files.
But, ultimately, it would be better to serve the files from http://theserver without having to indicate the user (since there really is only one user).
And then I had a truly brilliant idea.
Instead, I would rewrite my /etc/apache2/sites-enabled/000-default.conf file to read:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/user/theproject/webstuff
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now everything is lovely and good... except that PHP doesn't run any more.
Instead, the following error is raised:
AH01630: client denied by server configuration: /home/user/theproject/webstuff/script.php
To the client, this appears as a 403 Forbidden error.
So this is something of a dual question:
Is there a better way to achieve my goal?
How can I enable PHP in this situation?

You can find a well written description of this error with several possible solutions here:
http://wiki.apache.org/httpd/ClientDeniedByServerConfiguration

As it turns out, I had to edit /etc/apache2/apache2.conf.
On Line 164 there is a block which I had to modify as follows:
#<Directory /var/www>
<Directory /home/user/theproject/webstuff>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

Related

Development mode on Symfony2 virtual hosts

I was boring about my large url http://localhost:8888/site/web/app_dev.php, so, I created apache virtual hosts. When I write http://site.dev in my browser, everything is working, my website appears.
The problem is that my Symfony2 website seems to be in dev / prod mode whereas I point to app_dev.php (in the .htaccess).
I have the debug bottom toolbar (it shows me "dev environment"), I can do dumps, but when I modify a file (JS, Twig, and so on), I have to execute, each time, php app/console assetic:dump (I hadn't before).
My virtual host :
<VirtualHost *:80>
ServerName site.dev
ServerAlias www.site.dev
DocumentRoot /Applications/MAMP/htdocs/bo/web
<Directory /Applications/MAMP/htdocs/bo/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
</VirtualHost>
EDIT : I noticed that the website is so much faster like that (site.dev) than before (with the localhost URL). Don't know why, and still don't know how to fix the php app/console assetic:dump problem...
You need add this line DirectoryIndex app.php
<VirtualHost *:80>
ServerName site.dev
ServerAlias www.site.dev
DocumentRoot /Applications/MAMP/htdocs/bo/web
DirectoryIndex app.php
<Directory /Applications/MAMP/htdocs/bo/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
</VirtualHost>
Don't you have any other problems but worrying about the lengths of the URL? :)
But seriously, try starting the internal PHP/Symfony server with the following command:
$ app/console server:start
The development version of your app will be at http://localhost:8000. Nice and short.
Based on your comment, it turns out that the actual problem you have is hardcoding URLs in your JS. The solution for that is https://github.com/FriendsOfSymfony/FOSJsRoutingBundle.
Basically, that bundle lets you expose routes to your JS so that you avoid hardcoding URLs there.

XAMPP access forbidden issues

Having issues with XAMPP and access forbidden problems.
Started using laravel, complete noob to anything MVC but thought I'd give it a go.
Started having issues with page routing, index page works fine, yet non of my routes work, all come up with a 404 error.
Have a little search around the internet, find out it could be due to my xampp/Apache config.
Had a play with the
Allow from all
and
Require all granted
options, but no dice.
This is my vhosts entry:
<VirtualHost *:80>
DocumentRoot "C:\Users\xxx\Desktop\Projects\xxx\Website-3.0\Website\public"
ServerName gw3.dev
<Directory "C:\Users\xxx\Desktop\Projects\xxx\Website-3.0\Website\public">
Allow from all
Require all granted
Options Indexes
</Directory>
</VirtualHost>
and this is what I edited in the httpd.conf file.
<Directory />
Require all granted
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
Made sure that the root directory is not read only.
Yet all I get are 403 - forbidden access errors.
Running Windows 10, fyi.
Not really sure where I'm going wrong here. Is there something I'm missing?
This section
<Directory />
Require all granted
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
Provides the basic security for the disk that Apache is installed on. Basic practice is deny access to everything and then allow access to only those directories that Apache should have access to. Also you are using Pache 2.2. and 2.4 syntax together, bad.
So change that back to :-
<Directory />
AllowOverride none
Require all denied
</Directory>
In the definition of the virtual host you are using both Apache 2.2 and 2.4 syntax. Thats not a good idea it can cause Apache to get confused. Also you are using the DOS back slash and that should be the unix forward slash.
So try this
<VirtualHost *:80>
DocumentRoot "C:/Users/xxx/Desktop/Projects/xxx/Website-3.0/Website/public"
ServerName gw3.dev
<Directory "C:/Users/xxx/Desktop/Projects/xxx/Website-3.0/Website/public">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
If you dont actually intend to allow anybody in the universe to access this site then you can use
Require local
Or if you want to access the site from another device in your local network you could try
Require ip 192.168.1
Note use of only 3 of the 4 quartiles of the IPV4 ip address. This allows access from any ip in that subnet.
Also make sure that you have added gw3.dev to your HOSTS file for both IPV4 and IPV6 addresses
127.0.0.1 gw3.dev
::1 gw3.dev
Retart Apache and try that.
You need
AllowOverride All
too in vhost
also dont forget to reboot the server

change the VirtualHost file with php

I have installed apache on Debian server, and setup some example sites but I would like to make a billing system and automatically update the Virtualhost details like ServerAdmin, ServerName, ServerAlias when order is completed.
My question is: Is it possible to update them with PHP?
Example site in the sites-available directory:
<VirtualHost *:80>
ServerAdmin info#example.org
ServerName example.org
ServerAlias www.example.org
DocumentRoot /srv/www/example.org/public_html/
ErrorLog /srv/www/example.org/logs/error.log
CustomLog /srv/www/example.org/logs/access.log combined
</VirtualHost>
With the proper write permissions, you can certainly do it. It does seem like you will want some seriously paranoid validation and testing before you restart apache after a write a new one because a malformed directive in there is a quick way to 500.
Edit: I'm not sure I would recommend giving your script the 'proper' write permissions in the first place.

Django/mod_wsgi and PHP as Virtual Hosts on same Apache Server using MAMP

UPDATE: My original question is below, but the code I posted with the question has been edited to the final working solution.
I am trying to run multiple sites on my MAMP development server. Some of the sites are wordpress sites that live in the htdocs in MAMP and some of the sites are django apps that live in a folder titled djangoprojects.
I have been trying to implement the solutions from these stack questions:
multiple django sites with apache & mod_wsgi
How do I run Django and PHP together on one Apache server?
but I have not been successful. I was able to run the django site on apache with the code you see in the first VirtualHost brackets (from the daemon process line onward) but then none of the php sites could be visited.
Help is greatly appreciated. I am new with this and I can't work out the errors.
Here is the code from my httpd.conf:
UPDATE: The code below works. Both the Django App and the PHP applications exist on the localhost server. The PHP related VirtualHost stuff was copied from further up in the MAMP httpd.conf file.
<VirtualHost *:80>
ServerName localhost:80
UseCanonicalName Off
DocumentRoot "/Applications/MAMP/htdocs"
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
<Directory "/Applications/MAMP/htdocs">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess site1 display-name=%{GROUP}
WSGIProcessGroup site1
Alias /media/ /Users/sequoia/djangoprojects/dynamics/media/
<Directory /Users/sequoia/djangoprojects/dynamics/media>
Options ExecCGI
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /dynamics /Users/sequoia/djangoprojects/dynamics/apache/django.wsgi
<Directory /Users/sequoia/djangoprojects/dynamics/apache>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
A couple of problems to start with:
ServerName is mean to specify the host name not a URL path.
You should never set DocumentRoot to be where your Django site source code is.

CakePHP rookie question, The requested URL /pages/andy was not found on this server

I am installing CakePHP for the first time, I am running LAMP on Ubuntu 10.04LTS. Not only am I a CakePHP rookie, I am a Linux rookie as well. I found installation instructions online and I thought i had everything setup correctly. When i go to localhost i get the default CakePHP page and everything is green.
The problem is when i created a generic page called andy.ctp in the /var/www/app/views/pages folder, when i try to go to localhost/pages/andy I get a 404 NOT FOUND page that says "The requested URL /pages/andy was not found on this server."
I am sure i missed something on the initial setup, i just cant find out what. I have Googled the error and have yet to find anything to get me along. Below is my default file. Please let me know if there is anything else you need to see. Thanks for the help in advance!
is there something in the .htaccess file that might need to be changed?
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/app/webroot
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
Let's try a few things first:
Do you have the whole CakePHP package installed under one same directory. I say so because I saw you have /var/www/app, and the cake directory must also be within /var/www/. Even when you have these directories allright, I recommend that you set the whole CakePHP package into another subdirectory, like /var/www/your_project/app. This will enable you to add more projects easily as time go. Also, you might want to set the Document Root to a home-level directory (i.e. /home/your_name/www/your_project so that you can handle file permissions more easy.
Do you have mod_rewrite enabled? It is required by Cake. Do a Google search; there are plenty of tutorials.
Let me know if any of these work.
Followup:
Hello again.
If you are seeing the default CakePHP start page with all green notices (see this old screenshot), then it means that you dont have anything wrong with mod_rewrite or htaccess. However, I reproduced the steps you took along with your virtualhost configuration file and found two issues:
1) You are pointing the DocumentRoot to /var/www/app/webroot when it should point to the top-level directory, in this case /var/www/ (i.e. the directory where CakePHP's topmost index.php is). Also, be sure to have this directive: DirectoryIndex index.php
2) You are not closing the <VirtualHost> tag; though this can actually be a wrong copy+paste here in S.O.
Overall, try to 'debug' your VirtualHost file by starting with just a few lines so that you have to worry less about misconfigurations. I use these few for any project in my local machine, and I've had multiple CakePHP Projects all running under Apache for Ubuntu.
<VirtualHost dummysite.com:80>
ServerName dummysite.com
ServerAdmin myemail#gmail.com
DocumentRoot "/home/yamir/Programming/Projects/dummysite"
DirectoryIndex index.php
LogLevel warn
ErrorLog "/home/yamir/Programming/Projects/dummysite/logs/error.log"
CustomLog "/home/yamir/Programming/Projects/dummysite/logs/access.log" combined
</VirtualHost>
Have you definitely turned on mod_rewrite?

Categories