1. 程式人生 > >contos7 使用yum快速 搭建lnmp 環境

contos7 使用yum快速 搭建lnmp 環境

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--表示永久生效