Monday 12 December 2016

[web] Start a simple web server

This guide will demonstrates how to create your own small local web server with php support via compiling both of them.

I'm using ubuntu 16.04 for this, But any version should do it.

Contents:
1- Compile nginx from source
2- Compile php from source
3- Edit nginx config
4- Start the server

- Prepare the working directory:
Simply create a new working directory and cd into it
And create a nginx prefix directory (mkdir anything) And a php prefix directory (mkdir anythingphp)



Compile nginx from source

I'll compile nginx from source.
Firstly: download nginx source from nginx website.
http://nginx.org/en/download.html
Note that you need to download the one without windows name in it.
extract that gzip into the working directory.
I prefer to compile that into a custom prefix but it's fine if you dont.
Compile nginx via:
./configure --prefix=/hereisyourprefix
make
make install
Change /hereisyourprefix to your nginx prefix


Compile php from source

Download php from:
Extract that into the working directory and cd into it.
Compile php via:
./configure --prefix=/hereisyourprefix
make
make install
Change /hereisyourprefix to your php prefix



Edit nginx config

Open [prefix]/conf/nginx.conf using your favorite text editor and:
add
location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9857;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
After
error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
And change the other parameters if needed



Start the server

Cd into sbin folder inside nginx prefix folder and Run:
./nginx -p nginxprefixdir
Change nginxprefixdir into your nginx prefix folder.

And then Open A new terminal then cd into the bin folder inside php prefix folder.
Then run php via:
./php-cgi -b 127.0.0.1:9857

No comments:

Post a Comment