博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在CentOS 6.5 环境下利用yum搭建LNMP环境
阅读量:6889 次
发布时间:2019-06-27

本文共 3714 字,大约阅读时间需要 12 分钟。

hot3.png

一、安装CentOS 6.5 ,采用最小安装min无桌面模式

二、开启网卡,确保联网可执行yum命令

[root@localhost ~]# vi /etc/sysconfig/network-script/ifcfg-eth0

       将onboot=no改成yes

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

[root@localhost ~]# vi /etc/sysconfig/iptables

            -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

            -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

[root@localhost ~]# /etc/init.d/iptables restart        //重启防火墙使配置生效

四、关闭SELINUX

[root@localhost ~]# vi /etc/sysconfig/iptables

五、配置CentOS第三方yum源(CentOS默认的标准源里没有nginx的包)     

[root@localhost ~]# yum -y install wget                //安装wget工具[root@localhost ~]# wget http://www.atomicorp.com/installers/atomic      //下载atomic yum源[root@localhost ~]# sh ./atomic                   //安装[root@localhost ~]# yum check-update       //更新yum软件包

五、安装Nginx

[root@localhost ~]# yum -y install nginx        //安装nginx软件[root@localhost ~]# service nginx start          //启动[root@localhost ~]# chkconfig nginx on        // 设置开机启动[root@localhost ~]# /etc/init.d/nginx restart         //重启nginx服务

六、安装MySQL

[root@localhost ~]# yum install mysql mysql-server -y        //安装mysql[root@localhost ~]# /etc/init.d/mysqld start                        // 启动mysql[root@localhost ~]# chkconfig mysqld on                            //设置开机启动[root@localhost ~]# cp /usr/share/mysql/my-medium.cnf  /etc/my.cnf     //拷贝文件覆盖原有的[root@localhost ~]# reboot            //重启系统[root@localhost ~]# mysql_secure_installation        //为root设置密码以及其他安全设置[root@localhost ~]# service mysqld restart            //重启mysql

七、安装PHP

[root@localhost ~]# yum install php -y[root@localhost ~]# yum -y install php-mysql phpgd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm[root@localhost ~]# /etc/init.d/mysqld restart        //重启mysql服务[root@localhost ~]# /etc/init.d/nginx restart          // 重启nginx服务[root@localhost ~]# /etc/rc.d/init.d/php-fpm start     //启动php-fpm服务[root@localhost ~]# chkconfig php-fpm on        //设置开机启动

八、配置Nginx支持PHP  

[root@localhost ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak        //备份[root@localhost ~]# vi /etc/nginx/nginx.conf                //修改用户名和组     user     nginx   nginx;   #修改 nginx 运行账号为:nginx 组的 nginx 用 户![root@localhost ~]# cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak//备份[root@localhost ~]# rm /etc/nginx/conf.d/default.conf      //删除default.conf[root@localhost ~]# vi /etc/nginx/conf.d/default.conf        //创建并将下列内容写入default.conf
server{    listen      80;    server_name _;    index index.php index.html index.htm;    root  /var/www;    location ~ .*\.(php|php5)?$    {            #fastcgi_pass  unix:/tmp/php-cgi.sock;            fastcgi_pass  127.0.0.1:9000;            fastcgi_index index.php;            include fastcgi.conf;    }    location / {        try_files $uri $uri/ /index.php?$query_string;    }}

注释:/var/www 为web根目录, location / ... 为url的rewrite,隐藏 index.php

      九、配置PHP

[root@localhost ~]# vim /etc/php.ini

        date.timezone = PRC

        expose_php = Off
        #;open_basedir = .:/tmp/        //注释掉这行

      十、配置php-fpm

[root@localhost ~]# vim /etc/php-fpm.d/www.conf        //编辑

        user = nginx           //编辑用户为nginx

        group = nginx        //修改组为nginx

[root@localhost ~]# /etc/init.d/mysqld restart     //重启mysql[root@localhost ~]# /etc/init.d/nginx restart        //启动nginx[root@localhost ~]# /etc/rc.d/init.d/php-fpm restart        //重启Php-fpm

十一、测试

[root@localhost ~]# cd /var/www[root@localhost ~]# vi index.php

写入以下代码

[root@localhost ~]# chown nginx.nginx /var/www -R        //设置权限[root@localhost ~]# service nginx restart[root@localhost ~]# service php-fpm restart

最后可以看到网页成功显示,说明LNMP已经搭建好。

注意事项:可能会有 “Unable to connect”的情况,如要在客户机得到显示效果,可关闭防火墙。

转载于:https://my.oschina.net/drathin/blog/877991

你可能感兴趣的文章
fastjson转json的时候过滤掉某些属性
查看>>
工作中遇到的几个Kafka问题整理
查看>>
apache与PHP结合,apache默认虚拟机
查看>>
Java开发,应该具备哪些技能呢?
查看>>
Tkinter之Menu组件用法
查看>>
Java动态追踪技术探究
查看>>
Confluence 6 管理应用服务器内存设置
查看>>
linux基础学习【3】
查看>>
优酷mac版视频怎么转码,如何将kux格式转成mp4格式
查看>>
Linux:Linux查找及压缩
查看>>
application.properties/application.yml文件中配置项
查看>>
微信小游戏子域和主域
查看>>
阿里工程师养了只“二哈”,专治讨厌的骚扰电话
查看>>
第一次开发PHP网页Hello PHP
查看>>
x86服务器与arm服务器
查看>>
Java职业规划,很详细,可以借鉴下
查看>>
Python -- Json 数据编码及解析
查看>>
深圳宏旺半导体宣布以“ICMAX”自主品牌正式进军中国半导体存储市场
查看>>
C4J私有化的小程序数据统计分析
查看>>
短信验证码免限
查看>>