基于CentOS 6.8平台最新源代码包编译安装LNMP环境搭建(Nginx+MySQL+PHP)

前端之家收集整理的这篇文章主要介绍了基于CentOS 6.8平台最新源代码包编译安装LNMP环境搭建(Nginx+MySQL+PHP)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

部署环境

系统:CentOS 6.8 x86_64

Nginx:1.11.3

MysqL:5.7.14

PHP:7.0.10

pcre:8.39

zlib:1.2.8

openssl:1.0.1t

freetype:2.6.5

libmcrypt:2.5.8

boost:1.59.0

cmake:3.6.1

部署准备

使用客户机浏览器访问freetype官网https://www.freetype.org/下载页面选取一个下载地址

wKiom1fKdN-QMBQ4AACN2-s5BB8081.png-wh_50

下载目前最新发行版本,右击-复制下载链接

wKioL1fKdszBCW8mAACDmBgSbtc657.png-wh_50

在CentOS服务系统切换到/usr/src目录下使用wget工具贴入下载刚刚复制的链接

cd /usr/src

wgethttp://download.savannah.gnu.org/releases/freetype/freetype-2.6.5.tar.gz

wKiom1fKeweBt4v_AAD3AAnref4963.png

访问mcrypt官网http://mcrypt.sourceforge.net/选择一个下载站点

wKiom1fKfaCjcZPeAAAsN-3Kgc0477.png

查看所有文件

wKioL1fKff3jOPxJAABzEtiY1pU845.png

选择目录libmcrypt

wKiom1fKyBXh5qj2AAA-CeLW_U8355.png-wh_50

2.5.8版本

wKioL1fKyFiSqQARAAA67ymlpUs138.png-wh_50

选择一个包下载

wKioL1fKyH-wMlsjAABE5hUbpI8131.png-wh_50

访问openssl官网https://www.openssl.org/ 下载页面

wKiom1fKi-LS1bW2AAEmmO8vXLw776.png-wh_50

这里选择下载1.0.1t版本

wKiom1fKm-CgHESoAAGmGA5KcLE617.png-wh_50

访问pcre官网http://www.pcre.org/ 选取一个下载站点

wKiom1fGhu7Bda5lAABavBXbrZ0884.png-wh_50

下载最新发行版本

wKioL1fGh5XyUW2fAAA_yCKhgv4653.png-wh_50

访问zlib官网http://www.zlib.net/ 拉到最下面选取一个下载站点

wKiom1fKgzSzOdhzAABV7sGXnV0517.png-wh_50

复制完整下载地址进行下载

wKioL1fKg3Piz8AEAAAv0qkKpP0599.png-wh_50

boost官网http://www.boost.org/ 选择1.59.0版本

wKiom1fKoFvwM3-CAAAuZrV-NmI033.png-wh_50

选择Linux平台下的软件包

wKiom1fKoLWhs5YCAAAXKEopOEQ636.png-wh_50

获取下载地址进行下载

wKiom1fKoRPhyje9AABl7RJipYw786.png-wh_50

访问cmake官网https://cmake.org/ 下载页面

wKioL1fKoWeysknCAACbt_u_6aY948.png-wh_50

下载最新发行版

wKiom1fKodvw1pM4AACxYlHz0Gw164.png-wh_50

访问Nginx官网http://nginx.org/ 下载目前最新发行版

wKiom1fKhBvzhp1wAAAqcegyXu8195.png-wh_50

wKiom1fKhHiyqa9aAABZdHFaZlA310.png

访问MysqL官网https://www.mysql.com/ 下载页面

wKiom1fGi96xq4rMAABUia3gLHY900.png

下载免费社区版

wKiom1fGjGWBKFQXAABmWovhpl8492.png-wh_50

前往下载页面

wKioL1fGjIyzHO7dAABHOy6LqWc985.png-wh_50

平台类型:源代码

wKiom1fGjPPyasvPAAAsFzkV6jw002.png-wh_50

tar包下载

wKiom1fGjWXQguNkAAB9VF1GXQg914.png

不登陆下载

wKioL1fGjZeyyWQjAADSgXQngls828.png-wh_50

获取完整下载地址后到下载到CentOS系统

wKioL1fKhgjTf0gOAAAzYzh8GxM714.png

访问PHP官网http://www.php.net/ 下载页面选择最新版

wKiom1fGjlDCYGYpAADK5TYhE1E311.png-wh_50

最近站点下载

wKioL1fGjpHzbclVAAAY1IvxbIg170.png-wh_50

获取完整下载地址下载

wKiom1fKhuPCH49qAAAxmxREYJg962.png

所有软件包

wKiom1fK_r3TpnZ-AAA3RLzDiBg835.png

部署过程

使用yum安装所需的系统软件包

yum install -y gcc gcc-c++ncursesncurses-devellibxml2 libxml2-develcurl-devellibpnglibpng-devel

wKiom1fKrS-zN5q-AAAvyILFpKc132.png

安装Nginx

解压pcre与zlib压缩包

tar zxf pcre-8.39.tar.gz

tar zxf zlib-1.2.8.tar.gz

tar zxf openssl-1.1.0.tar.gz

wKiom1fKjjvzAv6eAAAS2p497_w457.png

解压Nginx压缩包配置

tar zxf Nginx-1.11.3.tar.gz

cd Nginx-1.11.3

./configure --prefix=/usr/local/Nginx --pid-path=/usr/local/Nginx/run/Nginx.pid --user=Nginx --group=Nginx --with-http_gunzip_module --with-http_gzip_static_module --with-http_ssl_module --with-zlib=/usr/src/zlib-1.2.8 --with-pcre=/usr/src/pcre-8.39 --with-openssl=/usr/src/openssl-1.0.1t

wKioL1fKjw7w68m0AABguW4xB9w770.png

wKiom1fKnPuju3GCAACjd_ZQxOc325.png

编译安装

make && make install

wKiom1fJJJ6yqUOEAABU-aLykSs702.png

创建Nginx用户,分配权限。

useradd -M -s /sbin/nologin Nginx

chown -R Nginx.Nginx /usr/local/Nginx/

wKiom1fJKAiTq_jEAAATLSU68nU515.png

启动Nginx服务

/usr/local/Nginx/sbin/Nginx

wKioL1fJJQbSXqieAABQL38S74k362.png

创建开机自启动脚本 /etc/init.d/Nginx 内容如下:

#! /bin/sh

#

#

# chkconfig: 2345 66 34

# description: A very fast and reliable Nginx engine

#

#

#

BASEDIR=/usr/local/Nginx

DAEMON=$BASEDIR/sbin/Nginx

PIDFILE=$BASEDIR/run/Nginx.pid


set -e

if [ ! -x "$DAEMON" ];then

echo "Nginx deamon not exist"

exit 1

fi


if [ ! "$1" ];then

echo "Usage: {start|stop|reload|restart}"

exit 2

fi


_start() {

$DAEMON

}


_stop() {

$DAEMON -s stop

}


_reload() {

$DAEMON -s reload

}


case "$1" in

start)

_start

echo -e "Starting Nginx: [ \e[0;32mOK\e[0m ]"

;;

stop)

_stop

echo -e "Stoping Nginx: [ \e[0;32mOK\e[0m ]"

;;

reload|graceful)

_reload

echo -e "Reloading Nginx: [ \e[0;32mOK\e[0m ]"

;;

restart)

_stop

echo -e "Stoping Nginx: [ \e[0;32mOK\e[0m ]"

_start

echo -e "Starting Nginx: [ \e[0;32mOK\e[0m ]"

esac


exit 0

wKiom1fJIOOw4nyYAAA7TqP5-pU330.png-wh_50

添加执行权限

chmod 755 /etc/init.d/Nginx

wKioL1fJIU6jupfMAAAYHxTF1Uw142.png

添加到chkconfig服务管理

chkconfig --add Nginx

wKiom1fJIZWTEfZGAAAV5vTEEFE477.png

测试脚本运行情况

wKiom1fJIlDhIK5VAACdYLzqjbk480.png

安装MysqL

切换回/usr/src目录安装boost

cd /usr/src/

tar jxf boost_1_59_0.tar.bz2

cd boost_1_59_0

./bootstrap.sh

wKiom1fKo63Ti7PLAACVftrUoG4283.png-wh_50

编译

./b2

wKioL1fGoKaSfbErAACV1ivxNqU138.png

安装

./b2 install --prefix=/usr/local/boost

wKioL1fGoTDB9fjWAACXub-WS1M062.png

切换回/usr/src目录安装cmake

tar zxf cmake-3.6.1.tar.gz

cd cmake-3.6.1

./configure --prefix=/usr/local/cmake

wKioL1fKqi_gNjqUAABsystxFws718.png-wh_50

编译安装

make && make install

wKiom1fKrCbgqyH0AADPlgeoMcI323.png-wh_50

MysqL数据库

cd /usr/src/

tar zxf MysqL-5.7.14.tar.gz

cd MysqL-5.7.14

/usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/MysqL -DSYSCONFDIR=/usr/local/MysqL/etc -DMysqL_DATADIR=/usr/local/MysqL/data -DMysqL_UNIX_ADDR=/usr/local/MysqL/MysqL.sock-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMysqL_TCP_PORT=3306 -DMysqL_USER=MysqL -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_BOOST=/usr/local/boost/include

wKioL1fKrIDj1JgjAACxp_PU2X8941.png-wh_50

wKioL1fKraiC5QfRAABdJpGw95I173.png-wh_50

编译安装

make && make install

wKiom1fKummzih-zAAC5z8CZy-8669.png

创建有关目录

@H_310_502@mkdir -p /usr/local/MysqL/etc

mkdir -p /usr/local/MysqL/data

mkdir -p /usr/local/MysqL/log

mkdir -p /usr/local/MysqL/run

wKiom1fKut-iENHAAAA36Mw6ENs009.png

删除 /etc/my.cnf 配置文件,新建/usr/local/MysqL/etc/my.cnf 文件

rm -f /etc/my.cnf

cat > /usr/local/MysqL/etc/my.cnf << EOF

[MysqLd]

datadir=/usr/local/MysqL/data

socket=/usr/local/MysqL/MysqL.sock

user=MysqL

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0


[MysqLd_safe]

log-error=/usr/local/MysqL/log/MysqLd.log

pid-file=/usr/local/MysqL/run/MysqLd.pid

EOF

wKioL1fKv0zzECP9AABo1MJm8dE933.png

创建MysqL用户并分配权限

useradd -M -s /sbin/nologin MysqL

chown -R MysqL:MysqL /usr/local/MysqL/

wKiom1fKvJmRn9UxAAAtf6t6MBw375.png

初始化数据库,注意最后一行提示会给出临时登录密码。

/usr/local/MysqL/bin/MysqLd --initialize --user=MysqL --basedir=/usr/local/MysqL/ --datadir=/usr/local/MysqL/data

wKioL1fKvQOz5w9ZAACf25c4mzU384.png

启动MysqL数据库

/usr/local/MysqL/bin/MysqLd_safe &

wKioL1fKvXSjIx3cAACXxCk6e6k177.png

使用生成的临时密码登录MysqL数据库

/usr/local/MysqL/bin/MysqL -u root -p

wKiom1fH_DOCvUYxAABBlxoR5S0744.png

修改数据库登录密码为A2c@1B3

alter user 'root'@'localhost' identified by 'A2c@1B3';

wKiom1fHlYqhg4SAAAAQaRzSOjs364.png

创建MysqL服务启动脚本

cp /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqL

chmod 755 /etc/init.d/MysqL

wKioL1fKwQuxiU3-AAAsH-E1JhA575.png

修改启动脚本文件/etc/init.d/MysqL

basedir=/usr/local/MysqL

datadir=/usr/local/MysqL/data

MysqLd_pid_file_path=/usr/local/MysqL/run/MysqLd.pid

wKioL1fHl_6zzVuGAABUXREsxtc532.png


添加至chkconfig服务管理

chkconfig --add MysqL

wKioL1fKwejQq6XKAAA41BhDHYk983.png

安装PHP

切换回/usr/src目录安装freetype

tar jxf freetype-2.6.5.tar.bz2

cd freetype-2.6.5

./configure --prefix=/usr/local/freetype

wKiom1fKxyLwcU6tAAAqbZq_Bak911.png-wh_50

编译安装

make && make install

wKioL1fKx1WAfQkvAACmJGl1ZLQ304.png-wh_50

切换回/usr/src目录安装libmcrypt

tar zxf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure --prefix=/usr/local/libmcrypt

wKiom1fKyYagGt4OAACTzqDT9gA163.png-wh_50

编译安装

make && make install

wKioL1fKyc3zpdvqAAD9MbAUxTg557.png-wh_50

安装openssl

cd /usr/src/openssl-1.0.1t

./config --prefix=/usr/local/openssl

wKioL1fK7gLBeSVSAACZ3O6n1qg187.png-wh_50

编译安装

make && make install

wKioL1fK7uqyb56BAACl0liebOI502.png-wh_50

切换回/usr/src目录安装PHP

tarPHP-7.0.10.tar.gz

cdPHP-7.0.10

./configure --prefix=/usr/local/PHP --with-config-file-path=/usr/local/PHP/etc --enable-MysqLnd --with-MysqLi=MysqLnd --with-pdo-MysqL=MysqLnd --enable-mbstring --enable-fpm --with-fpm-user=Nginx --with-fpm-group=Nginx --with-mcrypt=/usr/local/libmcrypt/ --with-freetype-dir=/usr/local/freetype/ --with-openssl=/usr/local/openssl/ --enable-gd-native-ttf --with-gd --with-iconv --with-zlib --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-sockets --enable-zip --enable-soap --with-gettext --enable-session --with-curl --enable-opcache

wKiom1fK8kvxOEwWAADIKY22brk731.png-wh_50

编译安装

make && make install

wKiom1fK9K3wALkDAADiP_m1aT8725.png-wh_50

创建配置文件

cp PHP.ini-production /usr/local/PHP/etc/PHP.ini

cp /usr/local/PHP/etc/PHP-fpm.conf.default /usr/local/PHP/etc/PHP-fpm.conf

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

wKiom1fK9e2j8jLFAAA5DAAK88M303.png

创建PHP-fpm开机启动脚本

cp sapi/fpm/init.d.PHP-fpm /etc/init.d/PHP-fpm

chmod 755 /etc/init.d/PHP-fpm

wKioL1fK-FCgIxggAAAjjhNzVN8558.png

编辑/etc/init.d/PHP-fpm文件加入参数控制启动顺序,放在Nginx服务后启动。

# chkconfig: 2345 67 33

wKioL1fK-OLxTrPoAABX8LVTZ7M956.png

添加至chkconfig服务管理

chkconfig --add PHP-fpm

wKiom1fK-TbSLfqrAAA2R6bInYU098.png

编辑Nginx配置文件/usr/local/Nginx/conf/Nginx.conf 添加PHP索引

wKioL1fK-fPyZDF5AABGLpp3iVg763.png

取消PHP解析模块部分注释,修改脚本文件路径。

wKioL1fK-kmT0D6hAABp2Tu8IpE791.png

创建PHP测试文件

rm -f /usr/local/Nginx/html/*

cat > /usr/local/Nginx/html/index.PHP << EOF

<?PHP

PHPinfo();

?>

EOF

wKiom1fK-2-SXt5LAAA3-nm44fc038.png

重启Nginx服务与PHP-fpm服务,关闭系统防火墙与selinux服务。

service Nginx restart

/etc/init.d/PHP-fpm start

/etc/init.d/iptables stop

chkconfig iptables off

setenforce 0

wKiom1fK_I3Q7ZasAAB7kHmvHLU968.png

浏览器访问CentOS服务器地址,随后显示PHP测试页面详细信息。

wKioL1fK_UiRKrmaAADEvxsUdnA073.png-wh_50


注意:为了使PHP站点支持更多的扩展功能,以上安装了许多支持的第三方模块,请根据实际环境需求选择安装!

原文链接:https://www.f2er.com/centos/380883.html

猜你在找的CentOS相关文章