PHP virtualhost's settings issue - apache

I have a functional virtualhost set us
Listen 1234
<VirtualHost *:1234>
DocumentRoot "/Users/localuser/sites/testphp"
ServerName localhost
ErrorLog "/private/var/log/apache2/testphp-error_log"
CustomLog "/private/var/log/apache2/testphp-access_log" common
</VirtualHost>
<Directory "/Users/localuser/sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
PHP page is accessible by url localhost:1234.
Now I need to add another project, but I want to put it to different folder instead sites.
So I add another virtualhost settings as
Listen 1235
<VirtualHost *:1235>
DocumentRoot "/Users/localuser/Desktop/PE_RS/Projekty/php/hello-slim/public"
ServerName localhost
ErrorLog "/private/var/log/apache2/hello-slim-error_log"
CustomLog "/private/var/log/apache2/hello-slim-access_log" common
</VirtualHost>
<Directory "/Users/localuser/Desktop/PE_RS/Projekty/php/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
But in this case I'm getting for localhost:1235
Forbidden
You don't have permission to access / on this server.
I don't know if it does matter, but I have set in httpd-userdir.conf UserDir sites.
Thank you for any help.

In general, settings are all right. The issue is related to the folder/file permissions. I think that it was wrong to have PHP projects folder on Desktop. After move it into ~ and fix permissions by command sudo chmod -R 777 php (what is essential of this solution) all works!
Inspiration came from
askubuntu.com...

Related

500 Internal Server Error when trying to enable use of .htaccess in Apache on Ubuntu

I am trying to get my .htaccess working on my Ubuntu-apache2-webserver.
For that I opened /etc/apache2/apache2.conf,
I removed the comment sign (#) before AccessFileName .htaccess
and replaced AllowOverride None by AllowOverride All in
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
I activated mod_rewrite via a2enmod rewrite and restarted the server.
But each time I am performing those changes and open an html-file placed inside of /var/www/html, I get a 500 Internal Server Error for Virtual Host 80.
The same thing happened to me when placing
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
before </VirtualHost> into the 000-default.conf-file instead of the /etc/apache2/apache2.conf.
Can anyone tell me what I am missing?
You're slightly off in your syntax for allowOverride. The Directory tag needs to be inside the VirtualHost tag. Like so:
<VirtualHost *:80>
DocumentRoot /var/www/html
ErrorLog /var/log/apache2/error.log
Options Includes
<Directory "/var/www/html">
AllowOverride All
</Directory>
</VirtualHost>
Also, make sure Apache has permissions to read and write to the directory /var/www/html

Virtual host not displaying correct files

Centos 7.1 and apache 2.4 - We have installed a new drive in our server and want to move all of our sites to that drive (mounted as /data) and sites are located in /data/vhosts
When trying to access the site we are presented with the apache welcome screen. I can confirm that the vhost is loaded as trying changing the permissions of the dir above results in a forbidden access. There is also an index.php file located in /data/vhosts/test.mydomain.com/public_html
# IP has been changed for example:
<VirtualHost 91.91.91.91:80>
DocumentRoot "/data/vhosts/test.mydomain.com/public_html"
ServerName test.mydomain.com
<Directory /data/vhosts/test.mydomain.com>
Options All
AllowOverride All
order allow,deny
allow from all
</Directory>
</VirtualHost>
UPDATE 1:
I have deleted the welcome.conf file in /etc/httpd/conf.d/ and I am not given a forbidden 403. It is important to note that this is a new drive and no permissions has been set on /data (or sub folders) for apache. I am not entirely sure if that makes a difference?
I have also made some slight alternations to the vhost conf file but no difference:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/data/vhosts/test.mydomain.com/public_html"
ServerName test.mydomain.com
<Directory "/data/vhosts/test.mydomain.com">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory /data/vhosts/test.mydomain.com/public_html>
Options Indexes FollowSymLinks Includes ExecCGI
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Adding a directory to Apache Server

I have a Windows XP system running XAMPP/Apache. I already have files on an external hard drive that I would like to serve up without moving them to the same drive as the Apache installation.
Here is what I've tried so far:
In the main HTTPD.conf file:
Alias /client_files D:/clients/files
<Directory D:/clients/files>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
But the only result I got was :
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.6
I also tried adding to the HTTPD-VHOSTS.conf file:
ServerName client_files
ServerAlias client_files
DocumentRoot "D:/clients/files"
And also:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "D:/clients/files"
ServerName client_files
ServerAlias client_files
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
But neither of these worked either. How in the world can I add another directory to an Apache installation and have it accesible via something like "localhost/client_files"?
Any suggestions?
UPDATE: [SOLVED]
As per #Pedro Nunes's answer below, I now have my httpd.conf file with this section at the end of the file and which includes the line "Require all granted" which Pedro answered with and which now solves the issue:
Alias /client_files D:/clients/files
<Directory D:/clients/files>
Require all granted
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
Have you tried Require all granted inside the directory section?
This will grant access to all requests.
This guide explains exactly how I have it setup on my windows xampp machine. http://www.delanomaloney.com/2013/07/10/how-to-set-up-virtual-hosts-using-xampp/
remember to give an absolute documentroot path as well as adding the 127.0.0.1 servername line to hosts in C:/Windows/System32/drivers/etc/hosts

Two sites with Apache virtual hosts

I'm working on 2 different sites. I have local copies of them checked out from SVN at my home folder, and symbolic links in /var/www pointing to them.
I've set up virtual hosts in httpd.conf like this:
<VirtualHost *:80>
DocumentRoot /var/www/siteA
ServerName 192.168.0.10/siteA
<Directory "/var/www/siteA">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/siteB
ServerName 192.168.0.10/siteB
<Directory "/var/www/siteB">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I would like to be able to access the sites with 192.168.0.10/siteA and /siteB, but when typing the address in browser, it throws a 404 and apache error log says: "File does not exist: /var/www/siteA/siteA".
What am I doing wrong and where does the second "/siteA" come from?
You've got too much configuration in there. /SiteA and /SiteB should be paths relative to your site root, you can't have different sites on the same host header, which in this case is "192.168.0.10". If you want to bind that address to the configuration, something along the lines of the following should work.
<VirtualHost 192.168.0.10:80>
DocumentRoot /var/www
ServerName 192.168.0.10
<Directory "/var/www">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
If you now browse to /SiteA, /SiteB you should see the contents of your directory as long as your symlinks are correct. You also need to ensure you have the "NameVirtualHost" directive set correctly in your httpd.conf.

Moveable type images not displayed

I installed Moveable type on a ubuntu box.
The admin section works great.
However the front page does not. The images and CSS are not displayed.
This is coming from the apache error log:
Permission denied: exec of '/var/www/mt/example/styles.css' failed
Premature end of script headers: styles.css
I think it's related to my apache config. Since i call the admin section using the localhost, but i use the example.com for the front page, which is the part that doesnt work.
This is my apache config:
NameVirtualHost *
<VirtualHost *>
ServerAdmin chris#example.com
ServerName mt.example.net
DocumentRoot /var/www/mt
Alias /mt-static /var/www/mt/mt-static
<Directory /var/www/mt/mt-static>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias / /var/www/mt/
<Directory /var/www/mt>
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *>
ServerAdmin chris#example.com
ServerName example.com
ServerAlias example.com www. example.com
DocumentRoot /var/www/example
Alias /mt-static /var/www/mt/mt-static
<Directory /var/www/mt/mt-static>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Redirect /mt.cgi http://mt.example.net/mt.cgi
</VirtualHost>
it because the directory where the css file is located (var/www/mt/example/) is a sub-directory of one which is declared to be a script in (/var/www/mt) with Options +ExecCGI
Directories inherit the options of their parents
It sounds like Apache has tried to run the .css file as an executable. The only thing which I can suggest is that you might have a css file which has an executable permission, for some reason, so Apache tries to execute it. Try
chmod a-x
on the CSS file and see if it makes a difference.
Sometimes files copied from Windows have executable set when they shouldn't.