Getting Started
We are in the most fun section! Here you will understand how to create and start your PHP server.
Creating the main file
We need to create a file called index.js
in the project folder, this is where we will" create "our php server.
Hint
You can quickly create a new file using the Ctrl + N
shortcut on your keyboard and then using Ctrl + S
to save the file.
Editing index.js
Let's start! Open index.js with any text editor and enter the code below:
var php = require('easyphp');
php.start(80, function() {
console.log('(PHP) Server started');
})
In the code above, we defined that we need EasyPHP to start the server withvar php = require ('easyphp');
After that, we added the function to start the server, editing the port and an extra function to be called when the server starts.
php.get('/home/', 'home.php')
The get
you can use to define unique URL's. for example, as shown above, if I go to mywebsite.com/home/
it will return home.php
php.all('error404.html', function () {
console.log('Page accessed!')
})
All
will get all folders and subfolders that contain php files to be read according to the URL. For example: mywebsite.com/home/about
If there is a folder named home
and a php file called about
, it will return about.php
in case he doesn't find it, it will return index.php.
Hint
If you want, you can define a custom 404 page, just by adding the parameter of the location of the file that is the html of the error page.
Last updated