欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

一步一步带你设置LNMP环境

最编程 2024-08-09 21:14:38
...

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

LNMP是什么意思

Linux、Nginx、Mysql、PHP

linux系统

这个大家可以去阿里云或者腾讯云,再或者其他的一些服务器代理平台去购买

nginx安装

yum install nginx -y

mysql安装

yum install mysql-server -y

php安装

yum install php php-fpm php-mysql -y

以上就是LNMP的安装代码,安装好了,我们肯定还是需要将它们启动起来的,那么如何启动呢?

Nginx启动:nginx Nginx重载:service nginx restart

Mysql启动:service mysqld restart 设置 MySQL密码(默认账号:root):/usr/bin/mysqladmin -u root password '这里填写要设置的密码'

PHP启动:service php-fpm start 查看PHP监听端口:netstat -nlpt | grep php-fpm

当然可以将其添加到开启自启动里:

chkconfig nginx on,chkconfig mysqld on,chkconfig php-fpm on

以上就是启动代码,接下来我们要准备什么呢?

我们弄一个服务器肯定不会是只放一个网站吧,那样就太浪费了?

既然要放多个网站,那么是不是需要配置域名解析,并且要让我们配置的域名能够找到自己的运行目录?那我们要怎么操作呢?

我们需要先进入目录:/etc/nginx/conf.d/,然后创建文件test.com.conf(命令:touch test.com.conf) 然后打开test.com.conf(命令 vim test.com.conf),填写下列代码,大家可以根据标注自行更改

server {
    listen 80; #监听端口,可以使用:netstat -nlpt | grep nginx,来查看端口
    server_name  test.com; #这里是你要绑定的域名
    index  index.php index.html index.html; #这里是网站首页默认文件
    root           /www/web/test; #这里是你要绑定的程序目录,就是要运行的程序根目录
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ .php$ {
        fastcgi_pass   127.0.0.1:9000; #这里可以使用:netstat -nlpt | grep php-fpm,来查看端口
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

到了这一步服务器的配置环节已经完成了,接下来直接解析多个域名到我们的服务器ip上就完成了

是不是很简单呢?更多经验、知识,请持续关注我哈!