Im continue create my super-amazing-web-GIS-application. I have a weak hardware so i have choice between 2 server side languages php and node.js. With php i can work now and there but for using node.js i have to read tons of books and miles of forums. So i have php i choose you!
1. Installing.
In previous part we already install nginx and fastCGI. So now we need only php. I will make php+fastCGI not php+php-rgm just becouse im already have fastcgi. If someone will write in comments why i have to use php-rgm i will glad.
Install php:
apt-get install php5 nginx php5-cgi
I was not install mySQL becouse i will use PostgreSQL+PostGIS for spatial data.
2. FastCGI configuration.
Create file /usr/bin/php-fastcgi and put into:
#! /bin/sh PHP_FCGI_CHILDREN=3 PHP_FCGI_MAX_REQUESTS=1000 exec /usr/bin/php5-cgi
Create file /etc/init.d/init-fastcgi and put into:
#!/bin/bash
PHP_SCRIPT="/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php-fastcgi"
RETVAL=0
case "$1" in
start)
$PHP_SCRIPT
RETVAL=$?
;;
stop)
killall -9 php5-cgi
RETVAL=$?
;;
restart)
killall -9 php5-cgi
$PHP_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: sudo /etc/init.d/init-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
Make files executable:
chmod 755 /usr/bin/php-fastcgi chmod 755 /etc/init.d/init-fastcgi3. nginx configuration.
You can create new file /etc/nginx/sites-enabled/your-file-name for server configuration:
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
root /srv/www/localhost/public_html;
access_log /srv/www/localhost/logs/access.log;
error_log /srv/www/localhost/logs/error.log;
#index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
location ~\.php$ {
root /srv/www/localhost/public_html;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param SCRIPT_FILENAME /srv/www/localhost/public_html$fastcgi_script_name;
}
}
But i use default file so i just add:
location ~\.php$ {
root /srv/www/localhost/public_html;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param SCRIPT_FILENAME /srv/www/localhost/public_html$fastcgi_script_name;
}
into /etc/nginx/sites-enabled/default.
4. Site directory.
Its all with configurations. Now you can start FastCGI script:
Now we need to create directory for our site and log directory:
/srv/www/localhost/public_html /srv/www/localhost/logs
In public_html keeped all site content.
5. Results.
Its all with configurations. Now you can start FastCGI script:
sudo /etc/init.d/init-fastcgi start
And start nginx:
/etc/init.d/nginx start
Create file test.php in our site directory with:
Go to the localhost/test.php and if you do all right you'll see standart phpinfo() output:
Its mean that php+nginx work fine.
In my case i get a 404 error becouse nginx tried to find test.php in standart nginx directory /var/www. Restart of nginx and fastcgi not help me, i was forced to reboot machine. But after all work fine.
Another problem was with permissions. So dont forget set to site directory:
sudo chmod -R 755 /srv/www/localhost/public_html6. Enable PostgreSQL.
Its all nice but i will need PostgreSQL support in php. Now we need to install PostgreSQL module.
sudo apt-get install php5-pgsql
Restart fastCGI
sudo /etc/init.d/init-fastcgi restart
And go to localhost/test.php again to make sure that PostgreSQL enabled. You gonna see that part:
Its mean all works fine.

Комментариев нет:
Отправить комментарий