LNMP平台搭建与配置 » 荒野无灯weblog

Keep It Simple, Stupid.

荒野无灯weblog

LNMP平台搭建与配置

apt-get install mysql-server
apt-get install php5
apt-get install php5-mcrypt
apt-get install php5-mysql
apt-get install  php5-xdebug
apt-get install php5-cgi
apt-get install nginx
[email protected]:/etc/nginx/sites-available# service nginx restart
Restarting nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
configuration file /etc/nginx/nginx.conf test is successful
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: still could not bind()
nginx.
lsof -i tcp:80
[email protected]:/etc/nginx/sites-available# lsof -i tcp:80
COMMAND  PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
apache2  921     root    3u  IPv4   4548      0t0  TCP *:www (LISTEN)
apache2 4349 www-data    3u  IPv4   4548      0t0  TCP *:www (LISTEN)
apache2 4350 www-data    3u  IPv4   4548      0t0  TCP *:www (LISTEN)
apache2 4351 www-data    3u  IPv4   4548      0t0  TCP *:www (LISTEN)
apache2 4352 www-data    3u  IPv4   4548      0t0  TCP *:www (LISTEN)
apache2 4353 www-data    3u  IPv4   4548      0t0  TCP *:www (LISTEN)
apache2 4429 www-data    3u  IPv4   4548      0t0  TCP *:www (LISTEN)

发现80端口被 apache2占用,卸载之:

/etc/init.d/apache2 stop
apt-get remove apache2

如果不能卸载,那就先装一下,再卸载。

默认站点配置:

[email protected]:/etc/nginx/sites-available# cat default
# You may add here your
# server {
#       ...
# }
# statements for each of your virtual hosts

server {
        listen   80 default;
        server_name  localhost;

        access_log  /var/log/nginx/localhost.access.log;

        location / {
                root   /var/www/nginx-default;
                index  index.html index.htm;
        }

        location /doc {
                root   /usr/share;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }

        location /images {
                root   /usr/share;
                autoindex on;
        }

        error_page  404  /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   /var/www/nginx-default;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
                #proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /var/www/nginx-default/$fastcgi_script_name;
                include fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny  all;
        }
}

注意如果 fastcgi_param SCRIPT_FILENAME 不正确,访问PHP文件时会提示:No input file specified.

service nginx restart
php-cgi -b 127.0.0.1:9000 &

参考:http://www.howtoforge.com/installing-php-5.3-nginx-and-php-fpm-on-ubuntu-debian

http://interfacelab.com/nginx-php-fpm-apc-awesome/

http://www.softwareprojects.com/resources/programming/t-how-to-install-php-fpm-spawn-fcgi-replacement-1602.html

http://wiki.nginx.org/Nginx-init-ubuntu

http://till.klampaeckel.de/blog/archives/51-Ubuntu-nginx+php-cgi-on-a-socket.html

Tagged in : MySQL,PHP,Linux,lnmp,nginx

All Comments (0)
Gravatar image
No Comments