Ubuntu14.04简单部署LNMP环境

本文详细介绍了在Ubuntu环境下安装并配置PHP-FPM、Nginx及MySQL的方法,包括安装步骤、配置Nginx以支持PHP、修改PHP文件存放目录、测试配置、添加扩展包等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.安装mysql

sudo apt-get install mysql-server mysql-client

过程输入用户名和密码


1.安装nginx

sudo apt-get install nginx 

 

2.使用php5-fpm来作为我们的php解析

sudo apt-get install php5-fpm

 

3.修改一下nginx配置,使之支持php

$vim /etc/nginx/sites-available/default

server {

listen 80 default_server;

listen [::]:80 default_server ipv6only=on;

 

root /usr/share/nginx/html;

index index.php index.html index.htm;

 

server_name localhost;

 

 location ~ \.php$ {

                fastcgi_pass unix:/var/run/php5-fpm.sock;

                fastcgi_index index.php;

                include fastcgi_params;

        }

}

 

即因为ubuntu的对php监听端口修改了

修改 location ~ \.php$ {

                fastcgi_pass 127.0.0.1:9000;

                fastcgi_index index.php;

                fastcgi_param APPLICATION_ENV production;

                include fastcgi_params;

        }

        location ~ \.php$ {

                fastcgi_pass unix:/var/run/php5-fpm.sock;

                fastcgi_index index.php;

                include fastcgi_params;

        }

 

要修改php文件存放目录,把所有的root 后的路径改为自己要的路径

 

测试配置修改是否成功 sudo nginx -t

 

5.重启服务

sudo service php5-fpm restart 

sudo service nginx restart

 

6.测试

在/usr/share/nginx/html/目录下

rm index.html

vim index.php

<?php

phpinfo();

?>

 

在浏览器里输入127.0.0.1,出现如下界面则成功


7.添加扩张包(如php5-mcrypt )

a.命令行下载(不嫌麻烦可以到网上找安装包,用源码安装)

 sudo apt-get install php5-mcrypt  

b.查看是否安装成功

 find / -name mcrypt.so

c.修改配置文件php.ini vim /etc/php5/fpm/php.ini  

加入: extension=mcrypt.so 

d.重启服务 
sudo service php5-fpm restart sudo service nginx restart 


tips:

redhat 

lamp :  yum install -y httpd php mysql mysql-server

lnmp :  yum install -y nginx php php-fpm mysql mysql-server

# vim /etc/nginx/conf.d/default.conf

    location ~\.php$ {
        root /tmp/test;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值