centos7.2+php7.0.10+mysql5.7.14+nginx1.10.1搭建LNMP环境

前端之家收集整理的这篇文章主要介绍了centos7.2+php7.0.10+mysql5.7.14+nginx1.10.1搭建LNMP环境前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、准备工作:

软件默认下载在/usr/local/src下,安装在/app/local下的PHPMysqLNginx、data目录下,安装顺序按照Nginx->MysqL->PHP进行

编译工具集:

yum install -y wget gccgcc-c++autoconfautomake cmakebison m4libxml2libxml2-devellibcurl-devel libjpeg-devel libpng-devel libicu-develpcre pcre-devellibtool

openssl openssl-develbzip2 bzip2-devel ncurses ncurses-develfreetype freetype-devel

libxslt-devel

更新系统:yum install -y update

下载需要的软件:

PHP:wget -c http://mirrors.sohu.com/php/php-7.0.10.tar.gz

MysqL:wget -c http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.14.tar.gz

Nginx:wget -c http://nginx.org/download/nginx-1.10.1.tar.gz

cmake:wget -c https://cmake.org/files/v3.1/cmake-3.1.3.tar.gz

PHP需要的一些库文件:wget -chttp://zlib.net/zlib-1.2.8.tar.gz

wget -c http://blog.zyan.cc/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz

wget -c http://blog.zyan.cc/soft/linux/Nginx_PHP/mcrypt/mcrypt-2.6.8.tar.gz

wget -c http://blog.zyan.cc/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz

二、安装Nginx

新建用户和组:useradd -u 500 -g 500 -G 500 -s /sbin/nologin www

groupadd -g 500 www

新建相应的目录:mkdir -p /app/local/{Nginx,MysqL,PHP,data}

#tar zxvfNginx-1.10.1.tar.gz

#cd Nginx-1.10.1

#可以通过./configure --help查看帮助

#./configure --prefix=/app/local/Nginx --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module

#make && make install

#cd ../

#systemctl stop firewalld.service#关闭防火墙

#/app/local/Nginx/sbin/Nginx #开启Nginx

#可以通过curl判断Nginx是否正常访问或者在浏览器地址栏输入ip地址查看

三、安装MysqL

#tar zxvf cmake-3.1.3.tar.gz

#cd cmake-3.1.3

#./configure

#make && make install

#cd ../

#tar zxvf MysqL-boost-5.7.14.tar.gz

#cd MysqL-5.7.14/

#cmake -DCMAKE_INSTALL_PREFIX=/app/local/MysqL -DMysqL_UNIX_ADDR=/app/local/MysqL/MysqL.sock -DSYSCONFDIR=/app/local/MysqL/etc -DSYSTEMD_PID_DIR=/app/local/MysqL -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DMysqL_DATADIR=/app/local/data -DWITH_BOOST=boost -DWITH_SYSTEMD=1

#make && make install

#cd ../

#chown -R MysqL:MysqL /app/local/MysqL/

#chown -R MysqL:MysqL /app/local/data/

#cd /app/local/MysqL/bin

#./MysqLd --initialize --user=MysqL --basedir=/app/local/MysqL/ --datadir=/app/local/data/ #初始化数据库并且随机生成一个密码

#./MysqLd --user=MysqL#开启MysqL

#echo 'export PATH=$PATH:/app/local/MysqL/bin' >> /etc/profile.d/MysqL.sh

#source /etc/profile.d/MysqL.sh

#MysqL -uroot -p

Enter password:#输入刚才随机生成的密码

MysqL>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';#通过这个重置密码

四、安装PHP

首先安装PHP的一些包文件

#cd /usr/local/src/

#tar zxvf mhash-0.9.9.9.tar.gz

#cd mhash-0.9.9.9

#./configure

#make && make install

#cd ../

#tar zxvf libmcrypt-2.5.8.tar.gz

#cd libmcrypt-2.5.8

#./configure

#make && make install

#cd ../

#tar zxvf mcrypt-2.6.8.tar.gz

#cd mcrypt-2.6.8

#./configure

出现错误:configure: error: *** libmcrypt was not found

解决办法:ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config再./configure依然报错,执行export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH

再./configure通过

#make && make install

#cd ../

#tar zxvf zlib-1.2.8.tar.gz

#cd zlib-1.2.8

#./configure

#make && make install

#cd ../

#tar zxvf PHP-7.0.10.tar.gz

#cd PHP-7.0.10

#./configure --prefix=/app/local/PHP --with-config-file-path=/app/local/PHP/etc --with-pdo-sqlite --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-xmlreader --enable-xmlwriter --enable-soap --enable-calendar --with-curl --with-mcrypt --with-gd --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-pdo-MysqL --with-MysqLi --with-MysqL-sock --enable-MysqLnd --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --enable-ftp --with-imap-ssl --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --disable-fileinfo

#make && make install

#cd ../

五、配置

#cp /usr/local/src/PHP-7.0.10 /app/local/PHP/etc/PHP.ini

#cp/app/local/PHP/etc/PHP-fpm.conf.default/app/local/PHP/etc/PHP-fpm.conf

#cp/app/local/PHP/etc/PHP-fpm.d/www.conf.default/app/local/PHP/etc/PHP-fpm.d/www.conf

#vi www.conf#查找/static将pm=dynamic 改成pm =static保存退出

#vi/app/local/PHP/etc/PHP.ini#查找date.timezone将前面的分号去掉并设置为PRC保存退出

#vi /app/local/Nginx/conf/Nginx.conf

修改

user www www;

worker_processes 4;


error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;


#pid logs/Nginx.pid;



events {

use epoll;

worker_connections 51024;

}

location ~ \.PHP${


root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.PHP;

#fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;

include fastcgi.conf;


}

保存退出

#/app/local/Nginx/sbin/Nginx -t#测试配置文件是否有误 如果出现如下则表示无误 否则会提示错误信息在多少行

Nginx: the configuration file /app/local/Nginx/conf/Nginx.conf Syntax is ok

Nginx: configuration file /app/local/Nginx/conf/Nginx.conf test is successful

#vi /app/local/Nginx/html/index.PHP

输入<?PHP PHPinfo ?>保存退出

#/app/local/Nginx/sbin/Nginx#启动Nginx

#/app/local/PHP/sbin/PHP-fpm#启动PHP-fpm

#systemctl stop firewalld.service#关闭防火墙

在浏览器地址栏输入ip/index.PHP 如果出现如下则表明安装配置成功

wKiom1fK2r6BMFJhAADY18cfGME803.png-wh_50

猜你在找的CentOS相关文章