centos下lnmp环境配置

6 篇文章 0 订阅

网上各种方法要么不全,要么不太符合需求,根据网上方案自己提炼结合出来的一套配置环境方法。
安装GCC编译器、PCRE库、zlib库、OpenSSL开发库

yum install -y gcc
yum install -y gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

获得并解压Nginx对应的tar包

获得Nginx对应的tar包
wget http://nginx.org/download/nginx-1.11.9.tar.gz
解压tar包
tar zxvf nginx-1.11.9.tar.gz

进入解压文件夹,运行configure文件,对nginx进行编译前的配置

cd nginx-1.11.9/
sudo ./configure --with-http_ssl_module
make && make install

进入nginx目录启动nginx

cd /use/local/nginx/sbin
启动nginx
./nginx

配置防火墙

允许相应的端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=9000/tcp --permanent
重新载入配置
firewall-cmd --reload

阿里云还需要去控制台下的安全组配置->配置规则->入方向允许访问,能访问到nginx即安装成功
在这里插入图片描述
在etc/init.d目录下创建一个启动脚本,通过这个脚本来启动Nginx

在etc/init.d目录下创建nginx脚本
vim /etc/init.d/nginx

然后将下面内容复制并保存到这个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:    /usr/local/nginx/logs/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/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

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 ] && 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
接着为这个脚本添加执行权限
chmod +x /etc/init.d/nginx
并将Nginx添加到系统自启动组中
chkconfig --add /etc/init.d/nginx
最后将开启自启动
chkconfig nginx on
启动nginx
systemctl start nginx.service
停止
systemctl stop nginx.service
重启
systemctl reload nginx.service

安装mysql

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
//启动mysql
systemctl start  mysqld.service
//获得一个随机mysql密码
grep "password" /var/log/mysqld.log
//登录mysql
mysql -uroot -p
//输入随机密码后,修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
//这里会报策略错误,因为密码太简单,改一下策略重新修改密码
set global validate_password_policy=0;
set global validate_password_length=1;
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
//最后把这个卸载掉
yum -y remove mysql57-community-release-el7-10.noarch
//重启mysql
systemctl restart mysqld

yum自带php为5.4,需要升级

//检查是否有老版本
yum list installed | grep php
//有就删除
yum remove php*
//更改yum源:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
//查看是否存在7.x的php
yum search php7
//安装各种拓展,选择自己需要的即可
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml

完成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值