linux nginx php mysql

作者陈永鹏的csdn博客地址:http://blog.csdn.net/chenyoper

作者陈永鹏的博客园地址:http://www.cnblogs.com/Yoperchen/

作者陈永鹏的零零糖地址:http://www.linglingtang.com/index.php?s=User/Index/index&user_id=1



主要有三点:

安装nginx/安装php/安装mysql/整合nginx和php-fpm


【nginx】

yum -y install nginx

完成之后

service nginx start

我第一次报错

Starting nginx: nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)
[FAILED]

解决办法:
vim /etc/nginx/conf.d/default.conf

service nginx start

返回

Starting nginx: [  OK  ]


现在就可以通过ip测试访问了,如无意外是nginx的默认页面


【mysql】

yum install mysql mysql-server mysql-devel -y

完成之后

service mysqld start


设置mysql root密码

设置新的密码并同时授权限
mysql> grant all on *.* to root@'%' identified by 'youpassword';
刷新使之生效
mysql> flush privileges;
退出
mysql> exit;


修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'



[php]

下载php

解压php

进入php目录

./configure --prefix=/usr/local/php-5.4.4 --enable-fpm

make && make install

cp php.ini-production  /usr/local/php-5.4.3/lib/php.ini

启动php-fpm

/usr/local/php5.4.3/sbin/php-fpm 


nginx和php-fpm整合

cd /etc/nginx/conf.d

vim default.conf


加上如下(假设项目目录是myproject):

server {
    listen       80;
    server_name *.test.com;


    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;


    location / {
        root  /usr/share/nginx/html/myproject;
        index index.php index.html index.htm;
    }


    #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   /usr/share/nginx/html;
    }


    # 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$ {
        root           /usr/share/nginx/html/myproject;
        fastcgi_pass   127.0.0.1:9054;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$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;
    }
    #deny file type
    location ~* \.(html|ini|docx|txt|doc|log|pem|pfx|cer)$ {
        deny  all;
    }
}


完美











零零糖







猜你喜欢

转载自blog.csdn.net/yoperman/article/details/78313999