As the tittle says I'm new to all concepts of networkiing and web development.
Yesterday I was able to set up a Local Apache Server which I am using for development testing purposes.
I have assigned for a Server the ServerName "client1.dev" with a VirtualDocumentRoot "/www/client1/wwwroot", yet it is unclear for me how I am supposed to link my HTML page.
I am currently stuck at the point where all my files when accessing the domain appear under a plain list format from which I can select my files which will eventually load the HMTL content of choosing.
Since I'm a total beginner in this domain and I've got a hard time even googling the right questions. I'd like to know how I could instantly when accessing the server name domain to load a given HTML page.
By default, the Apache HTTP server will look for a file named index.html in the directory that is displayed. If it finds such a file, the index.html will be displayed. Otherwise it falls back to list the contents of the directory (but that could be changed to disallow directory listings).
If you do not have an index.html file in the directory, the easiest solution would be to create one.
If you want to display another file by default, then you can change that in the Apache configuration. Use the DirectoryIndex directive to do that. A basic example that changes the index files for the /foo directory looks like this:
# Example A: Set index.html as an index page,
# then add index.php to that list as well.
<Directory "/foo">
DirectoryIndex index.html
DirectoryIndex index.php
</Directory>
# Example B: This is identical to example A,
# except it's done with a single directive.
<Directory "/foo">
DirectoryIndex index.html index.php
</Directory>
The default page you want to make appear when accessing the root directory in your browser should be named "index.php" (I am supposing you are running PHP)
Related
I am new to this and I searched everywhere for a server routing method to be able to store 2 sites at different paths to a single domain. Most help I found refers to using virtual host to multiple domains, subdomains, IP etc. So far non of them fits what I need.
So I have the latest stack of Apache2, PHP, MySQL, on Debian-8 with 2 functional sites (databases, users, ...all OK) installed on sub folders of /html:
crm_site under /var/www/html/crm (storing a php script for project tracking)
and
wp_site under /var/www/html/wordpress (storing a wordpress website).
I want to be able to access them using the only domain I own (say www.example.com) which I already have set up to reach my server.
I was hoping that I would only need to add the path to my domain (www.example.com/crm/index.php or www.example.com/wordpress/index.php) and they will be served, but no matter what I add after the domain, the browser leads to the same place, showing the directory list in html (that is crm, and wordpress).
Can anyone tell me how can this be done? Thank you.
it sounds like you have everything setup correctly with the exception of your starting Directory.
It may be best to reword your question. This seems to be your situation (speaking from your perspective):
have a website at http://machine.domain.com
I want to set /var/www/html as my default directory
I want to set index.php as my default document
Once you view your issue this way, it is greatly simplified. A search engine can help you at this point.
To further guide you, doing said search for "apache set default directory" on Google, for instance, has the answer in bold. ... change the root directory of Apache or move the project to /var/www/html
You've already done this, right? So 1. and 2. above are done. If not, look at the following (which assumes apache2 package on Ubuntu latest. i've tested this in a docker container):
file: /etc/apache2/apache2.conf
contents:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Change the above /var/www/ to /var/www/html/
Next, the .php serving issue. This is controlled by the DirectoryIndex directive as referenced here. Looking at it's contents shows that index.php is enabled by default.
example:
root#b62dsa09327e:/# grep -rnw '/etc/apache2/' -e "DirectoryIndex"
/etc/apache2/mods-available/dir.conf:2: DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
This takes care of 3. And now we're all out of issues in your original question.
Note: you may have to chown the directory to whatever apache2 is running as in the event you dropped files in there as root. You'll also have to restart apache in order to have the changes above reflect in the service.
I am using xampp and i have a website in htdocs.
The home page home.html is in a folder website -> website/home.html. I want to host that website in xampp, so my question is, how to access the home page home.html directly.
Is there any modification that need to be done?
You'll just have to move your home.html to the htdocs folder (just simple move it outside your website folder) and then make sure to rename it as index.html.
Since index.(php/html) would be automatically be opened once you access your localhost.
But take note this will replace the XAMPP's default index page which is not a problem (unless you want to make use of it).
Are you saying that you want home.html to open as the default page when browsing to http://localhost? If so, you'll want to add home.html as a Directory Index file. In standard Apache HTTPD server configuration, you'd just look for a block looking like:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
Just add home.html to the end of the DirectoryIndex line, so you'd get:
<IfModule dir_module>
DirectoryIndex index.html index.php home.html
</IfModule>
The location of your httpd.conf file, where you'll need to make this change, depends on your XAMPP installation.
If this is not your question, you'll need to provide more specifics.
Although it might be preferable to change virtual hosts, a simpler solution would be to use an HTML Redirect. Create, in the htdocs folder, an index.html file with this line in it
<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=http://localhost/website/home.html">
(assuming that localhost is reachable and the structure of the directory is htdocs/website/home.html)
I am using shared server for my website and therefore i dnt have access to my httpd.conf.
my director r getting listed like
when i click on mysite.com/xyz/
all php files are showing.
Please help
in your .htaccess file add
Options -Indexes
To follow up and more thoroughness, you can also use an index file in the directory by creating a blank index.html file.
e.g. index.html
Or you can also specify the exact file and orders you want to be the index in htaccess with
DirectoryIndex index.html index.php
So there you have a few choices. The file will have to exist and it can contain anything or nothing.
I get my web site appears only by typing the following: www.example.com/index.php
when typing: www.example.com nothing happens.
How to call index.php on startup by typing my website's address.
Create a .htaccess file and put it in your server root. Add the following to the file:
DirectoryIndex index.php index.html index.htm
In the server section of your nginx.conf (or whatever file it includes), make sure you have the line:
index index.php;
You ARE running nginx, aren't you? ;-)
While you have not provided any technical details on your web server, I would suggest looking into DirectoryIndex.
The DirectoryIndex directive sets the list of resources to look for,
when the client requests an index of the directory by specifying a /
at the end of the directory name. Local-url is the (%-encoded) URL of
a document on the server relative to the requested directory; it is
usually the name of a file in the directory. Several URLs may be
given, in which case the server will return the first one that it
finds. If none of the resources exist and the Indexes option is set,
the server will generate its own listing of the directory.
Example:
DirectoryIndex index.html index.php
A request for http://mysite.com/docs/ would return http://mysite.com/docs/index.php if it exists, or would list the directory if it did not.
I have a small little site I am testing, first time using PHP. It is sitting on an Ubuntu box, in the /var/www folder. I can get to it in my internal network, but I can't get to it outside. I have port 80 forwarded to my Ubuntu box in my router. That is the first question. Second, how do I designate the first page to be served when you get to that box. The default Apache page is index.html. I want a page called login.php to be first. I have renamed index.html to html.old, but then I just get a file listing. Any help, much appreciated.
For custom index page place this in your .htaccess (in root folder)
DirectoryIndex login.php
I don't understand your first question.
For the apache default page, you can either go find your httpd.conf file edit this:
DirectoryIndex index.html
Or you can add the following to a .htaccess file:
DirectoryIndex login.php
2) Delete or move index.html. Rename login.php to index.php or create a new index.php with
<?php require dirname(__FILE__) . '/login.php';
Thats the most basic ways to do this. There are many there solutions, but it seems to me, that this is sufficient in your case.
This works, because the apache by default is looking for several index.*-files (in order).