BPI-M2+ Weather station_11 create web server(nginx+php)
we need finish create nginx+php server
install nginx:
1 install nginx
sudo apt-get install nginx
-
Modify Profile
sudo nano /etc/nginx/sites-available/default
change web root directory
chane root to as below
#root /var/www/html;
root /home/pi/www;
-
create a test page
sudo nano /home/pi/www/index.html
edit index.html add below:
<h1>hello world!</h1>
save
4.reboot nginx
sudo nginx -s stop
sudo nginx
5 test
open browser and imput : 127.0.0.1
install PHP:
-
download php
wget –c http://cn2.php.net/distributions/php-5.4.45.tar.bz2
-
unzip
tar –jxvf php-5.4.45.tar.bz2
-
Generate configuration files
cd php-5.4.45
./configure --enable-fpm --with-mysql
erroe:
error:xml2-config not found. Please check your libxml2 installation
Execute the commands below:
sudo apt-get install libxml2-dev
rebuild makefile
../configure--enable-fpm --with-mysql
-
compile
./make
-
when compile finish , do install
sudo makeinstall
-
Create a configuration file, and copy it to the correct location.
cp php.ini-development/usr/local/php/php.ini
cp /usr/local/etc/php-fpm.conf.default/usr/local/etc/php-fpm.conf
cp sapi/fpm/php-fpm /usr/local/bin
-
set php.ini cgi.fix_pathinfo to 0 。
open php.ini:
sudo nano /usr/local/php/php.ini
find cgi.fix_pathinfo= and change it to 0
cgi.fix_pathinfo=0
-
before you start php server ,need to editphp-fpm.conf file ,check php-fpm module use www-data user and www-data user group to run it,
sudo nano /usr/local/etc/php-fpm.conf
change as below:
; Unix user/group of processes
; Note: The user is mandatory. If the groupis not set, the default user's group
; will be used.
user = www-data
group = www-data
-
start php-fpm server :
./usr/local/bin/php-fpm
-
add php start when boot OS
edit rc.local
sudo nano /etc/rc.local
at exit 0 add below
sudo php-fpm &
change nginx configuration
-
change main page and php configuration
sudo nano/etc/nginx/sites-available/default
find index line ,add index.php, as below:
index index.php index.html index.htm
find php define line, change it as below:
location ~* .php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
-
reboot nginx
sudo nginx -s stop
sudo nginx
-
create a test page:
sudo nano /home/pi/www/index.php
input
<? phpinfo(); ?>
save
- open brower ,and input :127.0.0.1
so all is working fine.