Centos6.9上搭建lnmp环境

我准备把之前做的www.dy360.net重新搞起来,就在vultr上买了vps,于是乎有了下面这篇文章。
在vps上系统是Centos6.9,至于为什么使用Centos,那是因为我个人比较熟悉Centos!

yum安装Nginx

1.执行下面的yum命令安装Nginx

yum install nginx

如果上面命令没有执行成功,说明系统中yum源中没有Nginx的源,因此我们需要手动添加Nginx的源,步骤如下:

vi /etc/yum.repos.d/nginx.repo
输入一下内容:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/6/$basearch/
gpgcheck=0
enabled=1

保存之后执行下面的命令更新源
yum clean all
yum update

2.启动Nginx

service nginx start

现在Nginx已经启动了,直接访问服务器就能看到Nginx欢迎页面了的。如果还无法访问,则需配置一下Linux防火墙。
3.配置防火墙,开放80端口

vim /etc/sysconfig/iptables

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
#复制上面一行,将22改成80,保存即可
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

#最好重启一下防火墙
service iptables restart

注意:如果是阿里云的ecs,你可能需要在阿里云的主机管理后台,添加安全组规则,方可开启80端口
4.设置开机启动

chkconfig --list | grep nginx
chkconfig nginx  on

END:Nginx安装配置完成


yum 安装MySQL5.6

参考:

https://www.cnblogs.com/007sx/p/7083143.html
1.检查系统是否安装其他版本的MYSQL数据

yum list installed | grep mysql
yum -y remove mysql-libs.x86_64

2.配置MySQL源

 wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
 rpm -ivh mysql-community-release-el6-5.noarch.rpm
 yum repolist all | grep mysql

3.安装MYSQL数据库

yum install mysql-community-server -y

4.设置为开机启动(2、3、4都是on代表开机自动启动)

chkconfig --list | grep mysqld
chkconfig mysqld on

5.启动mysql

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密码

 /usr/bin/mysqladmin -u root password 'xxxxx'

安全处理,看不懂英文直接一路yes就行

/usr/bin/mysql_secure_installation

[注意]2017/12/24更新:

今日安装MySQL执行上面的命令的时候出现下面的话
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

意思是root用户设置密码,之前我们已经设置过了,这个地方输入“no”即可,不然你还要重新设置root用户密码。

7.设置utf-8编码

查看mysql原本编码:
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

编辑mysql的配置文件/etc/my.cnf

vi /etc/my.cnf

[mysqld]
character-set-server=utf8 
collation-server=utf8_general_ci 
sql_mode='NO_ENGINE_SUBSTITUTION'

[mysql]
default-character-set = utf8

[mysql.server]
default-character-set = utf8


[mysqld_safe]
default-character-set = utf8


[client]
default-character-set = utf8

#重启mysql
service mysqld restart

#再次查看

mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

END:到此MySQL安装配置成功


编译安装PHP7.0.26

参考:

  1. https://segmentfault.com/a/1190000005005068
  2. http://blog.csdn.net/tomspcc/article/details/71080991

1.安装PHP支持库

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源码包

 wget  http://sg2.php.net/distributions/php-7.0.26.tar.gz

3.编译安装PHP

./configure \
--prefix=/usr/local/php \
--exec-prefix=/usr/local/php \
--bindir=/usr/local/php/bin \
--with-fpm-user=www \
--with-fpm-group=www \
--sbindir=/usr/local/php/sbin \
--includedir=/usr/local/php/include \
--libdir=/usr/local/php/lib/php \
--mandir=/usr/local/php/php/man \
--with-config-file-path=/usr/local/php/etc \
--with-mcrypt=/usr/include \
--with-mhash \
--with-openssl \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-gd \
--with-iconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache \
--enable-fpm \
--without-gdbm \
--disable-fileinfo

编译报下面的错误

checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

执行下面的命令安装libmcrypet

yum install libmcrypt-devel -y 

若上面的方法解决不了,可以编译安装libmcrypet

cd /usr/local/src
wget http://softlayer.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
cd /usr/local/src/libmcrypt-2.5.8
./configure --prefix=/usr/local
make
make install

上面的方法要是还是不行,那用下面的方法:

安装第三方yum源
wget http://www.atomicorp.com/installers/atomic
sh ./atomic

yum install libmcrypt-devel -y 

4.最后执行下面的命令,完成PHP的安装

make 
make install

5.配置PHP-FPM

  • 增加用户&用户组
groupadd www
useradd -g www www
  • 拷贝php-fpm.conf文件
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
  • 拷贝php-fpm include文件
cp usr/local/php/etc/php-fpm.d/www.conf.default  www.conf
  • 从源码包里拷贝php.ini
cp /usr/local/src/php-7.0.26/php.ini-production /usr/local/php/etc/php.ini

6.将PHP加入环境变量

vi /etc/profile

export PATH=$PATH:/usr/local/php/bin
source /etc/profile

7.php-fpm自启动

  • 从源码包里拷贝启动脚本
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  • 加入系统启动项
chkconfig php-fpm on

8.重启PHP

service php-fpm restart

END:PHP安装配置完成


编译安装git

参考:
http://www.cnblogs.com/fazo/p/5578644.html

1.安装依赖的包

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

2.下载源码包

wget https://github.com/git/git/archive/v2.9.0.zip
unzip v2.9.0.zip
cd git-2.9.0

3.编译安装

make prefix=/usr/local/git all
make prefix=/usr/local/git install

4.加入系统变量

vi /etc/profile  
export PATH=/usr/local/git/bin:$PATH

5.配置git

git config --global user.name 'vultr'
git config --global user.email 'vultr@dy360.net' 'vultr@dy360.net'
git config --global credential.helper store #保存密码

6.生成ssh密钥,执行下面的命令,一路回车即可,即可用密钥克隆项目。

ssh-keygen -t rsa -C 'vultr@dy360.net'

END:git安装配置成功


最后,终于环境搭建好了!自己搭建lnmp环境少说也有十几次了,可是每次都有新感觉!因为每次出现的问题,都不太一样!最近两次都出现了Nginx安装后,通过ip不能访问的问题,结果发现都是防火墙的问题,没有开启80端口。坑的要命!

相关文章

此处评论已关闭