php file operations permission denied - php

I have two Virtual Hosts on Redhat Enterprise server, one of which functions as desired. The second I a have problems when using PHP to do any kind of file operations. As far as I can tell both virtual hosts have been set up in the same. I have checked that file permissions have been set correctly on the folders/files in question. I have gone as far to set permissions to 777.
Can anyone suggest where I might have gone wrong? The virtual hosts are set up as follows:
<VirtualHost *:80>
ServerName intranet
ServerAlias intranet *.intranet
DocumentRoot /home/burnside/public_html
<Directory "/home/burnside/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName tracker
ServerAlias tracker *.tracker
DocumentRoot /home/tracker/public_html
<Directory "/home/tracker/public_html">
Allow from all
Options +Indexes
</Directory>
</VirtualHost>

Related

apache2.conf and httpd.conf

After reading ubuntu AMP community and Apache 2.4 configuration.
I was wondering if there is a way to imitate the same behavior of the http docs used in XAMPP or bitnami stacks but using the default LAMP. Which uses apache 2.4
In XAMP you would assign an extra number to your httpd-vhost.conf like this:
Listen *:9000
<virtualhost *:9000>
ServerName localhost
DocumentRoot "~/xamp/apache2/htdocs/html/app-name/"
</virtualhost>
<Directory "~/xamp/apache2/htdocs/html/app-name/">
Options Indexes FollowSymLinks
AllowOverride all
</Directory>
Then Edit your httpd.conf files like:
//....Some code..... */
<Directory>
AllowOverride all
<Directory />
//...Some code...
and uncomment this line:
//....Some code..... */
# Virtual hosts
include conf/extra/httpd-vhosts.conf
//...Some code...
My question is:
Is there is a way to configure Apache 2.4 just by dropping all my vhost's in one single file, without having to go through the process of configuring etc/apache2/sites-available and then adding names to etc/hosts?
Then completing the process by including some things like above just like Bitnami or Xamp stacks will do so your localhost will be able to serve not only static html files but an entire application's folder.
What works is the following in (for example) your 000-default.conf:
<VirtualHost *:80>
ServerName site1.vm
ServerAdmin webmaster#localhost
DocumentRoot /var/www/site1/web/
ErrorLog ${APACHE_LOG_DIR}/site1_error.log
CustomLog ${APACHE_LOG_DIR}/site1_access.log combined
<Directory /var/www/site1/web/>
Options All
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName site2.vm
ServerAdmin webmaster#localhost
DocumentRoot /var/www/site2/web/
ErrorLog ${APACHE_LOG_DIR}/site2_error.log
CustomLog ${APACHE_LOG_DIR}/site2_access.log combined
<Directory /var/www/site2/web/>
Options All
AllowOverride All
</Directory>
</VirtualHost>
This way all you have to do is add the site to the conf file, add the host to your hosts file, and reload apache2 service. Hope that is what you were looking for.

WAMP server - localhost displays directory listing only

I am a complete novice when it comes to WAMP, apache etc.
I'm trying to get a site to run locally but so far not having any luck. I've got as far as installing WAMP and it seems to be going online fine, i.e. the green "W" icon is green. Features like phpmyadmin seems to be working. When I click "localhost" it opens the browsers and navigates to localhost as you'd expect, however, all I see is the directory listing.
So, I have virutal hosts set up as follows:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/bts/BiteTheSun"
ServerName bts
ServerAlias bts
<Directory "c:/wamp/www/bts/BiteTheSun">
Require all granted
</Directory>
</VirtualHost>
and in my hosts file I have:
127.0.0.1 localhost
127.0.0.1 bts
::1 bts
::1 localhost
I've added some images just to be clear as to the issue - the top image shows what I think I should be seeing and the bottom shows what I actually see:
localhost screenshot issue
I've tried everything I can think of to no avail. It might also help to mention that in the log file [apache_error.log] I seem to get errors relating to permissions:
"AH01630: client denied by server configuration: C:/Apache24, referer: http://localhost/"
However, I've gone through the permissions set in the config files using examples from several sources and nothing seems amiss.
Has anyone any idea what is going on here? I have searched online high and low on this and on one else seems to have exactly this issue which makes me think it is me doing something very silly - I just need someone to point out how exactly! :)
Richard
Is there an index file in your www folder?
Typically, you want to place your individual projects within the www folder and point your virtual hosts to the www/your-project/ folder which should contain an index.php file (unless you have a custom set up where you are going to point your virtual host directly to a specific file).
Your Virtual Host definitions are incomplete.
Each VH should have its own <Directory>...</Directory> definitions so you can apply the access and other config information to that directory.
The parts you are missing are AllowOverride and Options.
The other thing to remember is that when you create a Virtual Host environment the host defined in the httpd.conf file is basically ignored and the VH's take presidence. This is why you need to redefine the localhost in the VH file.
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
<Directory "c:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/bts/BiteTheSun"
ServerName bts
<Directory "c:/wamp/www/bts/BiteTheSun">
AllowOverride All
Options Indexes FollowSymLinks
Require local
</Directory>
</VirtualHost>
Your AH01630: client denied by server configuration: C:/Apache24 error is likely because the default httpd-vhost.conf file comes with 2 example definitions as supplied by Apache. These should be completely deleted from the file. So if you left these in the httpd-vhost.conf file. Delete them completely from the file.
Example of the defs to remove. Note they use the c:/Apache24 directory which does not, and should not exist in a WAMPServer environmant!
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

Apache virtual host without domain name

I have a VPS with apache2 installed and I would like to access some PHP projects without a domain name just with the IP address. For example:
http://162.243.93.216/projecta/index.php
http://162.243.93.216/projectb/index.php
I have other projects with domain like example.com, in my directory /var/www/
/html/
info.php
/projecta/
/projectb/
/example/
When I go to
http://162.243.93.216/info.php then /var/www/html/info.php is opened.
My file 000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
" http://162.243.93.216/info.php then /var/www/html/info.php is opened "
I am assuming this already works (If not, uncomment the ServerAlias line shown in the conf below)
You now want to map
http://162.243.93.216/projecta/ to /var/www/projecta
http://162.243.93.216/projectb/ to /var/www/projectb
For this you need to use the Apache Alias directive.
Update your 000-default.conf file to:
<VirtualHost *:80>
# ServerAlias 162.243.93.216
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
Alias /projecta /var/www/projecta
Alias /projectb /var/www/projectb
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Create a new virtual host file, and setup like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerAlias 192.168.1.1
DocumentRoot /somewhere/public_html
<Directory /somewhere/public_html/>
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride Authconfig FileInfo
Require all granted
</Directory>
</VirtualHost>
add the serveralias and it will recognize the IP address as well ...
if you want to add more IP addresses (like local network second interface), you can add more serveralias lines ...
Step Six — Set Up Local Hosts File (Optional)
If you have been using example domains instead of actual domains to test this procedure, you can still test the functionality of your virtual hosts by temporarily modifying the hosts file on your "LOCAL COMPUTER". This will intercept any requests for the domains that you configured and point them to your VPS server, just as the DNS system would do if you were using registered domains. This will only work from "YOUR COMPUTER", though, and is simply useful for testing purposes.
Note: Make sure that you are operating on your local computer for these steps and not your VPS server. You will need access to the administrative credentials for that computer.
If you are on a Mac or Linux computer, edit your local hosts file with administrative privileges by typing:
sudo vi /etc/hosts
If you are on a Windows machine, you can find instructions on altering your hosts file here.
The details that you need to add are the public IP address of your VPS followed by the domain that you want to use to reach that VPS:
127.0.0.1 localhost
127.0.1.1 guest-desktop
server_ip_address example.com
server_ip_address example2.com
reference:https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-7?utm_source=Customerio&utm_medium=Email_Internal&utm_campaign=Email_CentOSDistroNginxWelcome&mkt_tok=eyJpIjoiTnpWbU5tUTJPV1F5TVRBMyIsInQiOiJhd0JCQVI0NDd0ZWprUDFaaDlhbENcL0lyTjdSbnhwMEpkTE1QcXJTcHl1ZXFhNURKVmVBZHFKMk92RW1kSFwvMHowOW0zcExhaUdyOU42U2lLbk1Cd2FRYzB4XC9lbkhlWnd1ekZOcW1sZVhRYlwvT0xrTUpmQ2dEK2dNVUw4alFrc00ifQ%3D%3D

Configure multiple Kohana applications on one server

Currently I am using wamp on a windows machine and have kohana up and running for one site. I would like to deploy another site which is completely separate and uses a different copy of kohana. To do so I added file structure and deployed kohana as follows
+wamp
++www
+++site1
++++kohana
+++site2
++++kohana
Currently my apache httpd.conf listener is as follows
Listen 0.0.0.0:80
And my hosts file in the windows directory is set up as
127.0.0.1 localhost
127.0.0.1 site1.localhost
127.0.0.1 site2.localhost
Currently when I go to localhost it will go to site1.localhost. Or if i go to site1.localhost it will go to site 1. If I go to site2.localhost the application will redirect to site1.localhost
I am very new to LAMP so this may be a very basic issue, for that I apologize.
Creating a virtual host is the answer
<VirtualHost site1.localhost>
ServerAdmin webmaster#site1
ServerName site1
DocumentRoot "C:/wamp/www/site1"
<Directory "C:/wamp/www/site1">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/site1-error.log"
CustomLog "logs/site1-access.log" common
</VirtualHost>
<VirtualHost site2.localhost>
ServerAdmin webmaster#site2
ServerName site2
DocumentRoot "C:/wamp/www/site2"
<Directory "C:/wamp/www/site2">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/site2-error.log"
CustomLog "logs/site2-access.log" common
</VirtualHost>

Setup VirtualHost for Zend Application on Wamp server

I'm following this tutorial to learn how to start a project using ZendFramework
http://framework.zend.com/manual/1.12/en/learning.quickstart.create-project.html
When I get to setup a virtual host I get stuck. If I do exactly as the tutorial says, it shows me an error (in all my project, zend or not), says the file wasn't found.
Then I found this tutorial on StackOverflow very handy
Can't run zend framework MVC application on WAMP
Following what the guy on the bottom of the page says takes me to the same error when I try to access my app as zendProject.local/
This is what I got
on hosts (Windows/System32/drivers/etc/hosts) file
127.0.0.1 blog.local
on httpd-vhosts.conf file
<VirtualHost 127.0.0.1>
ServerName blog.local
DocumentRoot /blog/public
SetEnv APPLICATION_ENV "development"
<Directory /blog/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Can you tell me what I am doing wrong? The browser still says Not Found The requested URL /public was not found on this server when I go to http://blog.local/
I'm running WAMP on Windows. And this is the absolute path to the 'blog' project C:\wamp\www\blog
#Edit RiggsFolly
this is what I got now in the httpd-vhosts.conf file
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www">
AllowOverride All
# make sure this is only allowed to be accessed by the local machine
# then if/when you open one of your other sites up to the internet and somebody uses your IP
# they will get directed here as its the first VH def and then receive a 403 not allowed to access
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/websites/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/websites/blog/public">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
And I created a new directory at C:/ called 'websites' as you suggested
You need to be a little more specific with your folder locations. I guess this tutorial was written for Unix and you are using windows.
For Apache 2.2.x use this syntax:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/wamp/www/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/wamp/www/blog/public">
DirectoryIndex index.php
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
You would be better avoiding the Allow from all and using Allow from localhost 127.0.0.1 ::1 until you actually want to allow the universe to see your sites.
For Apache 2.4.x use this syntax:
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/wamp/www/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/wamp/www/blog/public">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
Note NameVirtualHost *:80 no longer required for Apache 2.4.x
Again you would be better avoiding the Require all granted and using Require local until you actually want to allow the universe to see your sites.
EDITED After comment from Questioner:
Right, that's the Apache default. If you enter a url it cannot find a Virtual Host definition for it will default to the first Virtual Host definition you gave it, the blog in your case.
Ok, so now you need to create a Virtual Host for each of your other projects, and MOST IMPORTANTLY the first one needs to be localhost and only be allowed to be accessed from the local PC for a bit of extra security.
Now personally I would take this opportunity to move my actual sites to a totally separate folder structure outside the \wamp\ folder structure so there is no confusion with rights given to the \wamp\www folder and my other sites.
So for example, create a folder c:\websites\www and in that folder create a folder for each of your projects eg
c:\websites\www\blog
c:\websites\www\project2
Then point your virtual hosts to the relevant folder containing the site code ( this can be on another disk if you like ). This allows you to specify the Apache security ( who is allowed in to this site) specifically for each of your VHOSTS. So when you want a client or friend to be able to play with one site, you just change the security on that one site while you let them play.
Like this:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www">
AllowOverride All
# make sure this is only allowed to be accessed by the local machine
# then if/when you open one of your other sites up to the internet and somebody uses your IP
# they will get directed here as its the first VH def and then receive a 403 not allowed to access
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/websites/www/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/websites/www/blog/public">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName project2.dev
DocumentRoot "C:/websites/www/project2"
Options Indexes FollowSymLinks
<Directory "C:/websites/www/project2">
DirectoryIndex index.php
AllowOverride All
Require local
# this site also available to other PC's on my internal network
Require ip 192.168.0
</Directory>
</VirtualHost>
Remember, for each new Virtual Host site you create you also need to add that ServerName (project2.dev) to the hosts file.
hosts file:
127.0.0.1 blog.local
127.0.0.1 project2.dev
I hope this helps.

Categories