zoukankan      html  css  js  c++  java
  • CentOS7上安装并配置Nginx、PHP、MySql

    一、Nginx

     1、安装nginx

    yum install nginx

    2、启动nginx

    systemctl start nginx

    除了systemctl start nginx之外,常用的相关命令还有systemctl stop nginx、systemctl restart nginx、systemctl status nginx

    3、测试nginx是否安装成功

        浏览器输入ip地址或者域名(已经解析过的域名),如下图所示,则安装成功。

    4,配置Nginx支持PHP解析

         编辑/etc/nginx/nginx.conf,蓝色字体处为新加内容

     server {
            listen       80 default_server;
            listen       [::]:80 default_server;
            server_name  _;
            root         /usr/share/nginx/html;
            index index.php index.html index.htm;

            # Load configuration files for the default server block.
            include /etc/nginx/default.d/*.conf;

            location / {
            }

            error_page 404 /404.html;
                location = /40x.html {
            }

            error_page 500 502 503 504 /50x.html;
                location = /50x.html {
            }
            location ~ .php$ {
            try_files $uri =404;
            root /usr/share/nginx/html;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi.conf;
    }

    }

    二、PHP

    1,安装PHP

    yum install php php-mysql php-fpm

    安装过程中经常会见到如下问题:
    2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18()(64bit)
    2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18(libmysqlclient_18)(64bit)
    解决方法:
    把php-mysql换成php-mysqlnd
    即执行

    yum install php php-mysqlnd php-fpm

    2、编辑PHP的配置文件,/etc/php.ini,注意去掉分号注释

    vim /etc/php.ini

       将 ;cgi.fix_pathinfo=1 改为 cgi.fix_pathinfo=0

    3、编辑PHP-FPM配置文件

    vim /etc/php-fpm.d/www.conf

     将
     user = nobody
     group = nobody   

     改为
     user = nginx
     group = nginx
     前提是已经创建了nginx用户和nginx组。如果没有创建方法:

    1 groupadd -r nginx
    2 useradd -r -g nginx nginx

    4、启动PHP—FPM

    systemctl start php-fpm

    5、设置开机启动

    systemctl enable php-fpm

    6,确保Nginx配置文件修该之后,重启Nginx

    systemctl restart nginx

    7、在/usr/share/nginx/html/目录下创建phpinfo.php

        内容如下:

       <?php phpinfo();?>

       查看php进程:ps aux | grep php  查看端口占用:netstat -ano|grep 80

    8、浏览器上输入ip/phpinfo.php,如果出现如下界面,说明PHP和Nginx均安装和配置成功。

         

     三、MySql

    CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载

    1、补充yum源(1)

    wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

    2、补充yum源(2)

    rpm -ivh mysql-community-release-el7-5.noarch.rpm

    3、安装mysql

    yum install mysql-community-server

    4、成功安装之后重启mysql服务

    systemctl start mysqld

    初次安装mysql是root账户是没有密码的
    设置密码的方法

    1 mysql -uroot
    2 mysql> set password for ‘root’@‘localhost’ = password('mypasswd');
    3 mysql> exit

    mysql -u root -p

    输入密码之后,错误提示如下:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES),意思是root的密码不正确。

    解决办法如下:
    a.sudo mysqld_safe --user=root --skip-grant-tables --skip-networking &
    输入命令之后,如果提示信息为:
    mysqld_safe A mysqld process already exists
     
    表示mysqld_safe进程存在,可以通过
    ps -A|grep mysql 查看mysqld_safe进程ID
    kill -9 -xxxx            终结ID为xxxx的进程

    问题:以上安装之后 nginx并不解析 php文件的原因
     

    nginx安装完成后,修改nginx配置文件为,nginx.conf

    其中server段增加如下配置,注意标红内容配置,否则会出现No input file specified.错误

    # 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 $document_root$fastcgi_script_name;
    include fastcgi_params;
    }

    当时就是默认nginx里的配置与上面的红色有些出入,导致不能正常解析php文件。请注意红色加粗的部份。

    网上有很多帖子都不靠谱,后来找到一个靠谱的答案,已解决:http://blog.sina.com.cn/s/blog_6fcb75890102w8xm.html
     
     转自:https://www.cnblogs.com/peteremperor/p/6740725.html
  • 相关阅读:
    遗传算法(Genetic Algorithm, GA)及MATLAB实现
    CCF CSP 201809-2 买菜
    PAT (Basic Level) Practice (中文)1008 数组元素循环右移问题 (20 分)
    PAT (Basic Level) Practice (中文)1006 换个格式输出整数 (15 分)
    PAT (Basic Level) Practice (中文)1004 成绩排名 (20 分)
    PAT (Basic Level) Practice (中文)1002 写出这个数 (20 分)
    PAT (Advanced Level) Practice 1001 A+B Format (20 分)
    BP神经网络(原理及MATLAB实现)
    问题 1676: 算法2-8~2-11:链表的基本操作
    问题 1744: 畅通工程 (并查集)
  • 原文地址:https://www.cnblogs.com/rickzhai/p/9349901.html
Copyright © 2011-2022 走看看