阿里云 LNMP 环境配置

1) Nginx

// 使用yum安装Apache服务器
yum install nginx

// 修改为 listen 80;
vim /etc/nginx/conf.d/default.conf

// 查看nginx状态
nginx -t

// 启动nginx服务
service nginx start

// 配置 nginx 虚拟主机,注意,域名需要备案才能使用;
vim /etc/nginx/conf.d/your-domain.conf

server {
    listen 80;
    server_name  your-domain;
    root         /var/www/html;

    access_log /var/log/nginx/your-domain_access.log;
    error_log /var/log/nginx/your-domain_error.log;

    index  index.php index.html index.htm;

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

    location / {
        autoindex on;
    }

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

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

// 服务重启
service nginx reload

// 设置开机自动启动
chkconfig nginx on

因为阿里云默认不允许公网通过 HTTP、HTTPS 等服务,因此还需要在安全组那边进行配置;详见:应用案例

1. 登录 云服务器管理控制台。
2. 找到要配置的实例。
3. 打开实例的 本实例安全组,然后单击 配置规则。
4. 单击 公网入方向,然后单击 快速创建规则。
5. 添加安全组规则如下:
网卡类型:如果是经典网络,选择 公网。如果是 VPC 网络,不需要选择。
规则方向:入方向。
授权策略:允许。
协议类型 和 端口范围:选择 HTTP 服务的 TCP 80 端口,HTTPS 的 443 端口,或者自定义 TCP 8080 端口(如图所示)。
授权对象:0.0.0.0/0,表示允许所有地址访问。
优先级:1,表示安全规则中优先级最高,数字越小优先级越高。

到这里,就可以通过IP访问Nginx了;


2) PHP

// 追加remi源
rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

// 安装php56
yum install --enablerepo=remi --enablerepo=remi-php56 php php-bcmath php-cli php-common php-devel php-fpm php-gd php-imap php-ldap php-mbstring php-mcrypt php-pecl-apc php-mysqlnd php-mysql php-odbc php-pdo php-gd php-mcrypt php-pear php-pecl-igbinary php-xml php-xmlrpc

// 启动php
service php-fpm start
service php-fpm restart
service php-fpm status

// 设置开机自动启动 
chkconfig php-fpm on

// 编辑测试页面index.php,然后访问IP,即可看到页面效果;
vim /var/www/html/index.php
<?php
phpinfo();

记住,nginx的域名配置如果没有下面的内容(就是说,碰到.php结尾的文件,传递给后方127.0.0.1的9000端口上),会导致nginx无法解析PHP文件

location ~ .*\.php$ {
    fastcgi_pass   127.0.0.1:9000;
}

3) MySQL

// 安装mysql
yum -y install mysql-server

// 启动MySql服务
service mysqld start
service mysqld restart

// 设置开机启动
chkconfig mysqld on

// 接下来设置mysql密码
mysql_secure_installation

// 默认密码为空,直接回车,直到
Set root password? [Y/n] 
// 输入 y 回车
// 然后输入两次新密码
// 然后会有一堆问题,全部 y 回车
// OK 后重启mysql服务
service mysqld restart

// 输入刚刚设置的密码 回车 进入mysql 控制台,刷新一下权限
mysql -u root -p
flush privileges;

// 如果需要远程该数据库,有两种方法,一种是改表法,另外一种是授权法,此处我选择改表;
// 这里把localhost这条记录的host改为 %; 意思是root可以由任何主机登录mysql,网上很多写法,都没有and host='localhost'这个条件,经常报错。
use mysql;
update user set host='%' where user='root' and host='localhost';
select host, user from user;

exit;

参考:

阿里云配置mysql navcat远程连接
阿里云上安装mysql步骤/ 阿里云ECS搭建Java+mysql+tomcat环境

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值