阿里云 ESC ubuntu nginx +php+mysql 配置 (踩坑吐血推荐)

背景:使用阿里云服务器 ubuntu 16.04,mysql5.7 +php 7.0;

前言 : 若果想在本地使用 图形化工具 来访问你的服务器  或者外网去访问你的服务起 首先要先配置 阿里云安全组

其中80 为服务器 默认端口   3306为mysql 默认端口 配置好了 就正式开始了

一  安装任何软件之前先更新 源

   sudo apt-get update

二  安装nginx

   sudo apt install nginx

三  安装php7.0

   sudo apt install php7.0

四 安装php7.0-fpm,这是php和nginx之间的连接器。

   sudo apt install php7.0-fpm

五  安装php7.0-dev和php7.0-mysql

   sudo apt install php7.0-dev

   sudo apt install php7.0-mysql

六 安装正则表达式库pcre(根据个人需求)

   sudo apt install libpcre32-3

七 装过这些软件之后   打开/etc/nginx/sites-enabled/default文件进行配置 可参考如下代码(复制即可 但注意更改自己的域名)

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    #root为项目代码所在目录
    #index在中间添加index.php
    root /var/www/html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    #填写购买的阿里云外网IP或者自己已经解析备案的域名
    server_name 这里写自己的域名 没有的话写服务器公网ip;

    #更改未被注释一行
    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php?$query_string;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }
    #添加下面代码
        location ~ \.php$ {
               try_files $uri /index.php =404;
               fastcgi_split_path_info ^(.+\.php)(/.+)$;
               fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
               fastcgi_index index.php;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include fastcgi_params;
        }
}

  八 启动这两个进程:

  service nginx start

  service php7.0-fpm start

在根目录/var/www/html下添加一个index.php文件,打开浏览器,访问:你的域名或者 服务器公网IP,即可成功。测试php 已经配好了

九 mysql配置

1、root权限安装MySQL

sudo apt-get install mysql-server

期间会让你输入root的密码

2、登录MySQL并更改用户授权

登录:mysql -u root -p

输入root密码后,进入MySQL

use mysql;

update user set host='%' where user='root';

grant all privileges on  *.* TO '这里是名称  (我写的是root)'@'%' identified by '这里是密码' WITH GRANT OPTION;

注意这里的 % 是允许所有访问

FLUSH PRIVILEGES;

执行

select host,user from user;

去查看 是否创建成功

如图所示 创建成功

3、修改本地访问的3306

 在这个文件夹下 /etc/mysql/mysql.conf.d/mysqld.cnf,注释bindaddress=127.0.0.1这行代码

4、重启MySQL

service mysql restart

5、navicat或者其他客户端重新连接

猜你喜欢

转载自blog.csdn.net/primedream_RYH/article/details/81096848