centos7 搭建LNMP

一、安装mysql5.6版本

cd /usr/local/src      #进入目录 下载的包好管理

wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz     #下载mysql

tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz      #解压mysql

mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql    #移到到/usr/local/下

useradd mysql                                 #创建一个mysql用户

mkdir -p /data/

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql    #初始化mysql  

如果出现下面的错误

####l FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper #### 

这种初始化需要依赖perl语言

可以用yum list查看一下 yum list | grep perl | grep -i dumper  

命令:yum-y install autoconf
##################
 
cp support-files/my-default.cnf  /etc/my.cnf         #复制配置文件
mkdir -p /data/mysql
 
vim /etc/my.cmf 修改以下配置
 datadir=/data/mysql

socket=/tmp/mysql.sock

cp support-files/mysql.server /etc/init.d/mysqld  #复制启动脚本

vim /etc/init.d/mysqld     #编辑脚本 修改以下内容

basedir=/usr/local/mysql
datadir=/data/mysql  

 /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql

chkconfig --add mysqld    #添加mysqld服务

service mysqld start       # 开启服务

#! 如果出现启动脚本复制不了init.d里面  无法使用service 开启服务 可以使用

二、安装php

 wget http://cn2.php.net/distributions/php-5.6.30.tar.gz    #下载php包

 wget http://www.atomicorp.com/installers/atomicsh ./atomic

 #安装依赖包

yum -y install libjpeg*  libpng*  freetype* php-mcrypt  libmcrypt  libmcrypt-devel libxml2* openssl* libcurl-devel gcc* freetype*

tar zxf php-5.6.30.tar.gz

useradd -s /sbin/nologin php-fpm     #创建一个php-fpm 用户

./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl            #编译PHP

#####编译后看有没有出错#####

出错后 缺少什么包安装什么包

make && make install   #安装略久

cp php.ini-production /usr/local/php-fpm/etc/         #复制配置文件

cd /usr/local/php-fpm/etc/ 

 vim php-fpm.conf                
 #创建一个php-fpm.conf文件在https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/php-fpm.conf复制样例
 
 cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm   #复制启动程序
chmod 755 /etc/init.d/php-fpm 
chkconfig --add php-fpm
chkconfig php-fpm on 
service php-fpm start 
 

三、安装nginx

cd /usr/local/src/ 

wget  http://nginx.org/download/nginx-1.12.1.tar.gz 

tar zxf  nginx-1.12.1.tar.gz

cd nginx-1.12.1

./configure --prefix=/usr/local/nginx && make && make install 

编写启动脚本,启动样例在下面的网址

vim /etc/init.d/nginx

https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/etc_init.d_nginx

chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on

cd /usr/local/nginx/conf

mv nginx.conf nginx.conf.1    #备份一个配置文件

编辑新的配置文件 样例在下面网站

https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/nginx.conf

 vim /usr/local/nginx/html/1.php  # 编写测试脚本

<?php
echo "this is nginx test.";

curl /usr/local/nginx/html/1.php    #测试出来写的脚本就成功了

原文地址:https://www.cnblogs.com/lh777/p/8047944.html