手工搭建LNMP环境

本文详细介绍了如何在Linux服务器上手动部署LNMP(Nginx、MySQL、PHP)环境。首先,通过YUM安装Nginx并验证其运行状态。接着,安装MySQL,设置root用户密码并进行安全性配置。然后,安装PHP及其相关组件,并确认PHP版本。最后,修改Nginx配置以支持PHP,创建测试页面验证环境搭建成功。

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

简介

本文主要介绍如何使用服务器手工搭建LNMP平台的web环境

linux实例手动部署LNMP环境具体操作步骤如下:

1.安装nginx

2.安装mysql

3.安装php

4.浏览器访问测试

操作步骤

1.安装nginx

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

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

yum -y install nginx

systemctl start nginx
systemctl enable nginx

systemctl status nginx.service

使用浏览器访问 “http://服务器IP地址”,显示如下页面,说明nginx安装成功。

 2.安装MySQL

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

yum -y install mysql57-community-release-el7-10.noarch.rpm

yum -y install mysql-community-server

systemctl start mysqld
systemctl enable mysqld

systemctl status mysqld.service

执行以下命令,获取安装MySQL时自动设置的root用户密码。

grep 'temporary password' /var/log/mysqld.log

执行以下命令,并按照回显提示信息进行操作,加固MySQL。

mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:    #输入上一步骤中获取的安装MySQL时自动设置的root用户密码
The existing password for the user account root has expired. Please set a new password.

New password:  #设置新的root用户密码

Re-enter new password:   #再次输入密码
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration of the plugin.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N   #是否更改root用户密码,输入N

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y   #是否删除匿名用户,输入Y
Success.

Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y   #禁止root远程登录,输入Y
Success.

By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y   #是否删除test库和对它的访问权限,输入Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y   #是否重新加载授权表,输入Y
Success.

All done!

3.安装php

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

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

yum -y install php70w-tidy php70w-common php70w-devel php70w-pdo php70w-mysql php70w-gd php70w-ldap php70w-mbstring php70w-mcrypt php70w-fpm

执行以下命令,验证PHP的安装版本。

php -v

执行以下命令,启动PHP服务并设置开机自启动。

systemctl start php-fpm
systemctl enable php-fpm

修改nginx配置文件以支持PHP。

vim /etc/nginx/nginx.conf

修改打开的“nginx.conf”文件。





找到server段落,修改或添加下列配置信息。

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

    location / {
        root   /usr/share/nginx/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 /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
    }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

执行以下命令,重新载入nginx的配置文件。

service nginx reload

 浏览器访问测试。

在/usr/share/nginx/html/目录下创建“info.php”的测试页面

执行以下命令创建并打开“info.php”的测试文件

vim /usr/share/nginx/html/info.php

修改打开的“info.php”文件,将如下内容写入文件。

<?php
 phpinfo();
?>

使用浏览器访问“http://服务器IP地址/info.php”,显示如下页面,说明环境搭建成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

花小智

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

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

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

打赏作者

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

抵扣说明:

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

余额充值