阿里云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 中國進行許可。

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 我都不知道自己在等待什么 我都不知道自己還能堅持多久 我都不知道這樣的婚姻有何意義 我都不知道孩子大了會不會開心 ...
    尋愛cat閱讀 181評論 0 0
  • 2018.1.16 默寫陋室銘,愛蓮說,錢塘湖春行,天凈沙秋思,桃花源記,說明文兩篇 2018.1.17 默寫愛蓮...
    小羴羊閱讀 1,134評論 0 0
  • 最近一場感冒把我徹底搞垮了!同時也帶給我無限大的價值!經歷了一次神奇的體驗! 故事從幾天前賞月開始,連續三...
    莉麗_be50閱讀 237評論 0 0
  • 今天我爸爸給我買了起泡膠。起泡膠里面有兩個小瓶子,一個是藍色的瓶子,一個是白色的小水杯。藍色的水杯里,有一...
    45于淇閱讀 4,464評論 0 1