Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revisionBoth sides next revision
docs:user-guide:services:php [2018/03/03 19:08] – ↷ Links adapted because of a move operation docs:guide-user:services:webserver:php [2019/03/23 04:51] – [Installation] syntax highlights smoothswim
Line 1: Line 1:
 ====== PHP ====== ====== PHP ======
 ===== Installation ===== ===== Installation =====
-  - List available php packages <code>+  - List available php packages <code bash>
 opkg update opkg update
 opkg list php* opkg list php*
 </code> </code>
-  - Install php <code> +  - Install php <code bash
-opkg install php5 php5-cgi+opkg install php7 php7-cgi
 </code> </code>
  
 ===== Configuration ===== ===== Configuration =====
-For configuration please see the wiki-page for the particular web server: [[docs:user-guide:services:http.overview]], e.g. +For configuration please see the wiki-page for the particular web server: [[docs:guide-user:services:http.overview]], e.g. 
-  * [[docs:user-guide:services:webserver:http.apache#Configuring Apache and PHP5]] +  * [[docs:guide-user:services:webserver:http.apache#Configuring Apache and PHP5]] 
-  * [[docs:user-guide:services:webserver:lighttpd#Configuring Lighttpd and PHP5]] +  * [[docs:guide-user:services:webserver:lighttpd#Configuring Lighttpd and PHP5]] 
-  * [[docs:user-guide:services:webserver:http.hiawatha#Configuring Hiawatha and PHP5]] +  * [[docs:guide-user:services:webserver:http.hiawatha#Configuring Hiawatha and PHP5]] 
-  * [[docs:user-guide:services:http.nginx#Configuring Nginx and PHP5]] +  * [[docs:guide-user:services:webserver:nginx#Configuring Nginx and PHP5]] 
-  * [[docs:user-guide:services:uhttpd|Configuring uhttpd and PHP5]] +  * [[docs:guide-user:services:webserver:uhttpd|Configuring uhttpd and PHP5]] 
-  * or see [[docs:user-guide:services:webserver:lamp#Configuring PHP]]+  * or see [[docs:guide-user:services:webserver:lamp#Configuring PHP]]
  
 ===== Troubleshooting ===== ===== Troubleshooting =====
Line 23: Line 23:
   post_max_size = 8M   post_max_size = 8M
 Do not specify more memory than is available, and remember that other processes need memory too. Please note, some things will probably never run on the router. Especially under Backfire 10.03. PHP compiled without the SimpleXML extension, and libxml is missing too. If they are necessary, you need to recompile your own PHP. Without this extensions, some software, like Joomla 1.6 will never run. If you do manage to achieve to run, serious software solutions will run extremely slow, and will consume too much memory. Do not specify more memory than is available, and remember that other processes need memory too. Please note, some things will probably never run on the router. Especially under Backfire 10.03. PHP compiled without the SimpleXML extension, and libxml is missing too. If they are necessary, you need to recompile your own PHP. Without this extensions, some software, like Joomla 1.6 will never run. If you do manage to achieve to run, serious software solutions will run extremely slow, and will consume too much memory.
 +
 +===== PHP Development Server =====
 +This section explains how to quickly setup a php test server for prototyping php web applications, using php's own internal web server.
 +
 +A little known trick about php is that it has it's own built in web server.\\
 +If you install the command line php binary, you can run a quick, no frills web server on OpenWrt for development work and prototyping.\\
 +In no way should you expect a fully production ready web server from this method. php's internal web server is recommended for your own internal network testing and is not recommended as an alternative to a fully fledged http server daemon.\\
 +With that said; complete the following steps to create a quick php development server inside of an OpenWrt instance:
 +
 +Install the [[packages:pkgdata:php7-cgi|php7-cgi]] package using [[docs:guide-user:additional-software:opkg|opkg]].
 +<code bash>opkg update && opkg install php7-cli</code>
 +//(This pulls in packages [[packages:pkgdata:libpcre|libpcre]] [[packages:pkgdata:zlib|zlib]] [[packages:pkgdata:libxml2|libxml2]] [[packages:pkgdata:zoneinfo-core|zoneinfo-core]] [[packages:pkgdata:php7|php7]] as part of the installation.)//
 +
 +Optionally, now remove the package cache if you are low on memory space.
 +<code bash>rm -r /tmp/opkg-lists/</code>
 +Create a www directory (during testing, I skipped this normal step and just used the /root directory instead.)
 +<code bash>mkdir /www</code>
 +Use a text editor ([[packages:pkgdata:nano|nano]] in this example) to create the file **index.php** inside of the **/www** directory (nano can be installed via [[docs:guide-user:additional-software:opkg|opkg]] if need be.)
 +<code bash>nano /www/index.php</code>
 +Add the text "**It works!**" into the file, save and close it.
 +
 +Start the webserver from the command line.
 +<code bash>php-cli -S 172.16.0.1:8080 -t /www</code>
 +//(Replace **172.16.0.1:8080** with the ip address of your OpenWrt instance and the port number you want to use to access the server by.)//
 +
 +Open a web browser and visit the address **<nowiki>http://172.16.0.1:8080</nowiki>** (or whatever you used instead) and you should see the text "**It works!**" on the page.
 +
 +That's all there is to it.
 +
 +Taking it further, you could optionally [[docs:guide-user:base-system:uci|create a startup script]] which automates starting the server.\\
 +To stop the server use the **ctrl + c** key combination.\\
 +To spawn the server into a separate process and return command back to the console, add a double ampersand to the end of the command line options you use to start the server.
 +<code bash>php-cli -S 172.16.0.1:8080 -t /www &&</code>
 +The web server will then remain running until it's process is manually ended or the OpenWrt instance has been rebooted.
  • Last modified: 2019/04/04 07:08
  • by vgaetera