Linux+Nginx+Mysql+PHP(LNMP)架构流程

Linux+Nginx+Mysql+PHP(LNMP)架构流程

步骤1: 下载所需软件包

wget -c ‘http://nginx.org/download/nginx-1.20.1.tar.gz’
wget -c ‘http://www.mysql.com/downloads/mysql-5.7.tar.gz’
wget -c ‘http://php.net/get/php-7.4.0.tar.gz/from/this/mirror’

步骤2: 安装Linux系统依赖

sudo apt-get update
sudo apt-get install -y gcc make libc-dev pcre-dev zlib-dev openssl libssl-dev

步骤3: 安装Nginx

tar -zxvf nginx-1.20.1.tar.gz
cd nginx-1.20.1
./configure
make
sudo make install

步骤4: 安装MySQL

tar -zxvf mysql-5.7.tar.gz
cd mysql-5.7
cmake .
make
sudo make install

步骤5: 安装PHP

tar -zxvf php-7.4.0.tar.gz
cd php-7.4.0
./configure --prefix=/usr/local/php --with-mysql-sock=/tmp/mysql.sock --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
make
sudo make install

步骤6: 配置Nginx与PHP处理

配置Nginx

编辑Nginx配置文件,通常在 /usr/local/nginx/conf/nginx.conf 或/etc/nginx/nginx.conf

在server块中添加index.php处理

location / {
root html;
index index.php index.html index.htm;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}

配置PHP-FPM

复制PHP的示例配置文件
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

启动PHP-FPM

/usr/local/php/sbin/php-fpm

步骤7: 测试安装

创建一个简单的PHP文件,如 index.php,并将其放置在Nginx的web根目录中
重启Nginx 和 PHP-FPM 服务
在浏览器中访问服务器IP,查看PHP信息页面

  • 12
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SN_01

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值