在fedora中配置LNMP(linux + nginx + mysql +php)

我的环境

1.fedora 22

2.linux 64位

开始之前,可以用以下命令先查看是否已安装,mysql,nginx,php

which nginx           #查看nginx是否存在

which php             #查看php是否存在

which mysql          #查看mysql是否存在

一.安装

     第一步:安装nginx

             1.在Fedora( linux )终端键入yum install nginx 下载并安装nginx
             2.创建nginx启动链接并启动nginx
             3.systemctl enable nginx.service    //创建启动链接
             4.systemctl start nginx.service //启动nginx

             5.cp /etc/nginx/nginx.conf    nginx_2016_08_09.conf //先备份默认配置

             6.vim  /etc/nginx/nginx.conf 修改以下内容(只贴出有改的代码的相关部分):

user  nginx;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;
    access_log   /var/log/nginx/access.log main;//自己电脑中放置nginx的log的位置,没有的话就在/var/log/nginx中新建
    error_log    /var/log/nginx/error.log;//自己电脑中放置nginx的log的位置,没有的话就在/var/log/nginx中新建

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    server {
        listen       80;
        server_name  localhost;
        root /var/www/html;//自己项目的位置

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
                                                                                                                                                                                         1,0-1        顶端
        location / {
            root   html;
            index  index.html index.htm;
        }

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }


        #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   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           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$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;
        #}
    }
}

注:vim (1):wq  #保存     (2) i  #插入    (3):q! #不保存退出

在浏览器查看nginx的欢迎界面http://localhost  //有的话就成功了

      第二步

               1.安装PHP需要安装一些列的模块,输入命令安装:

               yum install php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xm

               2.然后打开/etc/php.ini并设定cgi.fix_pathinfo=0(避免pathinfo漏洞)

               3.php.ini 中找到 date.timezone修改未date.timezone = PRC,PRC,People’s Republic of China,中华人民共和国,也就是                 日期使用中国的时区。

      第三步:安装MySQL

      从Fedora 19以后,Fedora将mysql 替换成了mariadb,我之前不知道装了mysql结果无法使用,最后改装mariadb,再启用mysql就可以了;

              1.   yum  install  mariadb (安装mariadb)

              2. netstat -tump|grep 3306  (查看3306端口是被哪个服务使用着)

              3.systemctl start mariadb.service   (打开数据库)
      接下来设置密码:mysql_secure_installation 按提示进行设置。
      登陆MySQL,mysql -u root -p
      输入密码后,可以show databases查看数据库

二.测试

       在/var/www/html新建一个index.php,写入如下代码
       <?php
          phpinfo();
        ?>
在浏览器中输入http://localhost,出现PHP的相关信息。
三.根据不同的项目配置nginx

     在/etc/nginx/下新建一个vhosts放置自己需要的项目的配置,比如wordpress项目,就新建一个wordpress.conf,写入相关配置,至于如何配置这里不多说;

     在/etc/nginx/nginx.conf  中有一句 include vhosts/*.conf; 会自动加载你的配置

     注:

      systemctl   start  nginx.service  //启动nginx

      systemctl   restart  nginx.service  //重启nginx

      systemctl  start php-ftm.service  //启动php-ftm

      systemctl  restart php-ftm.service  //重启php-ftm

      systemctl  start  mariadb.service  //启动mariadb

       systemctl  restart  mariadb.service  //重启mariadb



        

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值