centos7编译安装LNMP

1、本次使用的应用版本

mysql5.6.31、nginx1.10.1、php5.6.30

软件下载地址:

https://wangxuejin-data-1252194948.cos.ap-shanghai.myqcloud.com/nginx-1.10.1.tar.gz

https://wangxuejin-data-1252194948.cos.ap-shanghai.myqcloud.com/mysql-5.6.31.tar.gz

https://wangxuejin-data-1252194948.cos.ap-shanghai.myqcloud.com/php-5.6.30.tar.gz

2、安装nginx

安装依赖环境

[root@55cea6de73cb ]# yum install gcc gcc-c++ openssl openssl-devel pcre pcre-devel zlib zlib-devel -y

解压nginx

[root@2df7fb5c5f50 opt]# tar xf nginx-1.10.1.tar.gz

配置nginx

[root@2df7fb5c5f50 ]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module

没有报错表示配置成功

编译并安装

[root@2df7fb5c5f50 opt]# make && make install

没有报错表示安装成功

启动nginx服务

[root@2df7fb5c5f50 opt]# /usr/local/nginx/sbin/nginx 

查看监听端口

网页访问IP地址

出现如上表示nginx安装成功

增加环境变量方便启动

[root@2df7fb5c5f50 opt]# echo "export PATH=$PATH:/usr/local/nginx/sbin" >>/etc/profile

//立即生效
[root@2df7fb5c5f50 opt]# source /etc/profile

//重启nginx服务测试
[root@2df7fb5c5f50 opt]# nginx -s reload

3、安装mysql数据库

解压

[root@2df7fb5c5f50 opt]# tar xf mysql-5.6.31.tar.gz

安装依赖环境

[root@2df7fb5c5f50 opt]# yum install -y cmake bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel

配置

[root@2df7fb5c5f50 mysql-5.6.31]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data

指定安装目录和数据存储目录

出现如下表示配置成功

编译并安装mysql

[root@2df7fb5c5f50 mysql-5.6.31]# make && make install

出现如下没有报错表示安装成功

初始化配置mysql

[root@2df7fb5c5f50 mysql-5.6.31]# cd /usr/local/mysql/
[root@2df7fb5c5f50 mysql]# useradd -s /sbin/nologin mysql

修改权限,当前目录授权给mysql用户

[root@2df7fb5c5f50 mysql]# chown mysql.mysql -R .

安装mysql系统表

[root@2df7fb5c5f50 mysql]# rm -f /etc/my.cnf    删除系统自带的my.cnf配置文件

[root@2df7fb5c5f50 mysql]# ./scripts/mysql_install_db --user=mysql

出现如下表示安装成功

复制配置文件到/etc/下

[root@2df7fb5c5f50 mysql]# cp support-files/my-default.cnf /etc/my.cnf

以完整路径启动mysql数据库

[root@2df7fb5c5f50 mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
 [1] 26282
 [root@2df7fb5c5f50 mysql]# 190805 07:45:58 mysqld_safe Logging to '/usr/local/mysql/data/2df7fb5c5f50.err'.
 190805 07:45:59 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

查看进程是否启动成功

复制服务进程到/etc/init.d/下

[root@2df7fb5c5f50 mysql]# cp support-files/mysql.server /etc/init.d/mysqld

重启服务

[root@2df7fb5c5f50 mysql]# /etc/init.d/mysqld restart
 Shutting down MySQL..190805 07:47:52 mysqld_safe mysqld from pid file /usr/local/mysql/data/2df7fb5c5f50.pid ended
  SUCCESS! 
 Starting MySQL. SUCCESS! 
 [1]+  Done                    /usr/local/mysql/bin/mysqld_safe --user=mysql

配置环境变量

[root@2df7fb5c5f50 mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile

生效

[root@2df7fb5c5f50 mysql]# source /etc/profile

第一次登陆没有密码需要设置mysql密码

[root@2df7fb5c5f50 mysql]# mysql -u root -p
 Enter password: 
 Welcome to the MySQL monitor.  Commands end with ; or \g.
 Your MySQL connection id is 1
 Server version: 5.6.31 Source distribution
 Copyright (c) 2000, 2016, 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> 

//修改root密码
mysql> use mysql;
 Reading table information for completion of table and column names
 You can turn off this feature to get a quicker startup with -A
 Database changed
mysql> update mysql.user set password=password('Aa123456') where user='root';
 Query OK, 4 rows affected (0.00 sec)
 Rows matched: 4  Changed: 4  Warnings: 0
 mysql> flush privileges;
 Query OK, 0 rows affected (0.00 sec)

至此mysql数据库安装成功

4、安装php

安装依赖环境

[root@2df7fb5c5f50 opt]# yum install -y gcc gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel

解压

[root@2df7fb5c5f50 opt]# tar xf php-5.6.30.tar.gz

配置

[root@2df7fb5c5f50 php-5.6.30]# ./configure --prefix=/usr/local/php-fpm --enable-fpm --with-zlib --with-pdo-mysql --enable-mbstring --with-gd --with-png-dir=/usr/lib64 --with-jpeg-dir=/usr/lib64 --with-freetype-dir=/usr/lib64 --with-mysql-sock=/tmp/mysql.sock --with-mysqli=/usr/local/mysql/bin/mysql_config

出现如下表示编译成功

编译并安装

 [root@2df7fb5c5f50 php-5.6.30]#  make && make install

出现如下提示表示安装成功

修改配置文件名字

[root@2df7fb5c5f50 php-5.6.30]# cd /usr/local/php-fpm/etc/
 [root@2df7fb5c5f50 etc]# cp php-fpm.conf.default php-fpm.conf  

配置php的配置文件

[root@2df7fb5c5f50 etc]# vim php-fpm.conf

修改用户和用户组为web

启动服务

[root@2df7fb5c5f50 etc]# useradd -s /sbin/nologin web
[root@2df7fb5c5f50 etc]# /usr/local/php-fpm/sbin/php-fpm 
设置php-fpm服务方便启动
[root@2df7fb5c5f50 /]# cp /opt/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 

检查服务是否启动

至此PHP服务安装完成

5、nginx开启支持php

[root@2df7fb5c5f50 conf]# vim /usr/local/nginx/conf/nginx.conf
45行增加index.php
65-71行去掉注释,修改fastcgi_param这一行

6、测试

[root@2df7fb5c5f50 conf]# vim /usr/local/nginx/html/index.php 

打开网页测试看是否能解析php语言

至此LNMP安装完成,如果大家有疑问可以加群找我讨论。QQ群号:955496382

发表评论

登录... 后才能评论