How to make a PHP test website on localhost

Do you want a local webserver with all the required software – Apache webserver, MySql database, PHP and more – for free? Use it for testing websites, or for learning PHP, Perl or Ruby or just for fun!.
The thing is, you can run it all on your laptop and carry it wherever you go.

Download the server

First, get a copy of vmware workstation. Although the vmware player is good enough and free, I would really recommend vmware workstation for its additional set of features. Being able to take snapshots and revert at any time, believe me, will save your soul!

You can use the free virtual box as well.
See here how to open the downloaded virtual machine in virtual box

Then, download the Turnkey LAMP image.

The TurnKey LAMP image contains almost all necessary stuff in it.
(Apache, PHP, perl and the webmin interface to manage the server)

For the sake of simplicity, we will assume that you have vmware workstation on a windows laptop

After downloading the image, unzip it . Open the .vmx file in vmware workstation. Once you fire up the virtual machine, it will take you step by step through the setup process.

First, it will ask for a new root password. Give it a new password and note it down.

Then it will ask for a new MySQL database password. Again, create a new password.

Next step is a backup/configuration that you can skip.

Let it install the security updates in the next step.

The last step shows the IP address of the server. Press escape and close the wizard.

login as root and then shutdown by entering
shutdown now
in the command prompt.

Press the power off virtual machine button in vmware.

Need a fixed IP address

In vmware, go to menu item: VM->Settings
Select Network Adapter and select ‘NAT’. Press OK and start the virtual machine.

After rebooting, your new server will show a screen like the one below displaying the IP address.

We need to setup a static IP so that we have a fixed address for this new server.

Press enter to go to the ‘Advanced Menu’.
Static IP Page

Select ‘Networking’ and then ‘Static IP’. take a note of the IP address and select ‘Apply’.

You can now press escape and quit the setup screen.

Enter the IP address you noted down in the last step in your browser and you will get the control panel screen:

Click the ‘Webmin’ icon, login and browse around. You will be happy to see how easy it is to manage your server using webmin!

Installing an FTP Server

We will now install the proftpd package on your new server for ease of transferring files.

In Webmin, go to: System->Software packages menu item

Under “Install a New Package”, select “Package from APT” and press the “Search APT” button.
This will open a window to search packages. Enter “proftpd”.

Click on “proftpd-basic” and then press “Install”

Note that installing any other package is similarly easy as well.

Create a new user

In your server’s webmin page, go to: System->Users & groups menu item

Click ‘Create New User’ link.

In the ‘Create user” page, provide a username, and ‘Normal password’ and press ‘Create’.

You have added a new user to the system now.
Let’s log-in to your server through FTP (you can get Filezilla FTP client here).

Enter the IP address of your server, your new user name and the password in the FTP client and log-in.

Create a new folder www (that we will be our web publish folder- will see in a minute)

Create a new ‘local’ website

Go back to your server’s webmin page. Select: Servers->Apache webserver menu item.

Click ‘Create virtual host’

For ‘document root’ provide the path to the www folder we created through FTP in the last step.

For ‘Server name’ enter an easy-to-remember domain name that you wish to use as a local web address.
For this example, we will use the domain user9.com

Press ‘create’.

Back in the Apache webserver page, we need to restart the webserver. Click the ‘Stop Apache’ link. After a few minutes, click the ‘Start Apache’ link.

We should now configure our local machine to direct to the new domain name.

Setting up a ‘local’ domain

Go back to your host machine (your laptop ).

Open Start menu->Accessories right click on Notepad and select “run as administrator”.

In notepad, file->open and select the file C:WindowsSystem32driversetchosts (you may have to copy and paste the path to your file open dialog box; those system folders will usually be hidden)

Add a new line, enter the IP address of your new server and then the new domain name.

Save the file and close notepad.
Log in through FTP and upload a sample HTML or PHP file to the www folder.

Now just enter the URL in the browser

There comes! your new local website!

Adding more websites:
To create more websites, you can repeat the steps starting from Create a new ‘local’ website.
For example, create a folder user10 and then add another virtual domain user10.com with Document Root mapped to the new folder.

Leave a Reply 4 comments

Close

Copy and paste this code to display the image on your site

Copied!