lnmp环境

Ubuntu

第一步:安装nginx 并启动

 sudo apt-get install -y nginx && service nginx start

第二步:安装mysql 并启动

 sudo apt-get install -y  mysql-server mysql-client && service mysql start

第三部:安装php和所需组件

sudo apt-get install -y php  php-common  php-fpm php-mysql && service php-fpm start

第四部:配置nginx

cd /etc/nginx/sites-enabled/

cp default  www.qq.com

vim www.qq.com

需要修改的地方:
listen 80 default_server;
root /var/www;
index index.php index.html index.htm index.nginx-debian.html;
location ~ \.php$ {
            include snippets/fastcgi-php.conf;
    #
    #       # With php7.0-cgi alone:
    #       fastcgi_pass 127.0.0.1:9000;
    #       # With php7.0-fpm:
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

重启nginx
service nginx reload

测试:
cd /var/www/
echo "<?php phpinfo();" >> index.php
访问服服务器ip地址 显示信息则成功

Centos

第一步:安装nginx 并启动

配置centos第三方yum源(centos默认的标准源里没有nginx软件包)
yum install -y wget

wget http://www.atomicorp.com/installers/atomic

sh atomic

sudo apt-get install -y nginx && service nginx start

yum install -y nginx && service nginx start && chkconfig --level 235 nginx on

第二步:安装mysql 并启动

yum install -y mysql mysql-server mysql-devel && service mysqld start && chkconfig --level 235 mysqld on

第三部:安装php和所需组件

yum install -y php lighttpd-fastcgi php-common php-devel php-fpm php-mysql && service php-fpm start && chkconfig --level 235 php-fpm on

第四部:配置nginx

mv /etc/nginx/nginx.conf     /etc/nginx/nginx.confbak       #将配置文件备份

cp /etc/nginx/nginx.conf.default    /etc/nginx/nginx.conf   #使用默认的配置文件作为配置文件

vi /etc/nginx/nginx.conf                                    #修改nginx配置文件,添加fastcgi支持

    #下面代码是文件nginx.conf需要修改的地方
        location /{
            root /www;
            index index.php index.html index.htm;
        }
        location ~ \.php$ {
            root           /www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www$fastcgi_script_name;
            include        fastcgi_params;
        }

配置nginx支持php
echo "cgi.fix_pathinfo=1" >> /etc/php.ini

重启nginx php-fpm
service nginx restart && service php-fpm restart 

建立index.php文件
mkdir /www && cd /www && echo "<?php phpinfo();" >> index.php
本地输入:192.168.1.10(服务器ip),如显示则成功
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 系统环境 所需软件官方下载地址: 一、 安装开发包环境: 二、 关闭iptables和Selinux(生产...
    莫名其妙的一生阅读 5,121评论 0 4
  • 1、配置防火墙,开启80端口、3306端口 vi /etc/sysconfig/iptables //在22端口的...
    henryspace阅读 2,915评论 0 0
  • 一.nginx安装1.下载对应当前系统版本的nginx包(package)​ wget http://nginx....
    code_nerd阅读 1,384评论 0 0
  • 首先简单介绍一下linux的两种安装方法,yum以及编译安装。yum是一个软件包管理器,使用yum指令安装,系统会...
    正在修炼的西瓜君阅读 4,773评论 0 2
  • 前面几篇文章和大家分享了yum和brew安装PHP环境,对于开发和测试环境来说,这已经足够了 ,但如果是生产环境,...
    你东哥呀阅读 1,742评论 0 5