CentOS7.2编译安装LNMP(2)

#修改/etc/profile文件 
vim /etc/profile 
#在文件末尾添加 
PATH=/usr/local/mysql/bin:$PATH 
export PATH 
#让配置立即生效 
source /etc/profile 
#登陆测试,默认是没有密码,直接回车就可进入 
mysql -uroot -p 
#设置mysql密码 
/usr/local/mysql/bin/mysqladmin -uroot -p password '你的密码' 
#登陆进命令行模式 
mysql -uroot -p 
#查看用户 
>select user,host from mysql.user; 
#删除不必要的用户 
>drop user ""@localhost;
> drop user root@'::1';
#赋予账号远程访问的权限
>GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY '你的密码';
>GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '你的密码';
#其它一些信息查询:
#检查mysql版本 
mysql -uroot -p"密码" -e "select version();"

MySQL安装完毕!

四、安装PHP5.5.12

1、安装依赖关系

yum install libmcrypt libmcrypt-devel mcrypt mhash

2、下载并编译安装php

wget  
tar zxvf php-5.5.12.tar.gz 
cd php-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 && make install

下面的警告说明已自带不需启用或安装,可忽略:

CentOS7.2编译安装LNMP

继续:

#修改fpm配置php-fpm.conf.default文件名称 
mv /usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf 
#复制php.ini配置文件 
cp php.ini-production /usr/local/php/etc/php.ini 
#复制php-fpm启动脚本到init.d 
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 
#赋予执行权限 
chmod +x /etc/init.d/php-fpm 
#添加为启动项 
chkconfig --add php-fpm 
#设置开机启动 
chkconfig php-fpm on 
#按照标准,给php-fpm创建一个指定的用户和组 
#创建群组 
groupadd www 
#创建一个用户,不允许登陆和不创主目录 
useradd -s /sbin/nologin -g www -M www 
#立即启动php-fpm 
/etc/init.d/php-fpm start

PHP安装完毕!

五、安装Nginx1.10.2

1、准备工作

#添加用户与属组
groupadd -r nginx 
useradd -s /sbin/nologin -g nginx -M nginx
#创建目录
mkdir -pv /var/tmp/nginx/client/ 
#解压安装包
tar zxvf nginx-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 && make install

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

nginx="/usr/sbin/nginx"

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=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

configtest || return $?

stop

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/null 2>&1

}

case "$1" in

start)

rh_status_q && 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

类似的脚本网上很多,注意config、pid、sbin的路径保持和编译一致即可。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/e54775338f9708dad95f758280dd6ae5.html