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 中国进行许可。
网友评论