一、前言
1、环境说明
linux:7.2
Nginx:1.10.2
MysqL:5.6.17
PHP:5.5.12
2、部署说明
PHP.ini配置文件路径:/usr/local/PHP/etc/PHP.ini
Nginx配置文件路径:/etc/Nginx/Nginx.conf
Nginx网站根目录:/usr/local/Nginx/html
二、准备工作
1、最小化安装Centos7.2
#建立一个软件包目录存放 mkdir-p/usr/local/src/ #清理已经安装包 rpm-ehttpd rpm-eMysqL rpm-ePHP yum-yremovehttpd yum-yremoveMysqL yum-yremovePHP #搜索apache包 rpm-qahttp* #强制卸载apache包 rpm-e--nodeps查询出来的文件名 #检查是否卸载干净 rpm-qa|grephttp*
selinux可能会致使编译安装失败,我们先禁用它。
永久禁用,需要重启生效
sed-i's/SELINUX=enforcing/SELINUX=disabled/g'/etc/selinux/config
@H_301_52@临时禁用,不需要重启
setenforce0
2、安装必备工具
yum-yinstallmakegccgcc-c++gcc-g77flexbisonfilelibtoollibtool-libsautoconfkernel-devellibjpeglibjpeg-devellibpnglibpng-devellibpng10libpng10-develgdgd-develfreetypefreetype-devellibxml2libxml2-develzlibzlib-develglib2glib2-develbzip2bzip2-devellibeventlibevent-develncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-develkrb5krb5-devellibidnlibidn-developensslopenssl-develgettextgettext-develncurses-develgmp-develpspell-develunziplibcaplsof
三、安装MysqL5.6.17
1、准备工作
#创建群组 groupaddMysqL #创建一个用户,不允许登陆和不创主目录 useradd-s/sbin/nologin-gMysqL-MMysqL #检查刚创建的用户 tail-1/etc/passwd
centos最小化安装后,会有MysqL的库因此先卸载!
#检查安装与否 rpm-qa|grepMysqL #强制卸载 rpm-erpm-eMysqL-libs-5.1.73-3.el6_5.x86_64--nodeps
MysqL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具。因此,我们首先要在系统中源码编译安装cmake工具。
wgethttp://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz tarzxvfcmake-2.8.12.2.tar.gz cdcmake-2.8.12.2 ./configure make&&makeinstall
2、使用cmake来编译安装MysqL 5.6.17
wgethttp://dev.MysqL.com/get/Downloads/MysqL-5.6/MysqL-5.6.17.tar.gz tarzxvfMysqL-5.6.17.tar.gz cdMysqL-5.6.17 cmake\ -DCMAKE_INSTALL_PREFIX=/usr/local/MysqL\ -DMysqL_DATADIR=/usr/local/MysqL/data\ -DSYSCONFDIR=/etc\ -DWITH_MYISAM_STORAGE_ENGINE=1\ -DWITH_INNOBASE_STORAGE_ENGINE=1\ -DWITH_MEMORY_STORAGE_ENGINE=1\ -DWITH_READLINE=1\ -DMysqL_UNIX_ADDR=/var/lib/MysqL/MysqL.sock\ -DMysqL_TCP_PORT=3306\ -DENABLED_LOCAL_INFILE=1\ -DWITH_PARTITION_STORAGE_ENGINE=1\ -DEXTRA_CHARSETS=all\ -DDEFAULT_CHARSET=utf8\ -DDEFAULT_COLLATION=utf8_general_ci\ -DMysqL_USER=MysqL\ -DWITH_DEBUG=0\ -DWITH_SSL=system make&&makeinstall #修改/usr/local/MysqL权限 chmod+w/usr/local/MysqL chown-RMysqL:MysqL/usr/local/MysqL
关于my.cnf配置文件:
在启动MysqL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索”$basedir/my.cnf”就是安装目录下/usr/local/MysqL/my.cnf,这是新版MysqL的配置文件的默认位置!注意:在最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字。如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MysqL的正确配置,造成无法启动。由于我们已经卸载了最小安装完成后的MysqL库所以,就没必要操作了。
cdsupport-files/ #如果还有my.cnf请备份 mv/etc/my.cnf/etc/my.cnf.bak cpmy-default.cnf/etc/my.cnf #执行初始化配置脚本,创建系统自带的数据库和表,注意配置文件的路径 /usr/local/MysqL/scripts/MysqL_install_db--defaults-file=/etc/my.cnf--basedir=/usr/local/MysqL--datadir=/usr/local/MysqL/data--user=MysqL #拷贝MysqL安装目录下support-files服务脚本到init.d目录 cpsupport-files/MysqL.server/etc/init.d/MysqLd #赋予权限、设置开机自启并启动 chmod+x/etc/init.d/MysqLd chkconfigMysqLdon serviceMysqLdstart #或者 /etc/init.d/MysqLstart
MysqL5.6.x启动成功后,root默认没有密码,我们需要设置root密码。设置之前,我们需要先设置PATH,否则不能直接调用MysqL
#修改/etc/profile文件 vim/etc/profile #在文件末尾添加 PATH=/usr/local/MysqL/bin:$PATH exportPATH #让配置立即生效 source/etc/profile #登陆测试,默认是没有密码,直接回车就可进入 MysqL-uroot-p #设置MysqL密码 /usr/local/MysqL/bin/MysqLadmin-uroot-ppassword'你的密码' #登陆进命令行模式 MysqL-uroot-p #查看用户 >selectuser,hostfromMysqL.user; #删除不必要的用户 >dropuser""@localhost; >dropuserroot@'::1'; #赋予账号远程访问的权限 >GRANTALLPRIVILEGESON*.*TO'root'@'127.0.0.1'IDENTIFIEDBY'你的密码'; >GRANTALLPRIVILEGESON*.*TO'root'@'localhost'IDENTIFIEDBY'你的密码'; #其它一些信息查询: #检查MysqL版本 MysqL-uroot-p"密码"-e"selectversion();"
MysqL安装完毕!
四、安装PHP5.5.12
1、安装依赖关系
yuminstalllibmcryptlibmcrypt-develmcryptmhash
2、下载并编译安装PHP
wgethttp://mirrors.sohu.com/PHP/PHP-5.5.12.tar.gz tarzxvfPHP-5.5.12.tar.gz cdPHP-5.5.12 ./configure--prefix=/usr/local/PHP--with-config-file-path=/usr/local/PHP/etc--enable-fpm--with-fpm-user=www--with-fpm-group=www--with-MysqL=MysqLnd--with-MysqLi=MysqLnd--with-pdo-MysqL=MysqLnd--with-iconv-dir--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr--enable-xml--disable-rpath--enable-magic-quotes--enable-safe-mode--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--with-curl--with-curlwrappers--enable-mbregex--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--disable-fileinfo--enable-maintainer-zts make&&makeinstall
下面的警告说明已自带不需启用或安装,可忽略:
继续:
#修改fpm配置PHP-fpm.conf.default文件名称 mv/usr/local/PHP/etc/PHP-fpm.conf.default/usr/local/PHP/etc/PHP-fpm.conf #复制PHP.ini配置文件 cpPHP.ini-production/usr/local/PHP/etc/PHP.ini #复制PHP-fpm启动脚本到init.d cpsapi/fpm/init.d.PHP-fpm/etc/init.d/PHP-fpm #赋予执行权限 chmod+x/etc/init.d/PHP-fpm #添加为启动项 chkconfig--addPHP-fpm #设置开机启动 chkconfigPHP-fpmon #按照标准,给PHP-fpm创建一个指定的用户和组 #创建群组 groupaddwww #创建一个用户,不允许登陆和不创主目录 useradd-s/sbin/nologin-gwww-Mwww #立即启动PHP-fpm /etc/init.d/PHP-fpmstart
PHP安装完毕!
五、安装Nginx1.10.2
1、准备工作
#添加用户与属组 groupadd-rNginx useradd-s/sbin/nologin-gNginx-MNginx #创建目录 mkdir-pv/var/tmp/Nginx/client/ #解压安装包 tarzxvfNginx-1.10.2.tar.gz
2、编译安装
./configure\ --prefix=/usr/local/Nginx\ --sbin-path=/usr/local/Nginx/bin/Nginx\ --conf-path=/usr/local/Nginx/conf/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
敲黑板:注意sbin、conf、pid、local的path要和后续的控制脚本保持一致!
make&&makeinstall
3、为Nginx提供SysV init脚本
cat/etc/init.d/Nginx
#!/bin/sh # # Nginx - this script starts and stops the Nginx daemin # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server,HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: Nginx # config: /usr/local/Nginx/conf/Nginx.conf # pidfile: /run/Nginx/Nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 prog=$(basename $Nginx) Nginx_CONF_FILE="/usr/local/Nginx/conf/Nginx.conf " lockfile=/var/lock/Nginx.lock 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 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT [ $retval -eq 0 ] && rm -f $lockfile restart() { configtest || return $? stop start reload() { echo -n $"Reloading $prog: " killproc $Nginx -HUP RETVAL=$? force_reload() { restart configtest() { rh_status() { status $prog rh_status_q() { rh_status >/dev/null 2>&1 case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 restart|configtest) reload) rh_status_q || exit 7 force-reload) force_reload status) rh_status condrestart|try-restart) *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac |
类似的脚本网上很多,注意config、pid、sbin的路径保持和编译一致即可。
chmod+x/etc/init.d/Nginx chkconfig--addNginx chkconfigNginxon #然后就可以启动服务了 systemctlrestartNginx.service #或 /etc/init.d/Nginxstart
1、编辑Nginx.conf,启用如下选项:
cd/usr/local/Nginx/conf/ catNginx.conf
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; } |
2、编辑/etc/Nginx/fastcgi_params,将其内容更改为如下内容:
#mvfastcgi_paramsfastcgi_params.bak #catfastcgi_params
fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE Nginx; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; |
location/{ roothtml; indexindex.PHPindex.htmlindex.htm; } |
#重新载入配置 #/etc/init.d/Nginxreload
3、在/usr/local/Nginx/html目录下新建index.PHP测试页面
cat>/usr/local/nignx/htmlindex.PHP<<EOF
PHPinfo(); ?> |
可通过浏览器 访问此测试页面,验证Nginx连接PHP配置是否成功。页面应该如下图
至此CenOS72下LNMP编译安装完毕!
原文链接:https://www.f2er.com/centos/379382.html