LNMP

LNMP环境搭建

LNMP中L指Linux,N指Nginx,M指Mysql,P指PHP,将这三个服务搭好就OK了,下面一步一步搭建

Nginx编译安装

需要rz命令将Nginx包拿进来,rz需要用yum安装,这里第一步先配置好yum
[[email protected] ~]#cd /etc/yum.repos.d/
[[email protected] /etc/yum.repos.d]# mkdir yum.bak
[[email protected] /etc/yum.repos.d]#mv C* yum.bak
[[email protected] /etc/yum.repos.d]#vi yum.repo
[[email protected]st /etc/yum.repos.d]# mount /dev/sr0 /media
安装rz把包取进来
[[email protected] /etc/yum.repos.d]# yum -y install lrzsz
所有的包都放在/usr/local/src下
[[email protected] /etc/yum.repos.d]#cd /usr/local/src
[[email protected] /usr/local/src]# rz
LNMP
[[email protected] /usr/local/src]#ls
libmcrypt-2.5.8.tar.gz mysql-5.5.22.tar.gz nginx-1.11.5.tar.gz php-5.5.14.tar.gz
创建 /data/server 解完的包服务都在放在这
[[email protected] /usr/local/src]#mkdir -p /data/server
[[email protected] /usr/local/src]# tar zxf nginx-1.6.0.tar.gz -C /data/server/
创建运行用户
[[email protected] /usr/local/src]#groupadd nginx
[[email protected] /usr/local/src]#useradd -s /sbin/nologin -M -g nginx nginx
配置Nginx
[[email protected] /usr/local/src]#cd /data/server/nginx-1.6.0/
[[email protected] nginx-1.6.0]#./configure --prefix=/data/server/nginx --user=nginx --group=nginx
报错缺少环境
[[email protected] nginx-1.6.0]#yum -y install gcc gcc-c++ pcre-devel zlib-devel
编译安装
[[email protected] nginx-1.6.0]#make && make install
路径优化
[[email protected] nginx-1.6.0]#ln -s /data/server/nginx/sbin/nginx /usr/local/bin/
开启服务、关闭防火墙网页验证
[[email protected] ~]#nginx
[[email protected] ~]#systemctl stop firewalld
LNMP

Mysql编译安装

[[email protected] /usr/local/src]#tar zxf mysql-5.6.19.tar.gz -C /data/server/
创建运行用户
[[email protected] /usr/local/src]#groupadd mysql
[[email protected] /usr/local/src]#useradd -s /sbin/nologin -M -g mysql mysql
配置Mysql
[[email protected] /usr/local/src]#cd /data/server/mysql-5.6.19/
[[email protected] mysql-5.5.22]#yum -y install cmake
[[email protected] mysql-5.5.22]#cmake -DCMAKE_INSTALL_PREFIX=/data/server/mysql -DSYSCONFDIR=/etc/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=al
编译安装
[[email protected] mysql-5.5.22]#make && make install
设置数据库目录的权限并建立配置文件
[[email protected] mysql-5.5.22]#chown -R mysql:mysql /data/server/mysql/
[[email protected] mysql-5.5.22]#cp support-files/my-default.cnf /etc/my.cnf
初始化数据库并设置环境变量
[[email protected] mysql-5.5.22]#/data/server/mysql/scripts/mysql_install_db --user=mysql --basedir=/data/server/mysql --datadir=/data/server/mysql/data/
发现报错缺少环境
[[email protected] mysql-5.5.22]#yum -y install perl perl-devel
[[email protected] mysql-5.5.22]#yum -y install perl-Data-Dumper
重复上面步骤即可
添加系统服务
[[email protected] mysql-5.5.22]#cp support-files/mysql.server /etc/init.d/mysql
[[email protected] mysql-5.5.22]#chmod a+x /etc/init.d/mysql
[[email protected] mysql-5.5.22]#chkconfig --add mysql
开启服务,看到端口号为3306
[[email protected] mysql-5.5.22]#systemctl start mysql
[[email protected] mysql-5.5.22]#netstat -anput |grep mysql
tcp6 0 0 :::3306 ::???? LISTEN 50063/mysqld
做路径优化
[[email protected] mysql-5.5.22]#ln -s /data/server/mysql/bin/* /usr/local/bin/
登录mysql数据库验证
[[email protected] mysql-5.6.19]# mysql -u root -p

LNMP

PHP编译安装

解压PHP
[[email protected] /usr/local/src]#tar zxf php-5.5.14.tar.gz -C /data/server/
配置PHP
[[email protected] /usr/local/src]#cd /data/server/php-5.5.14/
[[email protected] php-5.5.14]#./configure --prefix=/data/server/php --with-config-file-path=/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache=no --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline --without-sqlite3 --without-pdo-sqlite --with-pea
报错缺少环境用yum补齐 其中一个需要编译安装
[[email protected] /usr/local/src]#tar zxf libmcrypt-2.5.8.tar.gz -C /data/server/
[[email protected] /usr/local/src]#cd /data/server/libmcrypt-2.5.8/
[[email protected] libmcrypt-2.5.8]#./configure
[[email protected] libmcrypt-2.5.8]#make && make install
[[email protected] libmcrypt-2.5.8]#cd /data/server/php-5.5.14/
[[email protected] php-5.5.14]#yum -y install libxml2-devel
[[email protected] php-5.5.14]#yum -y install bzip2-devel
[[email protected] php-5.5.14]#yum -y install libcurl-devel
[[email protected] php-5.5.14]#yum -y install readline-devel
[[email protected] php-5.5.14]#yum -y install openssl-devel
安装完依赖环境继续编译安装
[[email protected] php-5.5.14]#make && make install
复制配置文件到data server下
[[email protected] php-5.5.14]# cp php.ini-development /data/server/php/etc/php.ini
[[email protected] php-5.5.14]# cp /data/server/php/etc/php-fpm.conf.default /data/server/php/etc/php-fpm.conf
[[email protected] php-5.5.14]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] php-5.5.14]# chmod +x /etc/init.d/php-fpm
[[email protected] php-5.5.14]# /etc/init.d/php-fpm start
发现报错,创建www用户
[[email protected] php-5.5.14]# groupadd www
[[email protected] php-5.5.14]# useradd -s /sbin/nologin -M -g www www
[[email protected] php-5.5.14]# /etc/init.d/php-fpm
Starting php-fpm done
开启成功
修改配置文件
[[email protected] php-5.5.14]# vi /data/server/nginx/conf/nginx.conf
LNMP
LNMP
编辑一个lnmp环境测试页面
[[email protected] php-5.5.14]# vi /data/server/nginx/html/fyk.php
LNMP
网页输入ip/fyk.php验证
LNMP
这样就成功了,如果失败就重启nginx 或者看最后修改配置有没有改错或没改的地方
[[email protected] php-5.5.14]# nginx -s reload
[[email protected] php-5.5.14]# nginx
重启就行