我准备把之前做的www.dy360.net重新搞起来,就在vultr上买了vps,于是乎有了下面这篇文章。
在vps上系统是Centos6.9,至于为什么使用Centos,那是因为我个人比较熟悉Centos!
yum安装Nginx
1.执行下面的yum命令安装Nginx
1 | yum install nginx |
如果上面命令没有执行成功,说明系统中yum源中没有Nginx的源,因此我们需要手动添加Nginx的源,步骤如下:
1 | vi /etc/yum.repos.d/nginx.repo |
2.启动Nginx
1 | service nginx start |
现在Nginx已经启动了,直接访问服务器就能看到Nginx欢迎页面了的。如果还无法访问,则需配置一下Linux防火墙。
3.配置防火墙,开放80端口
1 | vim /etc/sysconfig/iptables |
注意:如果是阿里云的ecs,你可能需要在阿里云的主机管理后台,添加安全组规则,方可开启80端口
4.设置开机启动
1 | chkconfig --list | grep nginx |
END:Nginx安装配置完成
yum 安装MySQL5.6
参考:
https://www.cnblogs.com/007sx/p/7083143.html
1.检查系统是否安装其他版本的MYSQL数据
1 | yum list installed | grep mysql |
2.配置MySQL源
1 | wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm |
3.安装MYSQL数据库
1
yum install mysql-community-server -y
4.设置为开机启动(2、3、4都是on代表开机自动启动)
1
2chkconfig --list | grep mysqld
chkconfig mysqld on
5.启动mysql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 service mysqld start
# 显示如图(部分)
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h vultr password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
Note: new default config file not created.
Please make sure your config file is current
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
[ OK ]
Starting mysqld: [ OK ]
6.设置mysql密码
1 | /usr/bin/mysqladmin -u root password 'xxxxx' |
安全处理,看不懂英文直接一路yes就行
1
/usr/bin/mysql_secure_installation
[注意]2017/12/24更新:
1 | 今日安装MySQL执行上面的命令的时候出现下面的话 |
7.设置utf-8编码
1 | 查看mysql原本编码: |
编辑mysql的配置文件/etc/my.cnf
1 | vi /etc/my.cnf |
END:到此MySQL安装配置成功
编译安装PHP7.0.26
参考:
1.安装PHP支持库
1 | yum install gcc gcc-c++ libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel php-mcrypt |
####
2.下载PHP7.0.26源码包
1 | wget http://sg2.php.net/distributions/php-7.0.26.tar.gz |
3.编译安装PHP
1 | ./configure \ |
编译报下面的错误
1 | checking for stdarg.h... (cached) yes |
执行下面的命令安装libmcrypet
1 | yum install libmcrypt-devel -y |
若上面的方法解决不了,可以编译安装libmcrypet
1 | cd /usr/local/src |
上面的方法要是还是不行,那用下面的方法:
1 | 安装第三方yum源 |
4.最后执行下面的命令,完成PHP的安装
1 | make |
5.配置PHP-FPM
增加用户&用户组
1
2groupadd www
useradd -g www www拷贝php-fpm.conf文件
1
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
拷贝php-fpm include文件
1
cp usr/local/php/etc/php-fpm.d/www.conf.default www.conf
从源码包里拷贝php.ini
1
cp /usr/local/src/php-7.0.26/php.ini-production /usr/local/php/etc/php.ini
6.将PHP加入环境变量
1 | vi /etc/profile |
7.php-fpm自启动
- 从源码包里拷贝启动脚本
1
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
- 加入系统启动项
1
chkconfig php-fpm on
8.重启PHP
1 | service php-fpm restart |
END:PHP安装配置完成
编译安装git
参考:
http://www.cnblogs.com/fazo/p/5578644.html
1.安装依赖的包
1 | yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker |
2.下载源码包
1 | wget https://github.com/git/git/archive/v2.9.0.zip |
3.编译安装
1 | make prefix=/usr/local/git all |
4.加入系统变量
1 | vi /etc/profile |
5.配置git
1 | git config --global user.name 'vultr' |
6.生成ssh密钥,执行下面的命令,一路回车即可,即可用密钥克隆项目。
1 | ssh-keygen -t rsa -C 'vultr@dy360.net' |
END:git安装配置成功
最后,终于环境搭建好了!自己搭建lnmp环境少说也有十几次了,可是每次都有新感觉!因为每次出现的问题,都不太一样!最近两次都出现了Nginx安装后,通过ip不能访问的问题,结果发现都是防火墙的问题,没有开启80端口。坑的要命!