Installing a local server on Windows

Installing a local server on Windows

16.08.2022
Author: HostZealot Team
2 min.
1754

To deploy a working environment, you will definitely need to install a local server on Windows – as a rule, such a bundle includes two elements:

  • GIT (Distributed Version Control System);
  • local server (MySQL, Apache, mongodb, Memcached, nginx, PHP).

In our case, for clarity, we will consistently install PuTTY, GIT, the gentleman's Denwer set (Apache, MySQL, PHP), Nginx, as well as Memcached, and MongoDB. All this is necessary for the full deployment of the local server.

How to install PuTTY

This client will allow us to access the project remotely and securely via SSH or Telnet. You just need to go to the https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.htmlofficial website of the developer, download the installer and install everything in the standard way. There will be no difficulties. You will have to deal with the setup yourself since this is not the main topic of our article.

Installing GIT

Again, go to the https://tortoisegit.org/official TortoiseGit website, select the appropriate release version, download, and install. We recommend TortoiseGit, as it is more stable and reliable from the point of view of development.

Denwer

A standard set of any web developer, including an installer, a web server, a MySQL database, PHP, a virtual hosting management system, and a number of other important components.

To install, you need to download the basic Denwer kit, as well as additional PHP5 modules. It is important to emphasize here that you will have to register, and only then you will be able to get a link to download the software to your email.

Memcached

We have already described this object caching system in detail in a separate article, so we will not linger here for a long time. To install, you will need to download an archive with a file in the binaries format, and then unpack it into the \usr\local\memcached directory.

In order for Memcached to run together with Denwer, you will have to write a small script with startup commands. To do this, in the \denwer\scripts\init directory.d\ create a file with the name memcached.pl , open it in edit mode and write the following lines:

#!perl -w
package Starters::Memcached;
BEGIN { unshift @INC, "../lib"; }
 
use StartManager;
 
my $basedir = '/usr/local/memcached/';
chdir($basedir);
 
StartManager::action
  $ARGV[0],
  start => sub {
    ###
    ### START.
    ###
        print "Starting memcached\n";
        system("memcached.exe -d");
        print "  Started!\n";
  },
  stop => sub {
    ###
    ### STOP.
    ###
        print "Stopping memcached\n";
        system("TASKKILL /F /IM memcached.exe");
        print "  Stopped!\n";
  };
 

return 1 if caller;

It remains a small matter – you need to create a link to this script in three different directories so that when you start Denwer, it is automatically executed init.d/memcached.pl . To do this, in a text editor, you need to write:

init.d/memcached

We call the file 40_memcached and save it in three different folders:

  • \denwer\scripts\main\start
  • \denwer\scripts\main\stop
  • \denwer\scripts\main\restart

After that, open the text script index.php and add three lines to it:

$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211);
echo ‘Memcache ver: ’ . $memcache->getVersion();

You can check if everything is working as intended by restarting Denwer.

Configuring the Nginx Web Server

During the installation of a local server on Windows, you can not do without a web server – in our case, this is Nginx. You just need to go to the official developer's website, download the Windows version and unpack the files to the \usr\local\nginx directory.

The next step is to configure a virtual host for your test site. Open \usr\local\nginx\conf\nginx.conf in edit mode and add the lines:

 	server {
          listen 127.0.0.1:80;
          server_name www.test.local test.local;
 
          if ($host = 'test.local'){
              rewrite ^/(.*)$ http://www.test.local$1 permanent;
          }
 
          location ~* \.(jpeg|jpg|gif|png|css|js|pdf|txt|tar)$ {
              root Z:\home\/test.local\www;
          }
          location / {
              ssi on;
             
              proxy_pass http://127.0.0.1:8080/;
              proxy_set_header X-REQUEST_URI $request_uri;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-for $remote_addr;
              proxy_set_header Host $host;
              proxy_connect_timeout 60;
              proxy_send_timeout 90;
              proxy_read_timeout 90;
              proxy_redirect off;
              proxy_set_header Connection close;
              proxy_pass_header Content-Type;
              proxy_pass_header Content-Disposition;
              proxy_pass_header Content-Length;
 
              root Z:\home\/test.local\www;
          }

  	}

Naturally, all the above parameters must be adapted in accordance with your project.

installing a local server on windows

How to configure Apache

Apache's default operating parameters are often not suitable for work – in particular, it is usually recommended to change the port 80 installed out of the box. Either for security reasons or if another web server is running on this port – for example, the same Nginx. Anyway, go to the Apache settings (посилання) and change the template for the virtual host to assign it a different port.

Open the file \usr\local\apache\conf\httpd.conf in edit mode and look for the following lines:

#Listen $&{ip:-127.0.0.1}:$&{port:-6080}
#NameVirtualHost $&{ip:-127.0.0.1}:$&{port:-6080}
#<VirtualHost $&{ip:-127.0.0.1}:$&{port:-6080}>
#  DocumentRootMatch "/home/(?!cgi-)(.*)^1/(?!cgi$|cgi-)(.*)"
#  DocumentRootMatch "/home/(?!cgi-)(.*)/public_html^1"
#  DocumentRootMatch "/home/(?!cgi-)(.*)/public^1"
#  DocumentRootMatch "/home/(?!cgi-)(.*)^1/html/(.*)"
#  DocumentRootMatch "/home/(?!cgi-)(.*)^1/domains/(?!cgi$|cgi-)(.*)"
#  DocumentRootMatch "/var/www/html/(?!cgi-)~(.*)^1/(?!cgi$|cgi-)(.*)"
#  DocumentRoot "$&" 
#  ServerName "%&/-www"
#  ServerAlias "%&/-www" "%&/-www/www" $&{host:-}
#
#  $&{directives:-}
#
#  ScriptAlias /cgi/ "$^1/cgi/"
#  ScriptAlias /cgi-bin/ "$^1/cgi-bin/"
#  AllowEncodedSlashes on

#</VirtualHost>

Here, instead of 6080, you can specify any other convenient port.

How to set up Denwer autorun with Nginx

Go to the directory \denwer\scripts\init.d\, here you need to create a file nginx.pl . Its contents should look like this:

#!perl -w
package Starters::Nginx;
BEGIN { unshift @INC, "../lib"; }
 
use StartManager;
 
my $basedir = '/usr/local/nginx/';
chdir($basedir);
 
StartManager::action
  $ARGV[0],
  start => sub {
	###
	### START.
	###
    	print "Starting Nginx\n";
        system("start nginx.exe");
    	print "  Started!\n";
  },
  stop => sub {
	###
	### STOP.
	###
    	print "Stopping Nginx\n";
        system("nginx.exe -s stop");
    	print "  Stopped!\n";
  };
 

return 1 if caller;

Save the changes and move on. Now open the text editor, write "init.d/nginx" without quotes in it, and then save it under the name 50_memcached in three different directories:

  • \denwer\scripts\main\start
  • \denwer\scripts\main\stop
  • \denwer\scripts\main\restart

To check the scripts, restart Denwer – if CSS is connected, everything is done correctly.

How to configure MongoDB

This document-oriented system is often used on local servers, as it has a clear object structure and advanced query capabilities. In addition, it is convenient to scale the database, which sometimes saves a lot of time. You can download it from https://www.mongodb.com/the official website of the developers.

Before installing MongoDB, you will need to download the PHP driver – go to github and find the file php_mongo.dll . After downloading, upload it to the \usr\local\php5\ext\ directory. You can connect the extension in the php.ini file by adding the line:

extension=php_mongo.dll

Now proceed directly to the installation – download the archive with the installer and unpack its contents at \usr\local\mongodb. Here we immediately create two more folders with the names db and logs.

Next comes the installation of the service:

> cd C:\WebServers\usr\local\mongodb\bin\
> mongod.exe --install --dbpath=C:\WebServers\usr\local\mongodb\db\ --logpath=C:\WebServers\usr\local\mongodb\logs\

It remains to configure MongoDB autorun together with Denwer. To do this, follow the path \denwer\scripts\init.d\ and here we create a file with the name mongod.pl . We throw a small script inside:

#!perl -w
package Starters::mongoDB;
BEGIN { unshift @INC, "../lib"; }
 
use StartManager;
 
StartManager::action
  $ARGV[0],
  start => sub {
	###
	### START.
	###
        print "Starting mongoDB\n";
        system("net start mongoDB");
        print "  Started!\n";
  },
  stop => sub {
	###
	### STOP.
	###
        print "Stopping mongoDB\n";
        system("net stop mongoDB");
   	 print "  Stopped!\n";
  };

 
return 1 if caller;

Now, by analogy with the previous steps, open the text editor, write inside:

init.d/mongod

We call the file "60_mongod" and save it in three directories:

  • \denwer\scripts\main\start
  • \denwer\scripts\main\stop
  • \denwer\scripts\main\restart

After that, we recommend visiting the official website of MongoDB developers and choosing an admin panel to your liking – all people have different tastes regarding interfaces, so we will not give any universal recommendations.

Finally, we add that instead of PuTTY, you can use KiTTY, and the Denwer bundle can be replaced with the Open Server software environment – it was also created with an eye on web developers and works fine under Windows. We hope our material helped you figure out how to install a local server on Windows and prepare it for work on the project. Thanks for your attention!

Related Articles