码迷,mamicode.com
首页 > 其他好文 > 详细

centos7.4 搭建lnmp

时间:2018-01-29 15:38:04      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:iptable   添加   -shared   status   nmp   mbr   usr   配置nginx   mysqli   

系统:阿里云 centos7.4

Php:PHP 7.1.13 (cli) 

Mysql:mysql5.7

Nginx:nginx/1.12.2

 

一、更新centos7 yum源

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
wget http://mirrors.aliyun.com/repo/Centos-7.repo

yum clean all
yum makecache
yum -y update
yum -y install gcc* #安卓gcc组件
yum -y install vim

二 、firwall 替换成iptables

//关闭默认防火墙
#停止firewall
systemctl stop firewalld.service 
#禁止firewall开机启动
systemctl disable firewalld.service 
#查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
firewall-cmd --state 
//安装iptables
yum install  -y iptables  iptables-services
// 查看iptables配置文件
iptables -L  
// 配置里面的规则 -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT 
vim /etc/sysconfig/iptables
#添加
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
#开启
service iptables start 
#设置防火墙开机启动
systemctl enable iptables.service 
#查看iptables状态
service iptables status      
#iptables服务重启
service iptables restart     
#iptables服务禁用 
service iptables stop    

三、安装Nginx

#安装nginx源【centos7.4 yum安装默认的Nginx为1.12.2】
yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm  
#安装
yum install nginx
service nginx start  
 
在浏览器输入ip查看
 

四、安装mysql

#安装mysql源  
yum localinstall  http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm  
#安装mysql
yum install mysql-community-server  
#安装mysql的开发包
yum install mysql-community-devel  
#启动mysql
service mysqld start  
#查看mysql启动状态
service mysqld status 

五、安装php

#下载安装包
wget  http://cn2.php.net/get/php-7.1.13.tar.gz
#解压安装包
tar zxvf  php-7.1.13.tar.gz
cd php-7.1.13
#创建PHP安装目录
mkdir -m 777  /usr/local/php
#安装PHP依赖

 ./configure --prefix=/usr/local/php --exec-prefix=/usr/local/php --bindir=/usr/local/php/bin --sbindir=/usr/local/php/sbin --includedir=/usr/local/php/include --libdir=/usr/local/php/lib/php --mandir=/usr/local/php/php/man --with-config-file-path=/usr/local/php/etc --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mcrypt=/usr/include --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-redis --enable-fpm --enable-fastcgi --with-fpm-user=www --with-fpm-group=www --without-gdbm --disable-fileinfo
#会提示一些错误
configure: WARNING: unrecognized options: --with-mysql, --enable-fastcgi
#编译【编译的时间比较长】 
make
#测试安装【可以省略】
make test
#安装
make install
#查看
php -v 

六、配置Nginx支持PHP

 

#添加用户组、用户
groupadd www #添加mysql组
useradd -g www www -s /bin/false #添加的用户直接登录系统

#直接使用编译后未经优化处理的配置
cp /usr/local/src/php-7.1.13/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
cp /usr/local/src/php-7.1.13/sapi/fpm/php-fpm.service /lib/systemd/system/php-fpm.service

#配置PHP文件
vi /usr/local/php/etc/php.ini
vi /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.d/www.conf

######测试配置
/usr/local/php/sbin/php-fpm -t
######修改文件权限
chmod 745 /lib/systemd/system/php-fpm.service   
######设置为开机启动
systemctl enable php-fpm.service
######启动php-fpm
systemctl start php-fpm.service

#配置域名
vim /etc/nginx/conf.d/vhost.conf
#添加

server {
    listen       80;
    server_name  www.xxx.com;
    access_log  /var/log/nginx/host.access.log  main;
    location / {
        root   /www/;
        index  index.html index.htm index.php ;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~* \.php$ {
        root           /www/;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    location ~ /\.ht {
        deny  all;
    }
}

 

 

 

 

 

  

 

 

 

 

文献参考:

    http://blog.csdn.net/u012027999/article/details/73744032,

    http://blog.csdn.net/trh0123/article/details/53899610?utm_source=itdadao&utm_medium=referral,

    https://www.cnblogs.com/zzh10086130/p/6440378.html,

    https://www.cnblogs.com/zzh10086130/p/6440378.html

centos7.4 搭建lnmp

标签:iptable   添加   -shared   status   nmp   mbr   usr   配置nginx   mysqli   

原文地址:https://www.cnblogs.com/jxkshu/p/8376273.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!