Apache sites-available default and other - php

i have a domain name called for example "mydomain.com"
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options -Indexes FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options -Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
....
</VirtualHost>
When i write the following address in url:
www.mydomain.com/mysubdomain/myfolder
go to a web page working fine.
mysubdomain sites-available is the following, called mysubdomain
<VirtualHost *:80>
DocumentRoot /var/www/mysubdomain
ServerName www.mysubdomain.com
ServerAlias mysubdomain.com
ErrorLog ${APACHE_LOG_DIR}/error_mysubdomain.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access_mysubdomain.log combined
<Directory /var/www/mysubdomain>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Everything works fine, when i type www.mydomain.com/mysubdomain/myfolder goes fine to
www.mydomain.com/mysubdomain/myfolder/login.php
but when i write
http://www.mysubdomain.com/myfolder/login.php
don´t work as expected, because when i include in login.php a ref, like ../../myfolder can´t go to root folder as i expected, how can i fix it ?
in www.mydomain.com/mysubdomain/myfolder/login.php the ref like ../../myfolder go fine to /var/www/
i want that the url showing to user could be http://www.mysubdomain.com/myfolder/login.php

Relative URLs are relative to the URL, not to the file system on the web server (which is invisible to the client).
You can't navigate up the directory tree to a file which doesn't appear under the web root for the virtual host being viewed.

The solution is simple:
change the file mysubdomain that is in sites-available to
DocumentRoot /var/www/mysubdomain
ServerName www.mysubdomain.com
ServerAlias mysubdomain.com
ErrorLog ${APACHE_LOG_DIR}/error_mysubdomain.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access_mysubdomain.log combined
Alias /myfolder /var/www/myfolder
<Directory /var/www/mysubdomain>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

Related

Live Server cannot load other pages with Apache 404 error

I'm using Google VM instances on Google Cloud Platform for running my live server. I'm also using CodeIgniter to build of my server. It can load the default route when entering the page but when going to other routes, it shows Apache 404 error:
Not Found
The requested URL was not found on this server.
Apache/2.4.29 (Ubuntu) Server at 35.186.147.249 Port 80
My Apache config file at /etc/apache2/sites-available:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
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>
</VirtualHost>
I looked up online and most people say it is an Apache problem but I'm not too sure. I'll share any of the files in order to fix this issue.
The line DocumentRoot /var/www/html determinate the base of your files, I reviewed the IP that you put and i can see the next folder and access correctly:
j/
medical-survey/
temp/
Here is the link to understand more about DocumentRoot, so you can define where you require the default folder route for your web files. In case you require to have different links of your web development you can follow this link to configure the virtual hosts. Hope this is what you were looking for.

Apache2 Ubuntu: Virtualhost redirects to localhost

I wanted to set up a virtualhost for my apache2 running on my computer. So when I browse to: "invision.jan.pcsg" I get the page contents/folder structure from "/var/www/html/invision"
This is the virtualhost file "invision.jan.pcsg.conf" I created:
<VirtualHost invision.jan.pcsg:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/invision
ServerName invision.jan.pcsg
ServerAlias hkl.mor.pcsg hkl_at.mor.pcsg
<Directory />
Options FollowSymLinks
AllowOverride FileInfo
</Directory>
<Directory /var/www/html/invision/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
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 ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/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>
When I browse to "invision.jan.pcsg" now, I get redirected to localhost and the "php is working"-page is displayed.
When browsing to "jan.pcsg" the folder contents of "/var/www" is displayed.
Does anyone have an idea why this happens?
I had the same issue but in my case I realized I had forgotten to enable the host .conf file.
sudo a2ensite myvhost.conf
Then I just reloaded apache and everything worked out as expected.
Change your DocumentRoot to directory where your web application ('view' if its MVC) is located.
Usually its : DocumentRoot /home/www-data/ /

Fixing the Permission Denied on My Localhost

I am using Ubunto.When i browse my local host i would like to see my shared directory named myproj. now when i browse it ,this is the message i receive:
Forbidden
You don't have permission to access / on this server.
I tried:
1)giving permission to anyone on this directory and changed the owner to my current user
2) changed my conf settings to below:
Can anyone help me fixing this?
my conf settings is as below:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /etc/apache2/sites-available/myproj
<Directory /myproj>
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /etc/apache2/sites-available/myproj>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
deny None
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
In the conf you should change:
-Indexes
To:
Indexes
Then, after restarting Apache and provided that /etc/apache2/sites-available/myproj does not have an index.html or index.php as default document you can see the contents of that folder displayed in your browser.

Apache2 Virtual host on mint

I'm trying to setup apache virtual host on Mint linux. It kinda works, but some images are not available. For example http://test.local/icons/world.png returns 404 even if image exist. When I check log it says it's looking for image at /usr/share/apache2/icons/world.png even if I setup my DocumentRoot to /var/www/test.local/public_html
This is how I did this. copy /etc/apache2/sites-available/default to test.local and edit like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName test.local
DocumentRoot /var/www/test.local/public_html
<Directory /var/www/test.local/public_html/>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
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 ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then I edit /etc/hosts and include 127.0.0.1 test.local in it. Run a2ensite test.local and restart apache.
What I try to do is map folder in my /var/www/test.local/public_html to http://test.local is there anything I'm missing, or easier way to do this.
Also to mention there is no .htaccess file in root directory of project, or in icons directory.
RESOLVED :)
This is 2nd time I'm answering my own questions here on SO. I actually was researching 2 days and found answer few hours after posting here.
Answer was that this is default Apache alias
Alias /icons/ "/usr/share/apache2/icons/"
Even if I couldn't find it in apache2.conf or in conf.d directory, it looks like it's there in /etc/apache2/mods-available/alias.conf under my Mint distribution (I guess all Debian distro will have similar path). All I needed to do is to comment out this alias and it works.

Setup virtualhost where localhost working on 81 port in apache zendserver

I have installed zendserver and it is running on http://localhost:81/.
Now I have created zend framework 2 project in Apache2/htdocs/zend2 and accessing this through http://localhost:81/zend2/public.
I have to set virtual host for this like zend.local but it is not working.
In httpd.conf file
NameVirtualHost *:81
<VirtualHost *:81>
<Directory "C:\Program Files/Zend/Apache2/htdocs/zend2/public">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
DocumentRoot C:\Program Files/Zend/Apache2/htdocs/zend2/public/
ServerName zend.local
ServerAlias zend.local
</VirtualHost>
and In hosts file
127.0.0.1 zend.local
I have tried all possibilities but nothing works.
I recommend installing ubuntu for development i dont see how your doing it on windows and how it doesn’t annoy you.
try this:
make a copy of the default portion and just add ServerName Zend.local then modify the paths and that should work. You might also want to try restarting the computer that sometimes makes it work (rare occasions)
here is a copy of mine that works but its under ubuntu so it might or might not work for you.
<VirtualHost *:80>
#ZEND-{354B5BC7F803049AB79DE95C47F32B59}
Include "/usr/local/zend/etc/sites.d/zend-default-vhost-80.conf"
#ZEND-{354B5BC7F803049AB79DE95C47F32B59}
ServerAdmin webmaster#localhost
ServerName zendapp.dev
DocumentRoot /var/www/vhosts/zendapp/public
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/vhosts/zendapp/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
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 ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/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>
</VirtualHost>
#ZEND-{90331A19916187EEA0C9B3A8FE0E1632}
Include "/usr/local/zend/etc/sites.d/globals-*.conf"
Include "/usr/local/zend/etc/sites.d/vhost_*.conf"
#ZEND-{90331A19916187EEA0C9B3A8FE0E1632}

Categories