Every day to be a little better

Cenos7安装LNMP

  • 修改yum
    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
  • 安装php、mysql、nginx
    yum -y install nginx
    yum -y install mysql-community-server
    yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-pdo.x86_64 php70w-mysqlnd php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongo
  • 配置mysql
    • MySQL 安装完成之后,在 /var/log/mysqld.log 文件中给 root 生成了一个默认密码
    • 通过下面的方式找到root 默认密码,然后登录 MySQL 进行修改
       systemctl start mysqld    # 启动 MySQL
       grep 'temporary password' /var/log/mysqld.log  # 查找默认密码
      2017-10-310T02:58:16.806931Z 1 [Note] A temporary password is generated for root@localhost: iacFXpWt-6gJ
      
    • 登录mysql
      ```
      mysql -uroot -p'iacFXpWt-6gJ'
      ```
      
    • 修改密码
      mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyPass1!';
      

      或者

      mysql> set password for 'root'@'localhost'=password('123abc');
      
    • 配置默认编码为 utf8:
      vim /etc/my.cnf
      [mysqld] ### 增加下面两行
      character_set_server=utf8
      init_connect='SET NAMES utf8'
      systemctl restart mysqld # 重启 MySQL
    • 设置开机启动
      systemctl enable mysqld
    • 默认配置文件路径
      配置文件:/etc/my.cnf
      日志文件:/var/log/mysqld.log
      服务启动脚本:/usr/lib/systemd/system/mysqld.service
      socket 文件:/var/run/mysqld/mysqld.pid
  • 配置nginx
systemctl status firewalld ### 防火墙 如果active (running) 则修改添加nginx规则
vi /etc/firewalld/zones/public.xml
<zone>
    ...
    <service name="nginx"/>
<zone>
systemctl reload firewalld  ### 重启防火墙
  • 配置nginx。con
cp /etc/nginx/nginx.conf  /etc/nginx/nginx.conf_bak
  • vi /etc/nginx/nginx.conf

user nobody; worker_processes 1; error_log /data/logs/nginx/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /data/logs/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; gzip_types text/plain application/javascript application/x-javascript text/css application/xml; include /etc/nginx/conf.d/*.conf; }
  • vi /etc/nginx/conf.d/default.conf
#
# The default server
#
server {
    listen       80;
    server_name  _;

    access_log   /data/log/nginx/defalut.access.log  main;

    root   /data/www;
    index  index.php index.html index.htm;

    location / {
        root   /data/www;
        index  index.php index.html index.htm;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /data/www/info_58;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #

    location ~ \.php$ {
            root           /data/www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;      
            fastcgi_param  SCRIPT_FILENAME  /data/www$fastcgi_script_name;
            include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}
  • 启动nginx
systemctl start nginx
systemctl enable nginx ### 开机启动
  • 启动fpm
systemctl enable php-fpm
systemctl start php-fpm
  • 访问测试
vi /data/www/test.php
<?php
phpinfo();

未经允许不得转载:奇葩菌博客 » Cenos7安装LNMP

分享到:更多 ()