Jump to content

How to Host a website locally for personal use


Die2mrw007

Recommended Posts

Purchasing a hosting is not really affordable to any newbies. . . Anyone who wish to setup a local server for educational purposes or testing purposes, can setup it for free.

Here I recently setup a local server on my Windows PC. I just thought to share a tutorial for the same. :)

So, here we go :

Requirements:

Apache Handler

MySQL (For Database)

PHP

myPHPAdmin (For managing Database in GUI)

Apache is one of the most popular web servers, and part of its charm is that it's free. It also has a lot of features that make it very extensible and useful for many different types of websites. It is a server that is used for everything from personal web pages to enterprise level sites.

Download Apache:

I recommend downloading the latest stable release. Download the binary for Win32 from Link. I downloaded Apache Stable Release v2.2.22 (released 2012-01-31) Win32 Binary including OpenSSL 0.9.8t (MSI Installer)

Once you've downloaded the binary, run it to start the self-installation.

You can input the Network domain and server name as "localhost" (without quotes)

http://forum.gizmolord.com/index.php?action=dlattach;topic=3556.0;attach=7220

Choose custom installation and select all the modules to be installed. Click "Finish".

Assuming that there were no problems, you are ready to customize your Apache configuration. This really just amounts to editing the httpd.conf file. This file is located in the C:/Program Files/Apache Group/Apache2/conf directory. You can edit the conf file with any text editor (Notepad Recommended).

Note: you should not use Word or a word processor to edit this file.

Open httpd.conf file using Notepad editor. Find DocumentRoot “C:/Program Files/Apache Group/Apache2/htdocs”

and replace it with DocumentRoot “E:\myhosting”

Find <Directory  “C:/Program Files/Apache Group/Apache2/htdocs” and replace with <Directory  “E:\myhosting”

(I have setup my server in this folder (E:\myhosting) and hence specified it. You can use any path but mention the same in this field)

Find #AllowOverride None and change to AllowOverride All.

Save the file as "httpd.conf" (without quotes) and in "save as" field, select "All files"

You are done setting up Apache :)

Type in web addresses http://localhost/

You will see a text as "It works!"

(this is the confirmation of setting up the Apache successfully :)

Every files you put in folder htdocs, will be shown on http://localhost/

Now we need a database for the hosting. MySql is the better option for it :)

Download MySql for Community Server from here

Get the appropriate MSI installer

Run the MySql installer which you downloaded.

Click on Custom installation and select all the modules to install

After the installation, it will ask for the configuration.

Select Detailed Configuration and click Next.

Select Server Machine and click Next.

Select Multifunctional Database and click Next.

For InnoDB Tablespace Settings, leave the default settings and click Nex

Select Online Transaction Processing (OLTP) and click Next.

Check Enable TCP/IP Networking, leave the default Port Number and click Next.

Select Standard Character Set and click Next.

Check Install as Windows Service, uncheck Include BIN directory in Windows PATH and click Next.

Enter a password for your root user, uncheck Create an Anonymous Account and click Next.

Click Execute to complete the installation.

Testing MySQL

Open your MySql command line client

To open MySql command line client Go to Start->All programs-> MySql-> MySql server 5.1-> MySql command line client

Type your password and you will get like this

http://forum.gizmolord.com/index.php?action=dlattach;topic=3556.0;attach=7222

Now we need to install php

Download the php zip files from here (Download the VC6 x86 Thread Safe file)

Extract the php files you downloaded to the desired drive with folder name "php"

Make a duplicate copy of "php.ini-recommended" file and rename it to "php.ini"

Open the file with notepad editor

Enable Short Open Tags

Search for the line that reads:

short_open_tag = Off

If short_open_tag is set to "off", tags like "<?" will not be recognised as the start tag for a PHP script. In such a case, to begin a PHP script, you will need to code your script with an opening tag like "<?php". Since many third party PHP scripts use "<?", setting this to "Off" will give you more problems than it's worth, particularly since most, if not all, commercial web hosts that support PHP have no issues with your scripts using "<?" as the open tag. To fix this, change it to the following:

short_open_tag = On

Magic Quotes

By default, input data is not escaped with backslashes. That is, if your visitors enter an inverted comma (single quote) into your web form, the script will receive that unadorned inverted comma (single quote). This is for the most part desirable unless you have special requirements. If you want your input data to have the backslash ("\") prefix, such as, for example, to mimic your web host's settings, search for the following:

magic_quotes_gpc = Off

and replace it with:

magic_quotes_gpc = On

Do not do this unless your web host has this setting as well. Even with the setting of "Off", you can still use the addslashes() function in PHP to add the slashes for the specific pieces of data that need them.

Register Globals

A number of older scripts assume that all data sent by a form will automatically have a PHP variable of the same name. For example, if your form has an input field with a name of "something", older PHP scripts assume that the PHP processor will automatically create a variable called $something that contains the value set in that field.

If you are running such scripts, you will need to look for the following field:

register_globals = Off

and change it to the following:

register_globals = On

WARNING: Do NOT do this unless you have third party scripts that need it. When writing new scripts, it's best to always code with the assumption that the register_globals item is set to "Off".

Display Errors

On a "live" website, you typically want errors in your script to be silently logged to a PHP error file. On your own local machine, however, while you are testing and debugging a PHP script, it is probably more convenient to have error messages sent to the browser window when they appear. This way, you won't miss errors if you forget to check the error log file.

If you want PHP to display error messages in your browser window, look for the following:

display_errors = Off

And change it to:

display_errors = On

This value should always be set to "Off" for a "live" website.

Session Path

If your script uses sessions, look for the following line:

;session.save_path = "/tmp"
The session.save_path sets the folder where PHP saves its session files. Since "/tmp" does not exist on Windows, you will need to set it to a directory that does. One way is to create a folder called (say) "c:\tmp" (the way you created c:\php earlier), and point this setting to that folder. If you do that, change the line to the following:

session.save_path = "c:\tmp"

Notice that in addition to changing the path, I also removed the semi-colon (";") prefix from the line.

Alternatively, you can find out the current TEMP folder on your computer and use that. Or create a "tmp" folder in your PHP directory, like "c:\php\tmp" and set the configuration file accordingly. The possibilities are endless. If you can't decide, just create "c:\tmp" and do as I said above.

SMTP Server

If your script uses the mail() function, and you want the function to successfully send mail on your local machine, look for the following section:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = [email protected]

Change it to point to your SMTP server and email account. For example, if your SMTP server is "mail.example.com" and your email address is "[email protected]", change the code to:

[mail function]
SMTP = mail.example.com
smtp_port = 25
sendmail_from = [email protected]

Note that after you do this, when your script tries to use the mail() function, you will need to be connected to your ISP for the function to succeed. If you do not modify the above lines and attempt to use mail() in your script, the function will return a fail code, and display (or log) the error (depending on how you configure php.ini to handle errors).

Running PHP 5 as an Apache Module

To configure Apache to load PHP as a module to parse your PHP scripts, use an ASCII text editor to open the Apache configuration file, "httpd.conf". Apache 2.2.x users can find it in "C:\Program Files\Apache Software Foundation\Apache2.2\conf\". Basically, it's in the "conf" folder of wherever you installed Apache.

Search for the section of the file that has a series of "LoadModule" statements.

Statements prefixed by the hash "#" sign are regarded as having been commented out.

If you are using Apache 1.x, add the following line after all the LoadModule statements:

LoadModule php5_module "c:/php/php5apache.dll"

If you are using Apache 2.0.x, add the following line after all the LoadModule statements:

LoadModule php5_module "c:/php/php5apache2.dll"

If you are using Apache 2.2.x, add the following line instead:

LoadModule php5_module "c:/php/php5apache2_2.dll"

Note carefully the use of the forward slash character ("/") instead of the traditional Windows backslash ("\").

If you are using Apache 1.x, search for the series of "AddModule" statements, and add the following line after all of them. You do not have to do this in any of the Apache 2 series of web servers.

AddModule mod_php5.c

Next, search for "AddType" in the file, and add the following line after the last "AddType" statement. Do this no matter which version of Apache you are using. For Apache 2.2.x, you can find the "AddType" lines in the <IfModule mime_module> section. Add the line just before the closing </IfModule> for that section.

AddType application/x-httpd-php .php

If you need to support other file types, like ".phtml", simply add them to the list, like this:

AddType application/x-httpd-php .phtml

Finally, for those using one of the Apache 2 versions, you will need to indicate the location of your PHP ini file. Add the following line to the end of your httpd.conf file.

PHPIniDir "c:/php"

Of course if you used a different directory for your PHP installation, you will need to change "c:/php" to that path. Remember to use the forward slash ("/") here again.

Configuring the Default Index Page

This section applies to all users, whether you are using PHP as a module or as a CGI binary.

If you create a file index.php, and want Apache to load it as the directory index page for your website, you will have to add another line to the "httpd.conf" file. To do this, look for the line in the file that begins with "DirectoryIndex" and add "index.php" to the list of files on that line. For example, if the line used to be:

DirectoryIndex index.html

change it to:

DirectoryIndex index.html index.php

The next time you access your web server with just a directory name, like "localhost" or "localhost/directory/", Apache will send whatever your index.php script outputs, or if index.php is not available, the contents of index.html.

Restart the Apache Web Server for the changes to take effect.

Testing Your PHP Installation

Create a PHP file with the following line:

<?php phpinfo(); ?>

Save the file as "test.php" or any other name that you fancy, but with the ".php" extension, into your Apache htdocs directory. If you are using Notepad, remember to save as "test.php" with the quotes, or the software will add a ".txt" extension behind your back.

Open your browser and access the file by typing "localhost/test.php" (without the quotes) into your browser's address bar. If all goes well, you should see a pageful of information about your PHP setup. Congratulations you have successfully installed PHP and configured Apache to work with it.

Installing PhpMyAdmin

Requirements

PHP 5.2/5.3

MySQL 5.1/5.5

Apache 2.0/2.2 (or IIS)

Download phpMyAdmin from here

Extract it on htdocs folder of Apache installation under folder name "phpmyadmin"

Restart your apache server.Open your browser and type

http://localhost/phpmyadmin/

http://forum.gizmolord.com/index.php?action=dlattach;topic=3556.0;attach=7224

Type username and password to login.

Username will be root and password will be the one you setup while installing MySql

post-1-138186193155_thumb.png

post-1-13818619316_thumb.jpg

post-1-138186193166_thumb.jpg

Link to comment
Share on other sites

But...whats the difference between this and other paid....like yahoo web hosting.....

is this published freelyy.....

lol its on your PC it is using you HDD as storage ..! and in yahoo etc we use there HDD as storage so they take money and we can't make a website online using our HDD as a storage...moreover its used for testing purposees and faster responses..!
Link to comment
Share on other sites

lol its on your PC it is using you HDD as storage ..! and in yahoo etc we use there HDD as storage so they take money and we can't make a website online using our HDD as a storage...moreover its used for testing purposees and faster responses..!

We can make the site public too...but our PC should be online 24x7 or else other users who access our site will not be able to visit the site.
Link to comment
Share on other sites

how to do that?what would be the nameservers then??

You have to set that as DNS... but it will be a bad idea to host from your personal computer and the limited internet connectivity in India..... Hosting needs a good amount of Internet connectivity. When a person access your locally hosted site, your PC sends the data to the target PC (person accessing the site) and vice versa when they make a post or add anything..... A good connection needs to be maintained between both the PC. If your Internet connectivity is low, the target PC will get the result delayed making the site load slow at their end.

When multiple users access the site, your System resource is used and your PC may freeze when it couldnt handle the requests.

A good server PC needs a dual core server processor and 24 GB high speed RAM

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...