GVKun编程网logo

Centos生产环境编译安装LNMP(centos7安装lnmp环境)

23

关于Centos生产环境编译安装LNMP和centos7安装lnmp环境的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Centos6编译安装LNMP、CentOS6.10编译安装LNMP

关于Centos生产环境编译安装LNMPcentos7安装lnmp环境的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Centos 6 编译安装LNMP、CentOS 6.10编译安装LNMP、CentOS 6.4系统下编译安装LNMP和配置PHP环境具体步骤、Centos 6.8编译安装LNMP环境(Nginx+MySQL+PHP)教程等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

Centos生产环境编译安装LNMP(centos7安装lnmp环境)

Centos生产环境编译安装LNMP(centos7安装lnmp环境)

640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy

一、环境准备

1、操作系统安装:CentOS 6.564位最小化安装。

2、配置好IP、DNS、网关、主机名

3、配置防火墙,开启80、3306端口

vim /etc/sysconfig/iptables

-A RH-Firewall-1-INPUT -mstate --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #允许80端口通过防火墙

-A RH-Firewall-1-INPUT -mstate --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允许3306端口通过防火墙

特别提示:如果这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的22端口 。

/etc/init.d/iptables restart #最后重启防火墙使配置生效4、关闭SELinux

vi /etc/selinux/configurations

#SELINUX=enforcing #注释掉#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq! #保存退出

setenforce 0#使配置立即生效


二、系统约定

硬盘分区:50G(/boot 200M /swap8192M /)+100G(/opt)

软件源代码包存放位置:/opt/local/src

源码包编译安装位置:/opt/local/软件名

数据库数据文件存储路径/opt/local/MysqL/var


三、软件包下载

1、下载Nginx(目前稳定版):http://Nginx.org/download/Nginx-1.4.4.tar.gz

2、下载pcre (支持Nginx伪静态):ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz

3、下载MysqL:http://cdn.MysqL.com/Downloads/MysqL-5.5/MysqL-5.5.35.tar.gz

4、下载PHP:http://cn2.PHP.net/distributions/PHP-5.5.7.tar.gz

5、下载cmake(MysqL编译工具):http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz

6、下载libmcrypt(PHPlibmcrypt模块):http://nchc.dl.sourceforge.net/project/mcrypt/libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

7、下载GD库安装包(PHP页面图片验证码支持):https://PHPsqq.googlecode.com/files/gd-2.0.36RC1.tar.gz

将以上软件包上传到/opt/local/src目录


四、安装编译工具及库文件

使用CentOS yum命令一键安装

yum install -y make apr* autoconf automake curl curl-devel gcc gcc-c++ gtk+-devel zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* cpp glibc libgomp libstdc++-devel keyutils-libs-devel libsepol-devel libselinux-devel krb5-devel libXpm* freetype freetype-devel freetype* fontconfig fontconfig-devel libjpeg* libpng* PHP-common PHP-gd gettext gettext-devel ncurses* libtool* libxml2 libxml2-devel patch policycoreutils bison


五、软件安装篇

1、安装cmake

cd /opt/local/src

tar zxvf cmake-2.8.8.tar.gz

cd cmake-2.8.8

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

make #编译

make install #安装

vim /etc/profile 在path路径中增加cmake执行文件路径

export PATH=$PATH:/opt/local/cmake/bin

source /etc/profile使配置立即生效

2、安装pcre

cd /opt/local/src

mkdir /usr/local/pcre #创建安装目录

tar zxvf pcre-8.34.tar.gz

cd pcre-8.34

./configure --prefix=/opt/local/pcre#配置

make && make install

3、安装libmcrypt

cd /opt/local/src

tar zxvf libmcrypt-2.5.8.tar.gz #解压

cd libmcrypt-2.5.8#进入目录

./configure #配置

make #编译

make install #安装

4、安装gd库

cd /opt/local/src

tar zxvf gd-2.0.36RC1.tar.gz

cd gd-2.0.36RC1

./configure --enable-m4_pattern_allow ―prefix=/opt/local/gd --with-jpeg=/usr/lib --with-png=/usr/lib --with-xpm=/usr/lib --with-freetype=/usr/lib --with-fontconfig=/usr/lib#配置

make #编译

make install #安装5、安装MysqL

groupadd MysqL #添加MysqL组

useradd -g MysqL MysqL -s /bin/false #创建用户MysqL并加入到MysqL组,不允许MysqL用户直接登录系统mkdir -p /opt/data/MysqL/var #创建MysqL数据库存放目录chown -R MysqL:MysqL /opt/data/MysqL/var #设置MysqL数据库目录权限

cd /opt/local/src

tar zxvf MysqL-5.5.35.tar.gz #解压

cd MysqL-5.5.35

cmake . -DCMAKE_INSTALL_PREFIX=/opt/local/MysqL -DMysqL_DATADIR=/opt/data/MysqL/var -DSYSconfdIR=/etc#配置

make #编译

make install #安装

cd /opt/local/MysqL

cp ./support-files/my-huge.cnf /etc/my.cnf #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)


vi /etc/my.cnf #编辑配置文件,在 [MysqLd] 部分增加

datadir = /opt/data/MysqL/var#添加MysqL数据库路径

./scripts/MysqL_install_db --user=MysqL #生成MysqL系统数据库

cp ./support-files/MysqL.server /etc/rc.d/init.d/MysqLd #把MysqL加入系统启动chmod755 /etc/init.d/MysqLd #增加执行权限

chkconfig MysqLd on #加入开机启动

vi /etc/rc.d/init.d/MysqLd #编辑

basedir = /opt/local/MysqL #MysqL程序安装路径

datadir = /opt/local/MysqL/var #MysqL数据库存放目录

service MysqLd start #启动

vi /etc/profile #把MysqL服务加入系统环境变量:在最后添加下面这一行

export PATH=$PATH:/opt/local/cmake/bin:/opt/local/MysqL/bin

source /etc/profile #使配置立即生效

mkdir /var/lib/MysqL#创建目录

ln -s /tmp/MysqL.sock /var/lib/MysqL/MysqL.sock #添加软链接

MysqL_secure_installation #设置MysqL密码,根据提示按Y 回车输入2次密码

/opt/local/MysqL/bin/MysqLadmin -u root -p password "123456"#或者直接修改密码

到此,MysqL安装完成!

6、安装 Nginx

cd /opt/local/src

groupadd www #添加www组

useradd -g www www -s /bin/false #创建Nginx运行账户www并加入到www组,不允许www用户直接登录系统

tar zxvf Nginx-1.4.4.tar.gz

cd Nginx-1.4.4

./configure --prefix=/opt/local/Nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/opt/local/src/pcre-8.31

注意:--with-pcre=/opt/local/src/pcre-8.34指向的是源码包解压的路径,而不是安装的路径,否则会报错

make

make install

/opt/local/Nginx/sbin/Nginx #启动Nginx

设置Nginx开启启动

vi /etc/rc.d/init.d/Nginx #编辑启动文件添加下面内容

=======================================================

#!/bin/bash# Nginx Startup script for the Nginx HTTP Server# it is v.0.0.2 version.# chkconfig: - 85 15# description: Nginx is a high-performance web and proxy server.# It has a lot of features,but it's not for everyone.# processname: Nginx# pidfile: /var/run/Nginx.pid# config: /usr/local/Nginx/conf/Nginx.conf

Nginxd=/opt/local/Nginx/sbin/Nginx

Nginx_config=/opt/local/Nginx/conf/Nginx.conf

Nginx_pid=/opt/local/Nginx/logs/Nginx.pid

RETVAL=0

prog="Nginx"

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ ${NETWORKING} = "no" ] && exit 0

[ -x $Nginxd ] || exit 0

# Start Nginx daemons functions.

start() {

if [ -e $Nginx_pid ];then

echo "Nginx already running...."

exit 1

fi

echo -n $"Starting $prog: "

daemon $Nginxd -c ${Nginx_config}

RETVAL=$?

echo

[ $RETVAL = 0 ] && touch /var/lock/subsys/Nginx

return $RETVAL

}

# Stop Nginx daemons functions.

stop() {

echo -n $"Stopping $prog: "

killproc $Nginxd

RETVAL=$?

echo

[ $RETVAL = 0 ] && rm -f /var/lock/subsys/Nginx /usr/local/Nginx/logs/Nginx.pid

}

reload() {

echo -n $"Reloading $prog: "

#kill -HUP `cat ${Nginx_pid}`

killproc $Nginxd -HUP

RETVAL=$?

echo

}

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

reload)

reload

;;

restart)

stop

start

;;

status)

status $prog

RETVAL=$?

;;

*)

echo $"Usage: $prog {start|stop|restart|reload|status|help}"exit1

esac

exit$RETVAL

=======================================================

:wq! #保存退出chmod775 /etc/rc.d/init.d/Nginx #赋予文件执行权限

chkconfig Nginx on #设置开机启动

/etc/rc.d/init.d/Nginx restart #重新启动Nginx

service Nginx restart

=======================================================


7、安装PHP

cd /opt/local/src

tar -zvxf PHP-5.5.7.tar.gz

cd PHP-5.5.7.

./configure --prefix=/opt/local/PHP5 --with-config-file-path=/opt/local/PHP5/etc --with-MysqL=/opt/local/MysqL --with-MysqL-sock=/tmp/MysqL.sock --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir


make #编译

make install #安装

cp PHP.ini-production /opt/local/PHP5/etc/PHP.ini #复制PHP配置文件到安装目录

rm -rf /etc/PHP.ini #删除系统自带配置文件

ln -s /opt/local/PHP5/etc/PHP.ini /etc/PHP.ini #添加软链接

cp /opt/local/PHP5/etc/PHP-fpm.conf.default /opt/local/PHP5/etc/PHP-fpm.conf #拷贝模板文件为PHP-fpm配置文件

vi /opt/local/PHP5/etc/PHP-fpm.conf #编辑

user = www #设置PHP-fpm运行账号为www

group = www #设置PHP-fpm运行组为www

pid = run/PHP-fpm.pid #取消前面的分号

设置 PHP-fpm开机启动

cp /opt/local/src/PHP-5.5.7/sapi/fpm/init.d.PHP-fpm /etc/rc.d/init.d/PHP-fpm #拷贝PHP-fpm到启动目录chmod +x /etc/rc.d/init.d/PHP-fpm #添加执行权限

chkconfig PHP-fpm on #设置开机启动

vi /opt/local/PHP5/etc/PHP.ini #编辑配置文件

找到:disable_functions =

修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用

找到:;date.timezone =

修改为:date.timezone = PRC #设置时区

找到:expose_PHP = On

修改为:expose_PHP = OFF #禁止显示PHP版本的信息

找到:short_open_tag = Off

修改为:short_open_tag = ON #支持PHP短标签


八、配置Nginx支持PHP

vi /opt/local/Nginx/conf/Nginx.conf

修改/opt/local/Nginx/conf/Nginx.conf 配置文件,需做如下修改

user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/opt/local/PHP/etc/PHP-fpm.conf中的user,group配置相同,否则PHP运行出错

user www www;

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

server {

listen80;

server_name localhost;

location / {

root html;

indexindex.PHP index.html index.htm;

}

location ~ \.PHP$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.PHP;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

}

}

/etc/init.d/Nginx restart #重启Nginx

六、测试篇

cd /opt/local/Nginx/html/ #进入Nginx默认网站根目录

rm -rf /opt/local/Nginx/html/* #删除默认测试页

vi index.PHP #新建index.PHP文件

PHPinfo();

?>

:wq! #保存退出chown www.www /opt/local/Nginx/html/ -R #设置目录所有者chmod700 /opt/local/Nginx/html/ -R #设置目录权限


七、其它说明

服务器相关操作命令

service Nginx restart #重启Nginx

service MysqLd restart #重启MysqL

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

/etc/rc.d/init.d/PHP-fpm restart #重启PHP-fpm

/etc/rc.d/init.d/PHP-fpm stop #停止PHP-fpm

/etc/rc.d/init.d/PHP-fpm start #启动PHP-fpm

Nginx默认站点目录是:/opt/local/Nginx/html/

权限设置:chown www.www /opt/local/Nginx/html/ -R

MysqL数据库目录是:/opt/local/MysqL/var

权限设置:chown MysqL.MysqL -R /opt/local/MysqL/var

八、安全优化

sherwin@rocnic~$ssh root@172.16.134.141

root@172.16.134.141's password:

Last login: Sat Jan 18 12:11:57 2014 from 172.16.134.1

-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

[root@dev01 ~]# locale

locale: Cannot set LC_CTYPE to default locale: No such file or directory

locale: Cannot set LC_ALL to default locale: No such file or directory

LANG=en_US.UTF-8

LC_CTYPE=UTF-8

LC_NUMERIC="en_US.UTF-8"

LC_TIME="en_US.UTF-8"

LC_COLLATE="en_US.UTF-8"

LC_MONETARY="en_US.UTF-8"

LC_MESSAGES="en_US.UTF-8"

LC_PAPER="en_US.UTF-8"

LC_NAME="en_US.UTF-8"

LC_ADDRESS="en_US.UTF-8"

LC_TELEPHONE="en_US.UTF-8"

LC_MEASUREMENT="en_US.UTF-8"

LC_IDENTIFICATION="en_US.UTF-8"

LC_ALL=

Centos 6 编译安装LNMP

Centos 6 编译安装LNMP

搭建环境:Centos 6.8,Nginx 1.9.14,MysqL 5.6.23,PHP 5.6.17

一、目的:LNMP如今已成为主流的web服务器搭建方案,公司内部的ECstore,discuz,计划用来替代nagios+check_mk监控平台的Zabbix。均基于LNMP。本次单机LNMP搭建为后续全面了解电商集群做准备,顺便记录搭建过程,作为以后搭建环境的参考。

二、LNMP安装环境准备:

关闭防火墙及selinux

serviceiptablesstop
chkconfigiptablesoff
setenforce0
vi/etc/sysconfig/selinux
SELINUX=disabled#enforcing改为disabled

依赖包安装

yum-yinstallgccgcc-c++autoconflibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develzlibzlib-develglibcglibc-develglib2glib2-develbzip2bzip2-develncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-develkrb5krb5-devellibidnlibidn-developensslopenssl-developenldapopenldap-developenldap-clientsopenldap-serversmakelibtool*gittreebisonpcre-develperlgdgd-devel

安装libiconv(支持编码转换为函数)

tarxflibiconv-1.14.tar.gz
cdlibiconv-1.14/
./configure--prefix=/usr/local
make&&makeinstall

安装libmcrypt (加密算法扩展库,支持DES,3DES,RIJNDAEL,Twofish,IDEA,GOST,CAST-256,ARCFOUR,SERPENT,SAFER+等算法)

tarxflibmcrypt-2.5.8.tar.gz
cdlibmcrypt-2.5.8
./configure
make&&makeinstall
cdlibltdl/
./configure--enable-ltdl-install#加载动态库
make&&makeinstall

安装mhash(Mhash是基于离散数学原理的不可逆向的PHP加密方式扩展库,其在默认情况下不开启。 mhash的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存)

tarxfmhash-0.9.9.9.tar.bz2
cdmhash-0.9.9.9
./configure
make&&makeinstall

安装mcript(mcrypt 是 PHP 里面重要的加密支持扩展库,Mcrypt扩展库可以实现加密解密功能,就是既能将明文加密,也可以密文还原。)

cd/usr/local/src
tarzxvfmcrypt-2.6.8.tar.gz
cdmcrypt-2.6.8/
exportLD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH#暂时生效
./configure
make&&makeinstall

亦可以通过以下两种方法增加库文件

ln-s/usr/local/lib/libmcrypt.la/usr/lib/libmcrypt.la
ln-s/usr/local/lib/libmcrypt.so/usr/lib/libmcrypt.so
ln-s/usr/local/lib/libmcrypt.so.4/usr/lib/libmcrypt.so.4
ln-s/usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8
ln-s/usr/local/lib/libmhash.a/usr/lib/libmhash.a
ln-s/usr/local/lib/libmhash.la/usr/lib/libmhash.la
ln-s/usr/local/lib/libmhash.so/usr/lib/libmhash.so
ln-s/usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2
ln-s/usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1
ln-s/usr/local/bin/libmcrypt-config/usr/bin/libmcrypt-config
vim/etc/ld.so.conf
/usr/local/lib/
ldconfig

安装cmake (MysqL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具)

tarxfcmake-3.4.1.tar.gz
cdcmake-3.4.1
./bootstrap
make&&makeinstall

注:一起解压所有文件可采用:find /usr/local/src/*.tar.gz -exec tar xf {} \;

三、MysqL编译安装

新增MysqL用户

groupadd-rMysqL
useradd-r-gMysqLMysqL

新建MysqL所需目录

mkdir-p/usr/local/MysqL
mkdir-p/data/MysqLdb

编译安装

tarxfmysql-5.6.23.tar.gz
cdmysql-5.6.23
cmake-DCMAKE_INSTALL_PREFIX=/usr/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-DMysqL_DATADIR=/data/MysqLdb-DMysqL_TCP_PORT=3306-DENABLE_DOWNLOADS=1-DSYSconfdIR=/etc-DWITH_SSL=system-DWITH_ZLIB=system-DWITH_LIBWRAP=0
make&&makeinstall

修改MysqL目录权限

cd/usr/local/MysqL
chown-RMysqL:MysqL.
cd/data/MysqLdb
chown-RMysqL:MysqL.

初始化MysqL数据库

cd/usr/local/MysqL
./scripts/MysqL_install_db--user=MysqL--datadir=/data/MysqLdb

编译修改/etc/my.cnf

[MysqL]

#CLIENT#
port=3306
socket=/data/MysqLdb/MysqL.sock

[MysqLd]

#GENERAL#
user=MysqL
default-storage-engine=InnoDB
socket=/data/MysqLdb/MysqL.sock
pid-file=/data/MysqLdb/MysqL.pid

#MyISAM#
key-buffer-size=32M
myisam-recover=FORCE,BACKUP

#SAFETY#
max-allowed-packet=16M
max-connect-errors=1000000

#DATASTORAGE#
datadir=/data/MysqLdb/

#BINARYLOGGING#
log-bin=/data/MysqLdb/MysqL-bin
expire-logs-days=14
sync-binlog=1

#REPLICATION#
skip-slave-start=1
relay-log=/data/MysqLdb/relay-bin
slave-net-timeout=60

#CACHESANDLIMITS#
tmp-table-size=32M
max-heap-table-size=32M
query-cache-type=0
query-cache-size=0
max-connections=500
thread-cache-size=50
open-files-limit=65535
table-deFinition-cache=4096
table-open-cache=4096

#INNODB#
innodb-flush-method=O_DIRECT
innodb-log-files-in-group=2
innodb-log-file-size=64M
innodb-flush-log-at-trx-commit=1
innodb-file-per-table=1
innodb-buffer-pool-size=592M

#LOGGING#
log-error=/data/MysqLdb/MysqL-error.log
log-queries-not-using-indexes=1
slow-query-log=1
slow-query-log-file=/data/MysqLdb/MysqL-slow.log

复制MysqL启动文件及其命令加入PATH

cpsupport-files/MysqL.server/etc/init.d/MysqLd
vim/etc/profile.d/MysqL.sh
PATH=/usr/local/MysqL/bin:/usr/local/MysqL/lib:$PATH
exportPATH
source/etc/profile.d/MysqL.sh

启动MysqL并增加启动项

serviceMysqLdstart
chkconfigMysqLdon

设置MysqL登录权限

dropuser''@localhost;
dropuser''@hostname;
updateMysqL.usersetpassword=password('*******');
flushprivileges;

四、Nginx编译安装

新增Nginx用户

groupadd-rNginx
useradd-gNginx-rNginx

创建所需要目录

mkdir-pv/var/tmp/Nginx/client

编译安装Nginx

tarxfNginx-1.9.14.tar.gz
cdNginx-1.9.14
./configure--prefix=/usr/local/Nginx--sbin-path=/usr/local/Nginx/sbin/Nginx--conf-path=/etc/Nginx/Nginx.conf--error-log-path=/var/log/Nginx/error.log--http-log-path=/var/log/Nginx/access.log--pid-path=/var/run/Nginx/Nginx.pid--lock-path=/var/lock/Nginx.lock--user=Nginx--group=Nginx--with-http_ssl_module--with-http_flv_module--with-http_stub_status_module--with-http_gzip_static_module--http-client-body-temp-path=/var/tmp/Nginx/client/--http-proxy-temp-path=/var/tmp/Nginx/proxy/--http-fastcgi-temp-path=/var/tmp/Nginx/fcgi/--http-uwsgi-temp-path=/var/tmp/Nginx/uwsgi--http-scgi-temp-path=/var/tmp/Nginx/scgi--with-pcre
make&&makeinstall

编辑启动脚本

vim/etc/rc.d/init.d/Nginx

#!/bin/sh
#
#Nginx-thisscriptstartsandstopstheNginxdaemon
#
#chkconfig:-8515
#description:NginxisanHTTP(S)server,HTTP(S)reverse\
#proxyandIMAP/POP3proxyserver
#processname:Nginx
#config:/etc/Nginx/Nginx.conf
#config:/etc/sysconfig/Nginx
#pidfile:/var/run/Nginx.pid

#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions

#Sourcenetworkingconfiguration.
./etc/sysconfig/network

#Checkthatnetworkingisup.
["$NETWORKING"="no"]&&exit0

Nginx="/usr/local/Nginx/sbin/Nginx"
prog=$(basename$Nginx)

Nginx_CONF_FILE="/etc/Nginx/Nginx.conf"

[-f/etc/sysconfig/Nginx]&&./etc/sysconfig/Nginx

lockfile=/var/lock/subsys/Nginx

make_dirs(){
#makerequireddirectories
user=`Nginx-V2>&1|grep"configurearguments:"|sed's/[^*]*--user=\([^]*\).*/\1/g'-`
options=`$Nginx-V2>&1|grep'configurearguments:'`
foroptin$options;do
if[`echo$opt|grep'.*-temp-path'`];then
value=`echo$opt|cut-d"="-f2`
if[!-d"$value"];then
#echo"creating"$value
mkdir-p$value&&chown-R$user$value
fi
fi
done
}

start(){
[-x$Nginx]||exit5
[-f$Nginx_CONF_FILE]||exit6
make_dirs
echo-n$"Starting$prog:"
daemon$Nginx-c$Nginx_CONF_FILE
retval=$?
echo
[$retval-eq0]&&touch$lockfile
return$retval
}

stop(){
echo-n$"Stopping$prog:"
killproc$prog-QUIT
retval=$?
echo
[$retval-eq0]&&rm-f$lockfile
return$retval
}

restart(){
configtest||return$?
stop
sleep1
start
}

reload(){
configtest||return$?
echo-n$"Reloading$prog:"
killproc$Nginx-HUP
RETVAL=$?
echo
}

force_reload(){
restart
}

configtest(){
$Nginx-t-c$Nginx_CONF_FILE
}

rh_status(){
status$prog
}

rh_status_q(){
rh_status>/dev/null2>&1
}

case"$1"in
start)
rh_status_q&&exit0
$1
;;
stop)
rh_status_q||exit0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q||exit7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q||exit0
;;
*)
echo$"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit2
esac

设置开机启动并启动服务

chmod+x/etc/rc.d/init.d/Nginx
chkconfig--addNginx
chkconfigNginxon
serviceNginxstart

五、PHP编译安装

解决PHP安装的库依赖关系

cp-frp/usr/lib64/libldaP*/usr/lib/
echo/usr/local/MysqL/lib>>/etc/ld.so.conf.d/MysqL-x86_64.conf
ldconfig-v

编译安装PHP

tarxfPHP-5.6.17.tar.gz
cdPHP-5.6.17
./configure--prefix=/usr/local/PHP--with-MysqL=/usr/local/MysqL--with-MysqLi=/usr/local/MysqL/bin/MysqL_config--with-iconv-dir=/usr/local--with-openssl--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr--enable-xml--disable-rpath--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--enable-mbregex--enable-mbstring--with-gd--enable-gd-native-ttf--with-mhash--enable-pcntl--enable-sockets--with-mcrypt--with-ldap--with-ldap-sasl--with-xmlrpc--enable-zip--enable-soap--with-bz2--with-config-file-path=/etc--enable-fpm--with-config-file-scan-dir=/etc/PHP.d--enable-maintainer-zts
makeZEND_EXTRA_LIBS='-liconv'
makeinstall

复制PHP配置文件

cpPHP.ini-production/etc/PHP.ini

复制PHP-fpm配置文件

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

设置PHP-fpm启动脚本并开机启动

cpsapi/fpm/init.d.PHP-fpm/etc/rc.d/init.d/PHP-fpm
chmod+x/etc/rc.d/init.d/PHP-fpm
chkconfig--addPHP-fpm
chkconfigPHP-fpmon
servicePHP-fpmstart

六、web功能基本实现

Nginx,PHP功能整合

vim/etc/Nginx/Nginx.conf
#location~\.PHP${
#roothtml;
#fastcgi_pass127.0.0.1:9000;
#fastcgi_indexindex.PHP;
#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
#includefastcgi_params;
#}
#修改为
location~\.PHP${
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.PHP;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}

增加LNMP测试页面

vim/usr/local/Nginx/html/test.PHP
<?PHP
$link=MysqL_connect('127.0.0.1','root','you_passwd');
if($link)
echo"It'sOK,Frank";
else
echo"Failed,Frank";
MysqL_close;
PHPinfo();
?>

Nginx重载

serviceNginxreload

访问http://ip/test.php,LNMP测试成功。

wKioL1dx2wWSYR_hAACjZ2PngIk856.png-wh_50

七、后记

从去年底开始,LAMP,LNMP断断续续搭建过多次,搭建时磕磕碰碰,完成后就会忘记,估计是基础不牢的原因。虽然本次搭建中间也有些许不顺,但决定写博文之后,还是有点小压力,前前后后验证了两遍,还是可以保证可行性的。本次Nginx,PHP的配置优化及插件均未涉及,后续博文中将陆续补上。

CentOS 6.10编译安装LNMP

CentOS 6.10编译安装LNMP

一、前期准备
1.服务器以最小化方式安装CentOS 6.9或CentOS 6.10
2.配置本地源及安装epel源
3.#yum install kernel kernel-devel,再重启服务器。 //升级内核
4.#yum update //系统升级。若为CentOS6.9,则升级后为CentOS 6.10
5.编译安装gcc-4.8.5, // 请参考https://blog.51cto.com/191226139/2066137
6.编译安装cmake-3.10.2,//请参考https://blog.51cto.com/191226139/2066186
7.安装ntpd时间服务器
8.Yum remove packages…
httpd httpd-tools MysqL MysqL-libs PHP-MysqL PHP-cli PHP-gd PHP-common PHP
特别执行#yum remove MysqL-libs //将删除crontabs,后面再安装crontabs,记得开启crond服务
9.Yum installing dependent packages…
flex bison file libtool libtool-ltdl autoconf kernel-devel patch wget crontabs libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel unzip tar bzip2 bzip2-devel libzip libzip-devel libevent libevent-devel ncurses ncurses-devel curl libcurl-devel libcurl e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal gettext gettext-devel gmp-devel pspell-devel libcap diffutils ca-certificates net-tools libc-client libc-client-devel psmisc libXpm-devel git c-ares-devel libicu-devel libxslt libxslt-devel xz expat-devel libaio-devel rpcgen libtirpc-devel perl bison bison-devel libcurl-devel libcurl libarchive-devel boost boost-devel lsof pcre pcre-devel
libmcrypt libmcrypt-devel libvpx mhash t1lib
二 编译安装LNMP
(一)编译安装Mariadb
1.安装依赖包
#yum install ncurses-devel libaio-devel openssl-devel -y
#cmake --version
cmake version 3.10.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
2.创建用于MysqL的组和账号
#groupadd -r MysqL
#useradd -r -g MysqL -s /sbin/nologin -M MysqL
3.编译安装mariadb
#cd /data/lnmpsoft

ls

mariadb-10.2.19.tar.gz

tar -zxvf mariadb-10.2.19.tar.gz -C /usr/local/src

#mkdir /usr/local/src/db-build
#mkdir /usr/local/mariadb-10.2.14
#chown root:root /usr/local/mariadb-10.2.14
#mkdir /var/run/MysqL
#chown MysqL:MysqL /var/run/MysqL
#cd /usr/local/src/db-build
#cmake /usr/local/src/mariadb-10.2.19
-DCMAKE_INSTALL_PREFIX=/usr/local/mariadb-10.2.19 \ -DMysqL_UNIX_ADDR=/var/run/MysqL/MysqL.sock
-DMysqL_TCP_PORT=3306
-DMysqL_USER=MysqL
-DDEFAULT_CHARSET=utf8mb4
-DDEFAULT_COLLATION=utf8mb4_general_ci
-DENABLED_LOCAL_INFILE=1
-DENABLE_DOWNLOADS=1
-DEXTRA_CHARSETS=all
-DSYSconfdIR=/etc
-DWITHOUT_TOKUDB=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MRG_MyISAM_STORAGE_ENGINE=1
-DWITH_CSV_STORAGE_ENGINE=1
-DWITH_SEQUENCE_STORAGE_ENGINE=1
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_ARIA_STORAGE_ENGINE=1
-DWITH_PERFORMANCE_SCHEMA_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DWITH_SSL=system
-DWITH_ZLIB=system
-DWITH_LOBWRAP=0
-DMysqL_MAINTAINER_MODE=0
-DWITH_DEBUG=0
此处为编译mariadb,可在MysqL-bianyi中复制。
#make && make install
#ln -s /usr/local/mariadb-10.2.19 /usr/local/MysqL
4.添加PATH至环境变量中
#echo ‘PATH=/usr/local/MysqL/bin:$PATH’ >> /etc/profile.d/MysqL.sh
检查文件
#cat /etc/profile.d/MysqL.sh
加载环境变量文件并检查
#source /etc/profile.d/MysqL.sh
#echo $PATH
检查MysqL版本
#MysqL -V
MysqL Ver 15.1 distrib 10.2.19-MariaDB, for Linux (x86_64) using readline 5.1
5.创建数据库存放文件夹并修改权限
#mkdir -pv /data/MysqLdb/3306/{log,data,pid,tmp}

chown -R MysqL:MysqL /data/MysqLdb/

chmod -R 770 /data/MysqLdb/

6.复制及修改配置文件my.cnf

cp /usr/local/MysqL/support-files/my-large.cnf /etc/my.cnf

vim /etc/my.cnf

[MysqLd]
port = 3306
socket = /var/run/MysqL/MysqL.sock
pid-file = /data/MysqLdb/3306/pid/MysqL.pid
datadir = /data/MysqLdb/3306/data
tmpdir = /data/MysqLdb/3306/tmp
innodb_file_per_table = 1
skip_name_resolve = 1
log-error = /data/MysqLdb/3306/log/error.log
7.安装数据库相关文件
#cd /usr/local/MysqL/
查看下安装程序的安装参数
#/usr/local/MysqL/scripts/MysqL_install_db --help

#./scripts/./MysqL_install_db --user=MysqL --basedir=/usr/local/mariadb-10.2.19 --datadir=/data/MysqLdb/3306/data
[Warning] ‘THREAD_CONCURRENCY’ is deprecated and will be removed in a future release.
OK

To start MysqLd at boot time you have to copy
support-files/MysqL.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

‘/usr/local/mariadb-10.2.19/bin/MysqLadmin’ -u root password ‘new-password’
‘/usr/local/mariadb-10.2.19/bin/MysqLadmin’ -u root -h dellcentos6.cqdzzx.cn password ‘new-password’

Alternatively you can run:
‘/usr/local/mariadb-10.2.19/bin/MysqL_secure_installation’

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the MariaDB KNowledgebase at http://mariadb.com/kb or the
MysqL manual for more instructions.

You can start the MariaDB daemon with:
cd ‘/usr/local/mariadb-10.2.19’ ; /usr/local/mariadb-10.2.19/bin/MysqLd_safe --datadir=’/data/MysqLdb/3306/data’

You can test the MariaDB daemon with mysql-test-run.pl
cd ‘/usr/local/mariadb-10.2.19/MysqL-test’ ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MysqL part at:
http://dev.mysql.com
Consider joining MariaDB’s strong and vibrant community:
https://mariadb.org/get-involved/
8.复制启动服务脚本至/etc/init.d目录并启动
#cp /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqLd
#chkconfig --add MysqLd
#chkconfig MysqLd on
#service MysqLd start
Starting MariaDB.190521 15:07:45 MysqLd_safe Logging to ‘/data/MysqLdb/3306/log/error.log’.
190521 15:07:45 MysqLd_safe Starting MysqLd daemon with databases from /data/MysqLdb/3306/data
SUCCESS!
9.进行安全配置
#/usr/local/MysqL/bin/MysqL_secure_installation

Enter current password for root 默认为空
Set root password 设置MysqL root密码
Remove anonymous users 是否移除匿名用户登录
disallow root login remotely 是否禁止root远程登录
Remove test database and access to it? 是否移除test数据和test账号
Reload privilege tables Now? 是否立即更新权限
Thanks for using MariaDB!
(二)编译安装Nginx
1.安装依赖包

yum install pcre pcre-devel openssl openssl-devel zlib zlib-devel

2.创建用于Nginx,PHP的组和账号

groupadd -r www

useradd -r -g www -s /sbin/nologin -M www

3.编译安装Nginx

mkdir -p /usr/local/Nginx

#chown root:root /usr/local/Nginx
#mkdir -pv /var/tmp/Nginx/{client_body_temp,proxy_temp,
fcgi_temp,uwsgi_temp,scgi_temp}
#cd /var/tmp

chown -R www:www /var/tmp/Nginx

#cd /usr/local/src/Nginx-1.14.0
#./configure
–prefix=/usr/local/Nginx
–user=www
–group=www
–with-http_stub_status_module
–with-http_ssl_module
–with-http_v2_module
–with-http_flv_module
–with-http_mp4_module
–with-http_gzip_static_module
–with-http_sub_module
–with-stream
–with-stream_ssl_module
–http-client-body-temp-path=/var/tmp/Nginx/client_body_temp/
–http-proxy-temp-path=/var/tmp/Nginx/proxy_temp/
–http-fastcgi-temp-path=/var/tmp/Nginx/fcgi_temp/
–http-uwsgi-temp-path=/var/tmp/Nginx/uwsgi_temp/
–http-scgi-temp-path=/var/tmp/Nginx/scgi_temp/
–with-openssl=
–with-pcre
4.加载环境变量文件并检查
echo ‘PATH=/usr/local/Nginx/sbin:$PATH’’>>/etc/profile.d/Nginx.sh
source /etc/profile.d/Nginx.sh
#Nginx -t
Nginx: the configuration file /usr/local/Nginx/conf/Nginx.conf Syntax is ok
Nginx: configuration file /usr/local/Nginx/conf/Nginx.conf test is successful
5.启动Nginx
#Nginx -c /usr/local/Nginx/conf/Nginx.conf
echo “/usr/local/Nginx/sbin/Nginx -c /usr/local/Nginx/conf/Nginx…conf”>>/etc/rc.d/rc.local //添加开机启动
6.iptables开启80端口
(三)编译安装PHP
1.安装依赖库
#yum install gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel libXpm-devel mhash libmcrypt libmcrypt-devel libvpx t1lib libicu-devel glibc
2.编译安装PHP-7.1.29
#cd /usr/local/src
#tar -zxvf PHP-7.1.29.tar.gz -C /usr/local/src
#mkdir /usr/local/PHP7
#cd /usr/local/src/PHP-7.1.29
#./configure --prefix=/usr/local/PHP7
–with-config-file-path=/usr/local/PHP7/etc
–with-config-file-scan-dir=/usr/local/PHP7/conf.d
–with-MysqL-sock=/var/run/MysqL/MysqL.sock
–enable-fpm
–with-fpm-user=www
–with-fpm-group=www
–enable-MysqLnd
–with-MysqLi=MysqLnd
–with-pdo-MysqL=MysqLnd
–with-iconv-dir=/usr/local/libiconv
–with-freetype-dir=
–with-jpeg-dir
–with-png-dir
–with-zlib
–with-libxml-dir=
–enable-xml
–disable-rpath
–enable-bcmath
–enable-shmop
–enable-sysvsem
–enable-inline-optimization
–with-curl
–enable-mbregex
–enable-mbstring
–enable-intl
–with-mcrypt
–enable-ftp
–with-gd
–enable-gd-native-ttf
–with-openssl
–with-mhash
–enable-pcntl
–enable-sockets
–with-xmlrpc
–enable-zip
–enable-soap
–with-gettext
–enable-opcache
–with-xsl
–enable-shared
–enable-libxml
–enable-session
–with-xpm-dir=

make && make install

3.配置PHP
⑴.cp /usr/local/src/PHP-7.1.29/PHP.ini-production /usr/local/PHP7/etc/PHP.ini
⑵.vim /usr/local/PHP7/etc/PHP.ini
①找到cgi.fix_pathinfo配置项并修改为0
cgi.fix_pathinfo=0
②找到 extension_dir 修改扩展目录位置并修改如下
extension_dir = “/usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20160303/”
③找到 timezone 修改时区如下:
date.timezone = PRC

PRC就是英文People’s Republic of China,中华人民共和国
④开启OPcache
跳转到文件的最后一行(shift+G), 输入以下内容:
zend_extension=opcache.so
⑤修改session的目录配置
#mkdir -p /var/lib/PHP7/session
#chown -R www:www /var/lib/PHP7/session

vim /usr/local/PHP7/etc/PHP.ini

找到 session.save_path 修改为如下内容:

session.save_path = “/var/lib/PHP7/session”
⑶添加PHP-fpm管理相关的配置文件到系统配置目录/etc/init.d
①# cp /usr/local/src/PHP-7.1.29/sapi/fpm/init.d.PHP-fpm /etc/init.d/PHP-fpm
#chmod 755 /etc/init.d/PHP-fpm
②cp /usr/local/PHP7/etc/PHP-fpm.conf.default /usr/local/PHP7/etc/PHP-fpm.conf
③cp /usr/local/PHP7/etc/PHP-fpm.d/www.conf.default
/usr/local/PHP7/etc/PHP-fpm.d/www.conf
⑷添加PHP系统环境变量

vim /etc/profile.d/PHP.sh

添加内容如下:

export PATH=PATH:/usr/local/php7/bin/:/usr/local/php7/sbin/PATH=/usr/local/php7/bin/:/usr/local/php7/sbin/PATH:/usr/local/php7/bin/:/usr/local/php7/sbin/或 PATH=/usr/local/php7/bin/:/usr/local/php7/sbin/:PATH:/usr/local/php7/bin/:/usr/local/php7/sbin/或PATH=/usr/local/php7/bin/:/usr/local/php7/sbin/:PATH

source /etc/profile.d/PHP.sh 使用source立即生效刚刚添加的PHP环境变量

⑸设置PHP开机启动
#chkconfig --add PHP-fpm
#chkconfig PHP-fpm on
#service PHP-fpm start

CentOS 6.4系统下编译安装LNMP和配置PHP环境具体步骤

CentOS 6.4系统下编译安装LNMP和配置PHP环境具体步骤

一、准备工作

上pkgs.org下载rmpforge。rpmforge是一个第三方yum源。

CentOS 6.4系统下编译安装LNMP和配置PHP环境

选择相应的版本下载安装。

// 安装成功后,清空yum list 并 重新获取

[root@pangou Desktop]# yum clean all

Loaded plugins: fastestmirror, refresh-packagekit, security

Cleaning repos: base extras rpmforge updates

Cleaning up Everything

Cleaning up list of fastest mirrors

[root@pangou Desktop]# yum -y list

Loaded plugins: fastestmirror, refresh-packagekit, security

Determining fastest mirrors

// ......

卸载已存在的apache服务和php

[root@pangou Desktop]# yum remove httpd php*

安装development Tools

[root@pangou Desktop]# yum -y groupinstall "Development Tools"

二、安装nginx

创建nginx目录,下载nginx,并解压缩

[root@pangou Downloads]# mkdir nginx

[root@pangou Downloads]# cd nginx/

[root@pangou nginx]# pwd

/root/Downloads/nginx

[root@pangou nginx]# wget http://nginx.org/download/nginx-1.4.0.tar.gz

--2013-04-30 23:13:44-- http://nginx.org/download/nginx-1.4.0.tar.gz

Resolving nginx.org... 206.251.255.63

Connecting to nginx.org|206.251.255.63|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 773451 (755K) [application/octet-stream]

Saving to: “nginx-1.4.0.tar.gz”

100%[================================================================>] 773,451 184K/s in 4.5s

2013-04-30 23:13:48 (166 KB/s) - “nginx-1.4.0.tar.gz” saved [773451/773451]

[root@pangou nginx]# ls

nginx-1.4.0.tar.gz

[root@pangou nginx]# tar -zxvf nginx-1.4.0.tar.gz

[root@pangou nginx]# ls

nginx-1.4.0 nginx-1.4.0.tar.gz

编译安装nginx

// 编译 安装路径/opt/nginx

[root@pangou nginx-1.4.0]# ./configure --prefix=/opt/nginx/

编译中如出现报错如:

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre= option.

就是用yum自行结局依赖关系

[root@pangou nginx-1.4.0]# yum install pcre pcre-devel

然后重新上面的编译

// 编译 安装路径/opt/nginx

[root@pangou nginx-1.4.0]# ./configure --prefix=/opt/nginx/

// 编译成功后

[root@pangou nginx-1.4.0]# make && make install

// 最后安装完成

启动nginx服务

[root@pangou nginx]# cd /opt/nginx/sbin/

[root@pangou sbin]# ./nginx

访问127.0.0.1

服务启动成功。

三、安装php

创建文件夹php,下载php,并解压缩

[root@pangou nginx-1.4.0]# cd /root/Downloads/

[root@pangou Downloads]# mkdir php

[root@pangou Downloads]# cd php/

[root@pangou php]# pwd

/root/Downloads/php

// 下载

[root@pangou php]# wget http://cn2.php.net/get/php-5.4.14.tar.gz/from/this/mirror

// 解压

[root@pangou php]# tar -zxvf php-5.4.14.tar.gz

安装依赖包

[root@pangou php]# yum install -y libxml2-devel libjpeg-devel libpng-devel freetype-devel openssl-devel libcurl-devel libmcrypt-devel

编译php

[root@pangou php]# ls

php-5.4.14 php-5.4.14.tar.gz

[root@pangou php]# cd php-5.4.14

[root@pangou php-5.4.14]# pwd

/root/Downloads/php/php-5.4.14

[root@pangou php-5.4.14]# ls

acinclude.m4 CREDITS ltmain.sh NEWS README.MAILINGLIST_RULES README.TESTING stamp-h.in

aclocal.m4 ext main pear README.namespaces README.TESTING2 stub.c

build EXTENSIONS makedist php5.spec.in README.NEW-OUTPUT-API README.UNIX-BUILD-SYSTEM svnclean.bat

buildconf footer Makefile.frag php.gif README.PARAMETER_PARSING_API README.WIN32-BUILD-SYSTEM tests

buildconf.bat generated_lists Makefile.gcov php.ini-development README.PHP4-TO-PHP5-THIN-CHANGES run-tests.php TSRM

CODING_STANDARDS genfiles Makefile.global php.ini-production README.REDIST.BINS sapi UPGRADING

config.guess header makerpm README.EXTENSIONS README.RELEASE_PROCESS scripts UPGRADING.INTERNALS

config.sub INSTALL missing README.EXT_SKEL README.SELF-CONTAINED-EXTENSIONS server-tests-config.php vcsclean

configure install-sh mkinstalldirs README.GIT-RULES README.STREAMS server-tests.php win32

configure.in LICENSE netware README.input_filter README.SUBMITTING_PATCH snapshot Zend

[root@pangou php-5.4.14]# ./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-mysql=/usr/ --with-mysqli=/usr/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic

// 编译时间可能有点长。。。

// 编译成功后,安装

[root@pangou php-5.4.14]# make && make install

// 安装时间也比较长

安装成功后,php的位置就应该在/opt/php目录下,接下去就是配置

// 复制配置文件到配置目录下

[root@pangou php-5.4.14]# cp /root/Downloads/php/php-5.4.14/php.ini-production /opt/php/etc/php.ini

[root@pangou php-5.4.14]# cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf

[root@pangou php-5.4.14]# cd /opt/php/etc/

[root@pangou etc]# ls

php-fpm.conf php-fpm.conf.default php.ini

// 然后配置nginx的配置文件,让其可以运行php

[root@pangou etc]# cd /opt/nginx/conf/

[root@pangou conf]# ls

fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf scgi_params uwsgi_params win-utf

fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default

[root@pangou conf]# vim nginx.conf

1、去掉 #user nobody; 的#号, 变成 user nobody;

2、去掉

#location ~ \.php$ {

# root html;

# fastcgi_pass 127.0.0.1:9000;

# fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

# include fastcgi_params;

#}

之前的#号,

并修改

复制代码 代码如下:

fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;


复制代码 代码如下:

[/cfastcgi_param SCRIPT_FILENAME /opt/nginx/html$fastcgi_script_name;
ode]
最终修改后的内容为:
[code]
location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /opt/nginx/html$fastcgi_script_name;

include fastcgi_params;

}



重启nginx服务,并开启php-fpm

[root@pangou ~]# /opt/nginx/sbin/nginx

[root@pangou ~]# /opt/php/sbin/php-fpm

// 创建phpinfo文件

[root@pangou ~]# vim /opt/nginx/html/phpinfo.php

内容为

复制代码 代码如下:

<?php  
phpinfo();
?>

访问http://127.0.0.1/phpinfo.php

安装成功。mysql,mysqli等扩展都有。

这边有一点偷懒,并没有编译安装mysql,而是使用yum安装的mysql。

您可能感兴趣的文章:

Centos 6.8编译安装LNMP环境(Nginx+MySQL+PHP)教程

Centos 6.8编译安装LNMP环境(Nginx+MySQL+PHP)教程

前言

对于新手的一点建议:

本篇安装的软件版本为:

最近研究了Linux系统下的PHP环境搭建,个人感觉最好最好不要用yum默认的程序包安装,因为版本都比较低,下载最新的稳定版自行安装比较好。现在网上教程很多,之所以还记这篇,原因有一点,当你重复网上的教程自行安装时,90%还是会出现各种各样的问题,因为你可能linux的系统版本不同,你想装的软件版本不同,安装的方法不同,你下错了安装包的版本,还有其它乱七八糟的。举个例,比如你看着5.6的MysqL安装教程,装5.7的,你感觉没问题,但是事实就是,5.7的不一样了!而且网上还没有新的这方面内容,不好找,这就需要你去摸索了,亲身经历啊。这里面,Niginx感觉最好配,MysqL最坑。

一 准备工作

1. 关闭SELINUX

修改配置文件,重启服务后永久生效。

# sed -i ‘s/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

命令行设置立即生效。

# setenforce 0

2. 如果是阿里云ECS用户,安全组设置中开启80端口方便调试。 

二 安装Nginx

1. 下载源码包

上Nginx官网,复制最新稳定版的下载地址过来,然后用wget下载(接下来需要下载安装包的都可以用wget):

# cd /usr/local/src
# wget http://Nginx.org/download/Nginx-1.10.3.tar.gz

下载完成的状态基本都是以下这样的:

2. 进行解压编译

# tar xvf Nginx-1.10.3.tar.gz
# yum groupinstall “Development tools”
# yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel

执行完成。

进入解压后的Nginx-1.10.3文件夹:

cd /usr/local/src/Nginx-1.10.3

执行以下语句:

./configure \
--prefix=/usr/local/Nginx \
--sbin-path=/usr/sbin/Nginx \
--conf-path=/etc/Nginx/Nginx.conf \
--error-log-path=/var/log/Nginx/error.log \
--http-log-path=/var/log/Nginx/access.log \
--pid-path=/var/run/Nginx.pid \
--lock-path=/var/run/Nginx.lock \
--http-client-body-temp-path=/var/tmp/Nginx/client \
--http-proxy-temp-path=/var/tmp/Nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/Nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/Nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/Nginx/scgi \
--user=Nginx \
--group=Nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module

完成后执行编译:

# make && make install
# mkdir -pv /var/tmp/Nginx/client

3. 添加SysV启动脚本。

用vim编辑脚本:

# vim /etc/init.d/Nginx

写入以下内容:

#!/bin/sh 
# 
# Nginx - this script starts and stops the Nginx daemon 
# 
# chkconfig: - 85 15 
# description: Nginx is an HTTP(S) server,HTTP(S) reverse \ 
#  proxy and IMAP/POP3 proxy server 
# processname: Nginx 
# config: /etc/Nginx/Nginx.conf 
# config: /etc/sysconfig/Nginx 
# pidfile: /var/run/Nginx.pid 
# Source function library. 
. /etc/rc.d/init.d/functions
# Source networking configuration. 
. /etc/sysconfig/network
# Check that networking is up. 
[ "$NETWORKING" = "no" ] &amp;amp;amp;&amp;amp;amp; exit 0
Nginx="/usr/sbin/Nginx"
prog=$(basename $Nginx)
Nginx_CONF_FILE="/etc/Nginx/Nginx.conf"
[ -f /etc/sysconfig/Nginx ] &amp;amp;amp;&amp;amp;amp; . /etc/sysconfig/Nginx
lockfile=/var/lock/subsys/Nginx
start() {
 [ -x $Nginx ] || exit 5
 [ -f $Nginx_CONF_FILE ] || exit 6
 echo -n $"Starting $prog: " 
 daemon $Nginx -c $Nginx_CONF_FILE
 retval=$?
 echo 
 [ $retval -eq 0 ] &amp;amp;amp;&amp;amp;amp; touch $lockfile
 return $retval
}
stop() {
 echo -n $"Stopping $prog: " 
 killproc $prog -QUIT
 retval=$?
 echo 
 [ $retval -eq 0 ] &amp;amp;amp;&amp;amp;amp; rm -f $lockfile
 return $retval
killall -9 Nginx
}
restart() {
 configtest || return $?
 stop
 sleep 1
 start
}
reload() {
 configtest || return $?
 echo -n $"Reloading $prog: " 
 killproc $Nginx -HUP
RETVAL=$?
 echo 
}
force_reload() {
 restart
}
configtest() {
$Nginx -t -c $Nginx_CONF_FILE
}
rh_status() {
 status $prog
}
rh_status_q() {
 rh_status &amp;amp;gt;/dev/null 2&amp;amp;gt;&amp;amp;amp;1
}
case "$1" in
 start)
 rh_status_q &amp;amp;amp;&amp;amp;amp; exit 0
 $1
 ;;
 stop)
 rh_status_q || exit 0
 $1
 ;;
 restart|configtest)
 $1
 ;;
 reload)
 rh_status_q || exit 7
 $1
 ;;
 force-reload)
 force_reload
 ;;
 status)
 rh_status
 ;;
 condrestart|try-restart)
 rh_status_q || exit 0
  ;;
 *)
 echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
 exit 2
esac

保存退出(按:wq!);可能你得稍微查一下vim的一些命令,不然操作时可能会出现一点小问题。

赋予脚本执行权限:

# chmod +x /etc/init.d/Nginx

添加至服务管理列表,设置开机自启:

# chkconfig Cadd Nginx
# chkconfig Nginx on

4. 启动服务。

# service Nginx start

出现这玩意说明成功了!

注:如果报错 [emerg]: getpwnam(“Nginx”) Failed ;

解决方法:

# useradd -s /sbin/nologin -M Nginx
# id Nginx

三 安装MysqL

1. 版本选择

在安装之前必须明白一件事情,MysqL有很多种安装方式,每种不一样,不要弄混了。

比如源码编译安装(MysqL-5.7.17.tar.gz),二进制安装(MysqL-5.7.17-linux-glibc2.5-i686.tar),nmp安装(最简单的)。这里我们用源码自己编译安装。

2. 准备编译环境

# yum groupinstall “Server Platform Development” “Development tools” -y
# yum install cmake -y

cmake在现在的版本是必须要安装的,你可以下载camke之后编译,也可以直接yum安装。接下来的编译过程如果报错缺少什么就补什么。

3. 准备MysqL数据库存放目录

# mkdir /mnt/data
# groupadd -r MysqL
# useradd -r -g MysqL -s /sbin/nologin MysqL
# id MysqL

4. 更改数据目录权限。

# chown -R MysqL:MysqL /mnt/data

5. 下载并解压编译官网下载的稳定版的源码包。

在下载的时候注意一下版本,下载对应的版本。我们源码编译,要下载长这样的安装包:MysqL-5.7.17.tar.gz,同时在安装的时候我们需要boost库,5.7需要1.59版本的库;你可以下载boost库然后编译boost库,或者像我一样,下载带有boost库的MysqL版本。

开始解压编译:

# tar xvf MysqL-boost-5.7.17.tar.gz -C /usr/local/src
# cd /usr/local/src/MysqL-5.7.17
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/MysqL \
-DMysqL_DATADIR=/mnt/data \
-DSYSconfdIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMysqL_TCP_PORT=3306 \
-DMysqL_UNIX_ADDR=/tmp/MysqL.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/MysqL/boost/boost_1_59_0 \
# make && make install

6. 修改安装目录的权限属组

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

7. 初始化数据库。

# /usr/local/MysqL/bin/MysqLd Cinitialize Cuser=MysqL Cbasedir=/usr/local/MysqL Cdatadir=/mnt/data/

需要注意这里是MysqL5.7的初始化命令,而5.7以下的都是用:

# /usr/local/MysqL/scripts/MysqL_install_db Cuser=MysqL Cdatadir=/mnt/data/

在初始化成功之后,5.7的initial命令会产生一个随机的root登录密码,你要用这个密码登录,然后修改(必须修改生成的随机密码不然无法后续操作)。在最后有一个类似这样的密码:

8. 复制配置文件

# cp support-files/my-default.cnf /etc/my.cnf

这里又有一点要注意:MysqL5.7配置文件需要修改my.cnf关键配置, MysqL5.7之前默认配置文件中是有配置项的,不用手动修改。以下为配置,根据实际情况修改:

</div>
<div>[MysqLd]</div>
<div>basedir = /usr/local/MysqL</div>
<div>datadir = /mnt/data</div>
<div>port = 3306</div>
<div>socket = /Ultrapower/test/MysqL/tmp/MysqL.sock</div>
<div></div>
<div>sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES</div>
<div>[client]</div>
<div>socket = /Ultrapower/test/MysqL/tmp/MysqL.sock</div>
<div>

如果添加[client]下 的内容,注意sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES要放在[MysqLd]下。
如果报错tmp目录不错在,到对应的地方去创建目录,然后创建后要赋予MysqL权限,chown -R MysqL:MysqL tmp。

9. 设置开机启动

# cp /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqLd
# chmod +x /etc/init.d/MysqL

注册为开机启动服务:

# chkconfig MysqLd on
# chkconfig Cadd MysqLd

查看是否设置成功:

# chkconfig Clist MysqL

10. 设置PATH环境变量。

# echo “export PATH=$PATH:/usr/local/MysqL/bin” > /etc/profile.d/MysqL.sh
# source /etc/profile.d/MysqL.sh

11. 启动服务

# service MysqLd start

这样基本上,这个MysqL就装好了。

12. 登录MysqL并修改密码

MysqL -uroot -p生成的密码

执行修改密码:

alter user ‘root'@'localhost' identified by ‘newpassword';

四 安装PHP-fpm

1. 安装依赖包:

yum install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel

这里还漏了几个,如果报错了提示缺少了什么就yum补上。

2. 到官网下载源码包后,开始编译安装:

# tar xvf PHP-7.0.16.tar.bz2 -C /usr/local/src
# cd /usr/local/src/PHP-7.0.16
执行下面的配置文件:
# ./configure --prefix=/usr/local/PHP \
--with-config-file-scan-dir=/etc/PHP.d \
--with-config-file-path=/etc \
--with-MysqL=/usr/local/MysqL \
--with-MysqLi=/usr/local/MysqL/bin/MysqL_config \
--enable-fpm \
--enable-opcache \
--disable-fileinfo \
--with-jpeg-dir \
--with-iconv-dir=/usr/local \
--with-freetype-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-exif \
--with-curl \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-inline-optimization \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-ftp \
--with-gettext \
--enable-zip \
--enable-soap \
--with-bz2

执行以上的配置,如果出现下面这样的license,才是正确的,才可以开始编译,如果出问题,就解决,一般是少了什么库。


执行编译:

# make && make install

3. 添加PHP和PHP-fpm配置文件。

# cp /usr/local/src/PHP-7.0.16/PHP.ini-production /etc/PHP.ini
# cd /usr/local/PHP/etc/
# cp PHP-fpm.conf.default PHP-fpm.conf
# sed -i ‘s@;pid = run/PHP-fpm.pid@pid = /usr/local/PHP/var/run/PHP-fpm.pid@' PHP-fpm.conf

4. 添加PHP-fpm启动脚本。

# cp /usr/local/src/PHP-7.0.16/sapi/fpm/init.d.PHP-fpm /etc/init.d/PHP-fpm
# chmod +x /etc/init.d/PHP-fpm

5. 添加PHP-fpm至服务列表并设置开机自启。

# chkconfig Cadd PHP-fpm
# chkconfig Clist PHP-fpm
# chkconfig PHP-fpm on

6. 启动服务。

# service PHP-fpm start

注:启动时如出现错误:

WARNING: nothing matches the include pattern ‘/usr/local/etc/PHP-fpm.d/*.conf' from /usr/local/etc/PHP-fpm.conf at line 125.
ERROR:. No pool defined at least one pool section must be specified in config file
ERROR: Failed to post process the configuration
ERROR: FPM initialization Failed

解决:到指定目录执行cp www.conf.default www.conf

7. 添加Nginx对fastcgi的支持,

首先备份默认的配置文件。

# cp /etc/Nginx/Nginx.conf /etc/Nginx/Nginx.confbak

# cp /etc/Nginx/Nginx.conf.default /etc/Nginx/Nginx.conf

编辑/etc/Nginx/Nginx.conf,在所支持的主页面格式中添加PHP格式的主页,类似如下:

</div>
<div>location / {</div>
<div>root /usr/local/Nginx/html;</div>
<div>index index.PHP index.html index.htm;</div>
<div>}</div>
<div>

取消以下内容前面的注释:

</div>
<div>location ~ \.PHP$ {</div>
<div>root /usr/local/Nginx/html;</div>
<div>fastcgi_pass 127.0.0.1:9000;</div>
<div>fastcgi_index index.PHP;</div>
<div>fastcgi_param SCRIPT_FILENAME /usr/local/Nginx/html/$fastcgi_script_name;</div>
<div>include fastcgi_params;</div>
<div>}</div>
<div>

8. 重启Nginx

# service Nginx reload

9. 测试是否成功

在/usr/local/Nginx/html/新建index.PHP的测试页面,内容如下:

<?PHP
PHPinfo();
?>

如果出现这个熟悉的界面,说明就大功告成了!Linux下一个基本的LNMP就搭建完毕了。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对编程小技巧的支持。

您可能感兴趣的文章:

关于Centos生产环境编译安装LNMPcentos7安装lnmp环境的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于Centos 6 编译安装LNMP、CentOS 6.10编译安装LNMP、CentOS 6.4系统下编译安装LNMP和配置PHP环境具体步骤、Centos 6.8编译安装LNMP环境(Nginx+MySQL+PHP)教程的相关信息,请在本站寻找。

本文标签:

上一篇centos 忘记root密码解决办法(centos忘记root密码的解决办法)

下一篇Create a virtualbox Based CentOS 6 OpenStack Cloud Image