centos7.3安装php nginx mysql

nginx

安装

yum install nginx

启动

systemctl start nginx

其他命令

systemctl stop nginxsystemctl restart nginxsystemctl status nginx

测试

输入IP


image.png

配置

编辑/etc/nginx/nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.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;
            include fastcgi_params;
        }
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # 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 {
#        }
#    }

}


PHP

安装

yum install php php-mysql php-fpm

配置PHP.ini

vim /etc/php.ini

把 cgi.fix_pathinfo=1 改为 cgi.fix_pathinfo=0

配置PHP-FPM

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


user = nobody
group = nobody

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

groupadd -r nginx
useradd -r -g nginx nginx

启动

systemctl start php-fpm

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

内容如下:

<?php phpinfo();?>

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

浏览器上输入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

推荐阅读更多精彩内容