阿里云CentOS 6.8下安装LNMP

step 1 租用阿里云服务器

先从阿里云租用ECS主机,配置,我选择的配置是:

系统:CentOS 6.8 64bit

CPU: 1核

内存: 1024 MB

带宽:1Mbps

step 2 登录服务器

配置好之后系统之后,通过SecureCRT远程登录到系统,开始进行我们的环境搭建,我搭建的是LNMP(Linux,Nginx,Mysql,PHP 7)

本文全部采用yum安装。

step 3 安装Nginx

修改yum源

进入 /etc/yum.repos.d/目录,创建一个nginx.repo文件

[root@castarwang ~] # cd /etc/yum.repos.d/

[root@castarwang yum.repos.d] # vim nginx.repo

写入源内容到nginx.repo文件:

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

gpgcheck=0

enabled=1

保存:

按Esc一下,输入

:wq

回车即可。

在系统根目录下输入yum update,更新yum源:

[root@castarwang yum.repos.d] # cd ~

[root@castarwang ~] # yum update

使用yum安装nginx,输入命令如下:

[root@castarwang ~] # yum install nginx -y

安装好之后查看版本:

[root@castarwang ~] # nginx -v

nginx version: nginx/1.10.3

打开nginx开机自启动:

[root@castarwang ~] # chkconfig nginx on

查看开机自启动服务项:

[root@castarwang ~] # chkconfig --list

...

nginx    0:off  1:off  2:on  3:on  4:on  5:on  6:off

...

PS:nginx的配置文件默认在/etc/nginx/conf.d/default.conf

step 4 安装mysql

更新及安装mysql yum源:

官网下载源码包:http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm

[root@castarwang ~] # wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm

rpm安装mysql5.7:

[root@castarwang ~] # rpm -Uvh mysql57-community-release-el6-7.noarch.rpm

打开mysql-community.repo看到关于mysql的内容:

[root@castarwang ~] # vim /etc/yum.repos.d/mysql-community.repo

找到[mysql57],确定[mysql57]的enable是1,图示如下:

[mysql-connectors-community]

name=MySQL Connectors Community

baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/6/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]

name=MySQL Tools Community

baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/6/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.5

[mysql55-community]

name=MySQL 5.5 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.6

[mysql56-community]

name=MySQL 5.6 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.7

[mysql57-community]

name=MySQL 5.7 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

~

~

~

~

~

~

~

"/etc/yum.repos.d/mysql-community.repo" 36L, 1033C 

退出vim编辑器。

执行安装mysql命令:

[root@castarwang ~] # yum install mysql-community-server

确认好版本没问题,是mysql57。当界面提示,是否按‘y’时,按‘y’回车安装即可。完成安装后启动服务:

[root@castarwang ~] # service mysqld start

启动后,查看安装自动生成的密码:

[root@castarwang ~] # grep "password" /var/log/mysqld.log

输入命令后,第一行就是我们的mysql的root密码了,此处省略图示。

修改初始化密码

[root@castarwang ~] # mysql_secure_installation

输入命令后,根据提示,首先输入初始密码,如果没有初始密码,则回车。

接着,输入新密码,再输入一次,回车。

登录验证下刚刚修改的密码是否可用:

[root@castarwang ~] # mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 177

Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

PS:要记住mysql的配置文件默认在/etc/my.cnf

打开mysql自启动:

[root@castarwang ~] # chkconfig mysqld on

step 5 安装PHP 7

如果之前安装过php的话,要先清理下,在根目录输入命令如下:

[root@castarwang ~] # yum remove php* php-common

与上面安装nginx,mysql的方式一样,先更新yum源,然后再安装yum源,依次在系统根目录下输入以下命令:

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

rpm -ivh epel-release-6-8.noarch.rpm

rpm -ivh remi-release-6.rpm

修改yum源:

[root@castarwang ~] # vim /etc/yum.repos.d/remi.repo

将[remi]段中的enabled=0改为enabled=1。

[root@castarwang ~] # vim /etc/yum.repos.d/remi-php70.repo

与remi.repo类似,将[remi-php70]段中的enabled=0改为enabled=1。

输入命令查看版本如果显示的是7.x的话就正常,也可以直接用yum install php70进行安装。

[root@castarwang ~] # yum list php

yum安装php 7及其扩展:

[root@castarwang ~] # yum install php php-fpm php-cli php-pdo php-mysql php-gd php-bcmath php-xml php-mbstring php-mcrypt php-redis

安装好之后 php -v,php -m查看版本及安装的扩展。

php的配置文件一般在/etc/php.ini文件中。

简单的修改一些配置,如下:

[root@castarwang ~] # vim /etc/php.ini

date.timezone = Asia/Shanghai

upload_max_filesize = 20M

post_max_size = 20M

display_errors = Off // 生产环境ban掉就好了

# 使HTTP Header中不显示PHP信息把

expose_php = On

修改为

expose_php = Off

重启php

[root@castarwang ~] # service php-fpm restart

打开PHP自启动:

[root@castarwang ~] # chkconfig php-fpm on

step 6 配置Nginx与PHP

安装好nginx之后,nginx默认的网站根目录应该是在 /usr/share/nginx/html/

虚拟主机的配制在 /etc/nginx/conf.d 如果要配制新的域名在这里就可以了。

默认有一个default.conf的配置文件,可以直接在这个文件上进行修改。

[root@castarwang ~] # vim /etc/nginx/conf.d/default.conf

server {

    listen      80;

    server_name  localhost;

    #charset koi8-r;

    #access_log  /var/log/nginx/log/host.access.log  main;

    #配置网页目录,如果没有/var/www目录,请新建

    root    /var/www/qadoor/public;

    #配置默认首页

    index  index.php index.html index.htm;

    #配置解析

    location / {

        try_files $uri $uri/ /index.php?$query_string;

    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html

    #

    error_page  500 502 503 504  /50x.html;

    location = /50x.html {

        root  /usr/share/nginx/html;

    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

    #

    #location ~ \.php$ {

    #    proxy_pass  http://127.0.0.1;

    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    # 配置解析规则

    location ~ \.php$ {

        try_files $uri /index.php =404;

        fastcgi_pass  127.0.0.1:9000;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include        fastcgi_params;

    }

    # deny access to .htaccess files, if Apache's document root

    # concurs with nginx's one

    #

    location ~ /\.ht {

        deny  all;

    }

}

配置完成之后,重启nginx服务:

[root@castarwang ~] # service nginx restart

本文由CastarWang根据勤奋的小青蛙【整理】【1】阿里云CentOS 6.5下Laravel部署(LNMP)修正部分内容,转载和引用遵循知识共享署名-非商业性使用 2.5 中国进行许可。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,560评论 4 361
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,104评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,297评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,869评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,275评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,563评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,833评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,543评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,245评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,512评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,011评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,359评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,006评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,062评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,825评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,590评论 2 273
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,501评论 2 268

推荐阅读更多精彩内容

  • 我都不知道自己在等待什么 我都不知道自己还能坚持多久 我都不知道这样的婚姻有何意义 我都不知道孩子大了会不会开心 ...
    寻爱cat阅读 167评论 0 0
  • 2018.1.16 默写陋室铭,爱莲说,钱塘湖春行,天净沙秋思,桃花源记,说明文两篇 2018.1.17 默写爱莲...
    小羴羊阅读 840评论 0 0
  • 最近一场感冒把我彻底搞垮了!同时也带给我无限大的价值!经历了一次神奇的体验! 故事从几天前赏月开始,连续三...
    莉丽_be50阅读 220评论 0 0
  • 今天我爸爸给我买了起泡胶。起泡胶里面有两个小瓶子,一个是蓝色的瓶子,一个是白色的小水杯。蓝色的水杯里,有一...
    45于淇阅读 4,328评论 0 1