step 1 租用阿里云服務(wù)器
先從阿里云租用ECS主機(jī)棘利,配置凄鼻,我選擇的配置是:
系統(tǒng):CentOS 6.8 64bit
CPU: 1核
內(nèi)存: 1024 MB
帶寬:1Mbps
step 2 登錄服務(wù)器
配置好之后系統(tǒng)之后,通過(guò)SecureCRT遠(yuǎn)程登錄到系統(tǒng),開(kāi)始進(jìn)行我們的環(huán)境搭建,我搭建的是LNMP(Linux,Nginx蛾狗,Mysql,PHP 7)
本文全部采用yum安裝仪媒。
step 3 安裝Nginx
修改yum源
進(jìn)入 /etc/yum.repos.d/目錄沉桌,創(chuàng)建一個(gè)nginx.repo文件
[root@castarwang ~] # cd /etc/yum.repos.d/
[root@castarwang yum.repos.d] # vim nginx.repo
寫入源內(nèi)容到nginx.repo文件:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
保存:
按Esc一下,輸入
:wq
回車即可算吩。
在系統(tǒng)根目錄下輸入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
打開(kāi)nginx開(kāi)機(jī)自啟動(dòng):
[root@castarwang ~] # chkconfig nginx on
查看開(kāi)機(jī)自啟動(dòng)服務(wù)項(xiàng):
[root@castarwang ~] # chkconfig --list
...
nginx? ? 0:off? 1:off? 2:on? 3:on? 4:on? 5:on? 6:off
...
PS:nginx的配置文件默認(rèn)在/etc/nginx/conf.d/default.conf
step 4 安裝mysql
更新及安裝mysql yum源:
官網(wǎng)下載源碼包: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
打開(kāi)mysql-community.repo看到關(guān)于mysql的內(nèi)容:
[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編輯器。
執(zhí)行安裝mysql命令:
[root@castarwang ~] # yum install mysql-community-server
確認(rèn)好版本沒(méi)問(wèn)題压昼,是mysql57求冷。當(dāng)界面提示,是否按‘y’時(shí)窍霞,按‘y’回車安裝即可匠题。完成安裝后啟動(dòng)服務(wù):
[root@castarwang ~] # service mysqld start
啟動(dòng)后,查看安裝自動(dòng)生成的密碼:
[root@castarwang ~] # grep "password" /var/log/mysqld.log
輸入命令后但金,第一行就是我們的mysql的root密碼了韭山,此處省略圖示。
修改初始化密碼
[root@castarwang ~] # mysql_secure_installation
輸入命令后冷溃,根據(jù)提示钱磅,首先輸入初始密碼,如果沒(méi)有初始密碼似枕,則回車续搀。
接著,輸入新密碼菠净,再輸入一次,回車彪杉。
登錄驗(yàn)證下剛剛修改的密碼是否可用:
[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的配置文件默認(rèn)在/etc/my.cnf
打開(kāi)mysql自啟動(dòng):
[root@castarwang ~] # chkconfig mysqld on
step 5 安裝PHP 7
如果之前安裝過(guò)php的話毅往,要先清理下,在根目錄輸入命令如下:
[root@castarwang ~] # yum remove php* php-common
與上面安裝nginx派近,mysql的方式一樣攀唯,先更新yum源,然后再安裝yum源渴丸,依次在系統(tǒng)根目錄下輸入以下命令:
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進(jìn)行安裝吠谢。
[root@castarwang ~] # yum list php
yum安裝php 7及其擴(kuò)展:
[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查看版本及安裝的擴(kuò)展诗茎。
php的配置文件一般在/etc/php.ini文件中工坊。
簡(jiǎn)單的修改一些配置,如下:
[root@castarwang ~] # vim /etc/php.ini
date.timezone = Asia/Shanghai
upload_max_filesize = 20M
post_max_size = 20M
display_errors = Off // 生產(chǎn)環(huán)境ban掉就好了
# 使HTTP Header中不顯示PHP信息把
expose_php = On
修改為
expose_php = Off
重啟php
[root@castarwang ~] # service php-fpm restart
打開(kāi)PHP自啟動(dòng):
[root@castarwang ~] # chkconfig php-fpm on
step 6 配置Nginx與PHP
安裝好nginx之后敢订,nginx默認(rèn)的網(wǎng)站根目錄應(yīng)該是在 /usr/share/nginx/html/
虛擬主機(jī)的配制在 /etc/nginx/conf.d 如果要配制新的域名在這里就可以了王污。
默認(rèn)有一個(gè)default.conf的配置文件,可以直接在這個(gè)文件上進(jìn)行修改楚午。
[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;
? ? #配置網(wǎng)頁(yè)目錄昭齐,如果沒(méi)有/var/www目錄,請(qǐng)新建
? ? root? ? /var/www/qadoor/public;
? ? #配置默認(rèn)首頁(yè)
? ? 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
? ? #
? ? # 配置解析規(guī)則
? ? 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服務(wù):
[root@castarwang ~] # service nginx restart
本文由CastarWang根據(jù)勤奮的小青蛙的【整理】【1】阿里云CentOS 6.5下Laravel部署(LNMP)修正部分內(nèi)容阱驾,轉(zhuǎn)載和引用遵循知識(shí)共享署名-非商業(yè)性使用 2.5 中國(guó)進(jìn)行許可。