contos7 使用yum快速 搭建lnmp 环境

本文详细介绍如何在Linux系统上安装配置LAMP(Linux, Apache/NGINX, MySQL, PHP)环境,包括安装PHP、NGINX、MySQL的具体步骤及常见问题解决方法。

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

1.安装 PHP
yum install php
yum install php-fpm
systemctl start php-fpm
2 安装 nginx 
yum install nginx
vim /etc/nginx/nginx.conf
打开nginx.conf 添加:

server {  
    listen       80;  
    server_name  localhost;  
    autoindex    on;  
    #charset koi8-r;  
    #access_log  /var/log/nginx/log/host.access.log  main;  
  
    location / {  
        root   /var/www/html;  
        index  index.html index.htm index.php;  
    }  
  
    location ~ \.php$ {  
        root           /var/www/html;  
        fastcgi_pass   127.0.0.1:9000;  
        fastcgi_index  index.php;  
        fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;  
        include        fastcgi_params;  
    }


3 安装MYSQL
1.下载YUM库


shell > wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm


2.安装YUM库


shell > yum localinstall -y mysql57-community-release-el7-7.noarch.rpm


3.安装数据库


shell > yum install -y mysql-community-server


4.启动MySQL服务


shell > systemctl start mysqld.service


5.默认空密码


shell > mysql -uroot -p


6.重置root密码后重启mysql服务


shell > update mysql.user set authentication_string=password("yourpassword") where user="root" and Host="localhost";


shell > flush privileges;


shell > quit;


shell > systemctl restart mysqld;


如果出现如下问题:


报错1:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)


请修改my.cnf,添加skip-grant-tables


shell > vi /etc/my.cnf


[mysqld]


skip-grant-tables




报错2:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解决办法:

1、 修改用户密码
mysql> alter user 'root'@'localhost' identified by 'youpassword';  
或者       
mysql> set password=password("youpassword");
2、刷新权限
mysql> flush privileges;




1、添加远程登录用户(登入Mysql)


use mysql;


GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;


注:'%'代表任意地址,也可以指定IP


2、检查用户表,刷新内存权限


select host, user from user;


FLUSH PRIVILEGES;

设置开机自启服务:
systemctl enable nginx
systemctl enable mysqld
开启防火墙:
systemctl start firewalld
firewall-cmd --zone=public --add-port=80/tcp --permanent    //设置需要开放的端口   permanent--表示永久生效
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值