What determines where the browser starts looking for pages? - apache

Sorry if I used the wrong terminology, I'm really new to web development/server stuff outside of Wordpress. I just made a DigitalOcean server and followed a bunch of tutorials to get it setup. I got my LAMP stack setup, but I got to the point in the tutorial where I created a quick php page and added it into /var/www as info.php. But when I go to my server IP/info.php, it couldn't find the page. It was only able to find the page when I moved it inside of /var/www/html which also contained index.html. My question is, what makes the browser/server look inside of html for files instead of /var/www?
My best guess is some apache config file that I'm not familiar with but I really have no idea.

Look in your apache httpd.conf file, most likely in /etc/httpd/conf on your server, for this command:
DocumentRoot "/var/www/html"

Related

DocumentRoot for PrestaShop

In tutorials, I have seen prestashop installed in at least three different DocumentRoot's:
/var/www/html/
/var/www/html/prestashop/
/var/www/html/prestashop/public_html
Is there any logical reason to prefer one location over the others? In my case, there is an Apache server and I will have two different websites (two domains).
/var/www/html is the default directory for apache default config.
Prestashop is meant to be used at the web root, so no matter what you choose you must adapt the apache configuration to match the directory where prestashop actually is.
That being said, you should go for /var/www/yourdomain.com or /opt/website/yourdomain.com (I think it fits more the File Hierarchy Standard).
People sometimes use /var/www/domain.com/public_html so they can put some private content in /var/www/domain.com that can be used by their website but is not facing the web.
Do use nested subdirectories if you don't have a reason for it. Go for the most straightforward way.

How can I run an index.html file on my localhost server?

I purchased a fancy little "visual menu maker" over at envato (Code Canyon) from here: https://codecanyon.net/item/z-menu-maker-drop-down-and-mega-menu/9240528
I was using their sample app where you can test out the tool and I was able to create a nice little menu for my site. But you have to purchase a license to export the code.
I purchased the license and the first "Getting Started" requirement is to "Start your Web Server and open the index.html file. This is where I'm lost. BTW... for reference, you can scroll to the bottom of that documentation page to see all the files that were included in the download.
When I try to open that "index.html" file in my browser, it doesn't load.
I followed some instructions to get my native Mac Apache server running, and everything seems to be working, with my localhost, but I don't know how to open this file through my Apache Web Server.
Any help would be so appreciated!!
I am assuming you have your Apache installed on your Mac under /etc/apache2 folder
If you want to serve your html files and related components, you need to tell apache from where to find your files
So , you need to configure apache so that it can server your files.
first you need to open an terminal from lunch menu then go to the apache2 installation directory
cd /etc/apache2
Then you need to open httpd.conf file and make necessary changes,
sudo nano /etc/apache2/httpd.conf
You will see "DocumentRoot" line/. Change it with your directory where you put your files.
Change also Directory path with yours. (It should be in same config file such as
with
<Document "some_path">
Then you should restart apache server with command
sudo apachectl restart
Now you can try to access your file . you can also check http://localhost to validate
You need to put the files somewhere within the DocumentRoot of your Apache web server, and then you should be able to visit them with http://localhost/ (assuming the index.html file is in the root of the DocumentRoot).
I'm not familiar with the default setting of DocumentRoot on the Mac port of Apache, but you should be able to find that quite easily in the configuration. On Linux that would commonly be found somewhere under /etc/apache2 or /etc/httpd.
There may be further configuration needed if the files expect some sort of server-side module to be activated (e.g. PHP), but it sounds like they are just plain HTML.
Some good answers were given but I think this particular app needed a few extra steps in order to work properly.
The developer got back to me and told me I'd need to install a MAMP solution in order to run the app.
So I installed that and then took the unzipped folder and all its contents in this folder /MAMP/htdocs/
Then when I visit http://localhost:8888/ZMenuMaker/ the app runs without a hitch!

htaccess - simulating local page as web page

Is there a way to rewrite a URL in a local project to look like web page?
For example I have project with url
localhost/site
I'm tryin' to rewirite this to:
www.site.com
or
site.com
That project has subpages, and it would be good if it worked like
site.com/subpage.php
I'm trying for an hour but I'm really htaccess noob.
I work with VertrigoServ and mod_rewrite works fine with some examples which I tried in other projects.
The issue is not with rewrite. To make a local page appear to have a more conventional domain you need to tell your browser that the conventional domain is found on your local webserver.
The simplest way to do this is by editing the hosts file on your OS. On *nix based devices it's usually /etc/hosts, On windows it's usually C:\Windows\System32\drivers\etc\hosts. You will need elevated privileges to edit the file.
Add a line to the end of the file that maps the domain name to your local ip address like this:
127.0.0.1 www.site.com
Close an reopen your browser and visit www.site.com, you should see it is loading the page from your local webserver.
Chances are, you are still seeing the same page as if you view localhost site. To make it load your code you need to change the DocumentRoot in httpd.conf for your apache install to match the directory where your code is.
A preferable solution may be to use Name Based Virtual Hosting, this allows multiple web sites to share the same IP address. Searching 'apache VirtualHost examples' should give you plenty of resources for this. Make sure that NameVirtualHost *:80 is also enabled in order for this to work.

Removing the .php file extension from files on an Apache server

My question is, I am sure, relatively straightforward and there are several questions about this exact topic already on stackoverflow. I have tried all of the solutions currently posted and none of them seem to work, this could be due to changes in the apache server over time and now it handles parsing a .htaccess file or it could be a configuration setting that isn't mentioned in the posts. Whichever the case an updated answer would be extremely helpful.
There are 2 main goals I have
1) Configure my apache server such that a link to the page [www.example.com/about] makes the web server understand that the page [www.example.com/about.php] should be rendered and shown to the user.
2) Configure my apache server such that a link to the page [www.example.com/about.php] redirects VISIBLY to [www.example.com/about] so that the user does not see the .php extension at the end of the url.
I have read through the Apache HTTP Server Version 2.4 documentation regarding mod_rewrite trying to figure out how to make this happen and I have not yet had success. I've also read through all the current posts on this topic and tried the posted solutions without luck thus far.
Any and all help will be extremely appreciated.
Thank you for your time.
For 1,
Its better to put Alias to achieve. Enter the following line to the VirtualHost container in httpd.conf
Alias /about /about.php
Then restart the httpd
For 2,
Try editing the httpd.conf and php.ini. From httpd.conf edit the following lines
ServerTokens Prod
ServerSignature Off
From php.ini edit/add the line
expose_php = Off
Let us know if that helped you :)

tomcat 5.5 setting up context path with virtual hosts (non webapps directory)

I have been a web developer for a couple of years (some ASP, mostly PHP) and have recently taken on Java/JSP in the last two years.
The one thing I have tried repeatedly but continue to fail to wrap my head around is the way to setup a working JSP application in another location that is NOT the webapps folder. Rocking my application out of webapps does not seem to be a problem for me.
Could anyone help break this down, or point me to post somewhere which outlines it?
I have Googled repeatedly and read and re-read the documentation on the apache.org website, but I still cant seem to get it :(
I am trying to setup an "exploded" site (folders and files separated - not part of a WAR).
I know that I CAN edit the server.xml file, but am not supposed to (not that it matters... even when I attempt to edit that I fail).
I know I am missing something with the way the paths work. I THOUGHT I understand but I dont thinks so.
Any help is mucho appreciated!!
Love this site.
-- I have decided to re-phrase my question with more detail --
Let's say I have a directory structure as follows (**NOTE: webproject is NOT in the tomcat/webapps directory)
/webproject
/webproject/htdocs
/webproject/htdocs/images
/webproject/htdocs/images/logo.gif
/webproject/java
/webproject/java/page1.jsp
/webproject/java/page2.jsp
I would like to setup a virtual host so that I can view my project via a URL: http://webproject
I THINK all I need is two things (I am using apache):
a 'VirtualHost' entry in my httpd.conf file.
some type of 'context' file or fragment somewhere.
Am I right? If so, could someone help me define these two elements?
Also, if I want to use a domain-relative URL for referencing my logo.gif file from either of my jsp pages what would my path look like?
What if I want to use a domain-relative URL for referencing page2.jsp from page1.jsp?
HOWEVER, if there are paths within my application that reference resources (images, scripts, etc) using a path which starts at the root (ie. img src="/htdocs/images/foo.gif") it is not found.
Are you aware that those paths are supposed to be URL's relative to the current request URL (the one of the JSP page) and thus not local disk file system paths relative to their location at the local disk file system? As you're using /htdocs, it namely look like that you thought the latter.
Thus, if the JSP page is for example to be requested by http://example.com/context/page.jsp and the foo.gif is actually available by http://example.com/context/images/foo.gif, then you need to use either page-relative URL:
<img src="images/foo.gif">
or domain-relative URL:
<img src="/context/images/foo.gif">
or protocol-relative URL:
<img src="//example.com/context/images/foo.gif">
or absolute URL:
<img src="http://example.com/context/images/foo.gif">
OK, after struggling with this I finally got it to work. I aint saying this is the best (or even correct!) way of doing it, but this is what ultimately worked for me locally on my Windows machine (running WAMP) and on a remote server running Linux.
The paths listed are where they were for my environments. Obviously this could be different for your situation.
BEFORE-FIRST (Windows only)
With Windows, you need to setup an entry in your hosts file for the new "domain".
WIN - C:\Windows\System32\drivers\etc\hosts
127.0.0.1 webproject.local
FIRST
Need to edit httpd.conf and add a virtual host
WIN - C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf
LINUX - /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
DocumentRoot "C:\wamp\www\webproject"
ServerName webproject.local
</VirtualHost>
SECOND
Setup a host and context in server.xml. From what I read online, editing server.xml is discouraged but this was the only way I could figure it out.
WIN - C:\Program Files (x86)\Apache Software Foundation\Tomcat 5.5\conf\server.xml
LINUX - etc/tomcat5/server.xml
<Host name="webproject" debug="0" appBase="webapps" unpackWARs="true">
<Context path="" docBase="C:/wamp/www/webproject"/>
<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="webproject.local_error-log." suffix=".txt" timestamp="true"/>
</Host>
The thing I don't think is right, but worked for me was using "webapps" as the appBase even though my files are not in the "webapps" folder. Not sure why this is working... I fear that it is one of those situations where it works even though it shouldnt. I hope someone a lot smarter than me can offer some insight.