博主信息
博文 91
粉丝 2
评论 4
访问量 146818
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
centors下搭建lamp
夏日的烈风的博客
原创
1211人浏览过

   搭建lnmp环境是每一位PHP开发者必会的技能,本文将带领大家一起完整的搭建一次lnmp环境。

        1、我们买了云服务器之后可是安装公共镜像,一般常用的是centos,我们选择版本较为新的centos7.2作为我们的操作系统。

        2、安装完系统后我们开始安装nginx,先下载对应的nginx包,建立yum库,安装nginx

                (1)wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm (一般自带wget命令,如果没用 yum  install wget安装即可)。

                (2)建立nginx的yum库    

                      rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

                (3)安装nginx           yum install nginx   (安装完成后,可是使用whereis nginx查看安装位置)

                  (4) 启动nginx       systemctl start nginx.service

     3、MYSQL安装,先下载mysql的repo源包,建立mysql yum 库,安装mysql ,修改mysql密码

                 (1)wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

                 (2)rpm -ivh mysql-community-release-el7-5.noarch.rpm

                 (3)sudo yum install mysql-server

                 (4)sudo chown -R root:root /var/lib/mysql

                 (5)systemctl restart mysql.service

                 (6)mysql -u root

                         mysql > use mysql;

                         mysql > update user set password=password('123456') where user='root';

                         mysql > exit;

        4、安装PHP,由于系统自带PHP ,首先删除旧版本的PHP。建立yum库,安装PHP以及主要的库还有PHP-fpm

                (1)查看当前安装的php版本( yum list installed | grep php),如果存在php安装包先删除之前版本  用yum remove 移除 php相关的包

         (2) rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

            rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

        (3)yum install php70w  php70w-mysql.x8664 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64  yum install php70w-fpm

        

    5、配置nginx、php-fpm

        (1)、nginx配置文件/etc/nginx/conf.d/default.conf

      

                location / {

                        root    /home/wwwroot;

                        index  index.php  index.html index.htm;

                }

                

                location ~  \.php|\.html$  {

                        root  /home/wwwroot/;

                        fastcgi_pass   127.0.0.1:9000;

                        fastcgi_index  index.php;

                        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

                        include        fastcgi_params;

                }

                (2) 、配置php-fpm配置文件 /etc/php-fpm.d/www.conf

                    将

             user =nginx

                         group=nginx

              (3)、重启nginx,启动php-fpm

                    systemctl  restart nginx.service  (设置开启启动 sudo systemctl enable nginx.service)

                    systemctl start php-fpm.service

          6、在/home/wwwroot/目录下新建index.html  index.php两个文件  分别写入PHP语言

                    <?php   phpinfo();?>

            在浏览器上输入访问地址 111.111.111.111/index.php  跟 111.111.111.111/index.html(假设是111.111.111.111)

                    


本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学