欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

阿里云CentOS7下部署Nginx,MySQL,PHP7环境

程序员文章站 2022-07-13 21:23:52
...

1、准备

  1. 更新

sudo yum update

  1. 安装 wget

sudo yum install wget

2、安装Nginx

阿里云默认使用了自己的镜像源。
不是阿里云需要下载对应当前系统版本的nginx包
建立nginx的yum仓库(默认yum是没有nginx的)
复制代码

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

sudo rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

开始安装Nginx

sudo yum install -y nginx

Nginx启动

sudo systemctl start nginx

3、安装php

  1. rpm 安装 Php7 相应的 yum源

sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

  1. 安装

sudo yum install -y php70w

  1. 安装php扩展(部分)

sudo yum install -y php70w-mysql.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64

  1. 安装PHP FPM

sudo yum install -y php70w-fpm

  1. 启动PHP FPM

sudo systemctl start php-fpm

  1. 查看启动状态:

systemctl status php-fpm

4、安装MySQL

  1. 下载mysql的repo源

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

  1. 安装mysql-community-release-el7-5.noarch.rpm包

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

  1. 安装MYSQL

sudo yum install -y mysql-server

  1. 更改MYSQL用户权限:

sudo chown -R root:root /var/lib/mysql

  1. 重启服务:

sudo systemctl restart mysql

  1. 登录,并修改密码:

mysql -u root

mysql > use mysql;

mysql > update user set password=password('password') where user='root';

mysql > flush privileges;

mysql > exit;

  1. 远程链接

mysql -u root -p

mysql > use mysql;

mysql > grant all privileges on *.* to [email protected]'%' identified by 'password' with grant option;

mysql >flush privileges

5、虚拟主机配置

拷贝一份默认配置。参考下面的server

cp nginx.conf /conf.d xxx.cong

server{
        listen 80;
        root /usr/share/nginx/html;
        index index.html index.php index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        #gzip_http_version 1.0;
        gzip_comp_level 5;
        gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary off;
        gzip_disable "MSIE [1-6]\.";


        charset UTF-8;

        location ~* .(jpg|jpeg|png|gif|css|js|swf|mp3|avi|flv|xml|zip|rar)$ {
                gzip on;
        }

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ .php {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
                include fastcgi_params;
        }
}
复制代码

重启Ngix和php-fpm、配置完毕。

转载于:https://juejin.im/post/5b20de5df265da6e5635ca05