Running php on node js

moeiscool / README.md

You must be root to follow the steps in this guide.

sudo apt-get install mariadb-server mariadb-client 
sudo systemctl stop mariadb.service sudo systemctl start mariadb.service sudo systemctl enable mariadb.service 
sudo mysql_secure_installation 

The choices you should choose are as follows:

- Enter current password for root (enter for none): Just press the Enter - Set root password? [Y/n]: Y - New password: Enter password - Re-enter new password: Repeat password - Remove anonymous users? [Y/n]: Y - Disallow root login remotely? [Y/n]: Y - Remove test database and access to it? [Y/n]: Y - Reload privilege tables now? [Y/n]: Y 
sudo systemctl restart mariadb.service 
CREATE USER 'mysqlConnectionUserName'@'localhost' IDENTIFIED BY 'new_password_here'; GRANT ALL ON * TO 'mysqlConnectionUserName'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION; FLUSH PRIVILEGES; 
  1. At this point you may want to import your SQL database for any websites you want to use. While still in the MariaDB client you can run the following to import .sql files.

Installing a PHP Website using Node.js Express Web Server

You must be root to follow the steps in this guide.

curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash - sudo apt-get install -y nodejs php sudo apt install php-fpm php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-mcrypt php-ldap php-zip php-curl php-cgi 
mkdir /home/wordpress cd /home/wordpress 
wget https://gist.githubusercontent.com/moeiscool/876e64a9725fa07ac9e6852e1001f1d5/raw/e4a8c72721e48c13a22a6894a56e766481fa5eed/runPhpSite.js -O runPhpSite.js 
  1. Put the PHP website inside a folder called public . The full path should be /home/wordpress/public . Your folder structure should be similar to the following.
- home | - wordpress | |- runPhpSite.js | |- public 

Источник

Читайте также:  Как форматировать php код

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Node.js interfacing with PHP-FPM through FastCGI

License

davidcoallier/node-php

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Inline PHP Server Running on Node.js

Be worried, be very worried. The name NodePHP takes its name from the fact that we are effectively turning a nice Node.js server into a FastCGI interface that interacts with PHP-FPM.

This is omega-alpha-super-beta-proof-of-concept but it already runs a few simple scripts. Mostly done for my talks on Node.js for PHP Developers this turns out to be quite an interesting project that we are most likely be going to use with Orchestra when we decide to release our Inline PHP server that allows people to run PHP without Apache, Nginx or any webserver.

Yes this goes against all ideas and concepts of Node.js but the idea is to be able to create a web-server directly from any working directory to allow developers to get going even faster than it was before. No need to create vhosts or server blocks ore modify your /etc/hosts anymore.

This node.js module is made for the sole purpose of my conference talk but also to allow developers to get started with PHP even faster than the usual. After installing this node-module, developers need to make sure they have PHP-FPM running somewhere on their system. If it is, they will be able to go to any of their web-directory (that the FPM user has access to) and simply type node php and from there they will see a nice little output that looks like this:

bash$~ PHP Server is now running on port 9001 Incoming Request: GET /test.php --> Request Response Status Code: "200" 

This is going to be running in the browser allowing you to develop and test your applications faster. Hopefully you will end up forking the project and helping out because I do not have enough time to do all I would want to do with this thing.

It allows you to go into a directory, type «node-php» and have a running webserver that serves PHP. Happy.

Well this is a bit tricky, there are a few things you will need in order to get this thang running:

  • You need a running PHP-FPM server.
  • You need to have Node.js installed with NPM
  • Install node-fastcgi-parser ( https://github.com/billywhizz/node-fastcgi-parser )
  • Then you git clone git://github.com/davidcoallier/node-php.git , then you git submodule init , then you git submodule update , and npm install

For this beta version, we assume that you are running FPM off localhost on port 9000 . If you are running through a socket you may want to make your own script that looks like this:

var php = require('nodephp'); php.nodephp(< fcgi: < port: '/tmp/php-fpm.sock', host: null, >, server: < port: 9998 >>); 

Please note that the sock connection has not been tested yet. All that has been tested is connecting to a different FastCGI port and starting the server on a different port like such:

var php = require('nodephp'); php.nodephp(< fcgi: < port: 9001, host: 'localhost', >, server: < port: 9111 >>); 

You will realise rapidly enough that only running this is quite useless as it does not serve static files and such. This is why the node-php code has the abiliyt to define blocks — albeit simple blocks. They are defined in the second argument of the nodephp call:

var php = require('nodephp'); php.nodephp(< fcgi: < port: 9001, host: 'localhost', >, server: < port: 9111 >>, < "\.(js|css|png|jpg|jpeg|gif|txt|less)$": php.NODEPHP_TYPE_STATIC, "\.php$": php.NODEPHP_TYPE_FCGI, "index": "index.php" >); 
NODEPHP_TYPE_STATIC: Static files that do not need to go through the fastcgi handler (`fastcgi_pass`) NODEPHP_TYPE_FCGI: Files you do send through the FCGI handler. 

If you want more simple using the default localhost:9000 for the FCGI handler:

var php = require('nodephp'); php.nodephp(<>, < "\.(js|css|png|jpg|jpeg|gif|txt|less)$": php.NODEPHP_TYPE_STATIC, "\.php$": php.NODEPHP_TYPE_FCGI, "index": "index.php" >); 

There are a few very important issues right now:

  • There is no POST handling. I’m not that far in the FCGI specs yet — need to find how to send data (post data)
  • There is no base url. If you include ../../../../poop it will try to load it and most likely will fail.
  • If you try to load a file that the PHP-FPM worker does not have access to, it will fail silently and you will swear. A lot. By silently I mean, it will give you a 404 even though the files do exist.

This is an ugly prototype and if you run this in production you are most likely mentally challenged (Not that it’s a bad thing..) but I take no responsibility for what you do with this. Moreover, this goes against everything Node.js stands for. So realise that.

Released under the New BSD License.

Copyright (c) 2011 David Coallier

About

Node.js interfacing with PHP-FPM through FastCGI

Источник

Run PHP Scripts from Node JS

Due to the asynchronous only design of ImageMagick within Node JS, I ran into a nightmare trying trying to code a recent web application. You can not run ImageMagick synchronously in NodeJS, I wasn’t able to get callbacks to work correctly, the npm async series method wasn’t working, and the nesting of ImageMagick functions wasn’t favorable. Much of my code was using ImageMagick to check the properties of the image and do conditional functions based on the results.

All that complaining said, the bigger frustration is that I already had most of this script written in PHP. In PHP the script uses an object oriented approach which does allow for a synchronous flow and conditional checks. So could I use this PHP script along side of my Node JS application?

How to call PHP from Node JS

A bit of digging and all of the solutions I was able to find suggested running Apache along side of Node JS, which would then allow you to call PHP via Apache. But seriously, this makes no sense. Calling a web server from a web server on the same machine? Even worse, I wanted my Node JS web app to be called on port 80, so installing Apache will create a port conflict, etc.

I want to give credit to scriptol.com for being the only reference I could find on how to beautifully blend Node JS with the synchronous methods of ImageMagick in PHP.

Источник

moeiscool / README.md

You must be root to follow the steps in this guide.

sudo apt-get install mariadb-server mariadb-client 
sudo systemctl stop mariadb.service sudo systemctl start mariadb.service sudo systemctl enable mariadb.service 
sudo mysql_secure_installation 

The choices you should choose are as follows:

- Enter current password for root (enter for none): Just press the Enter - Set root password? [Y/n]: Y - New password: Enter password - Re-enter new password: Repeat password - Remove anonymous users? [Y/n]: Y - Disallow root login remotely? [Y/n]: Y - Remove test database and access to it? [Y/n]: Y - Reload privilege tables now? [Y/n]: Y 
sudo systemctl restart mariadb.service 
CREATE USER 'mysqlConnectionUserName'@'localhost' IDENTIFIED BY 'new_password_here'; GRANT ALL ON * TO 'mysqlConnectionUserName'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION; FLUSH PRIVILEGES; 
  1. At this point you may want to import your SQL database for any websites you want to use. While still in the MariaDB client you can run the following to import .sql files.

Installing a PHP Website using Node.js Express Web Server

You must be root to follow the steps in this guide.

curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash - sudo apt-get install -y nodejs php sudo apt install php-fpm php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-mcrypt php-ldap php-zip php-curl php-cgi 
mkdir /home/wordpress cd /home/wordpress 
wget https://gist.githubusercontent.com/moeiscool/876e64a9725fa07ac9e6852e1001f1d5/raw/e4a8c72721e48c13a22a6894a56e766481fa5eed/runPhpSite.js -O runPhpSite.js 
  1. Put the PHP website inside a folder called public . The full path should be /home/wordpress/public . Your folder structure should be similar to the following.
- home | - wordpress | |- runPhpSite.js | |- public 

Источник

Оцените статью