centos7 配置 lnmp

来源:互联网 发布:个人数据融合模型 编辑:程序博客网 时间:2024/05/19 13:15

关闭防火墙

systemctl  stop iptables.service systemctl  stop firewalld.service# 因为我是在内网环境中使用,所以把防火墙都关了,若想开防火墙,修改配置文件,让防火墙允许指定的端口访问即可。

关闭SELINUX

vi /etc/selinux/config#SELINUX=enforcing      # 注释掉#SELINUXTYPE=targeted      # 注释掉SELINUX=disabled         # 增加shutdown -r now     # 重启系统# 我没有修改该配置,也可以

安装nginx

sudo yum install nginxsudo systemctl start nginxsudo systemctl enable nginx.service  # 开机启动,可以不设置

安装MySQL(MariaDB)

MariaDB是MySQL的一个分支,主要由开源社区进行维护和升级,而MySQL被Oracle收购以后,发展较慢。在CentOS 7的软件仓库中,将MySQL更替为了MariaDB。

安装mariadb-server mariadb

yum install mariadb-server mariadb -y

修改mysql配置文件/etc/my.cnf

vim /etc/my.cnf//最后加上编码配置default-character-set =utf8//这里的字符编码必须和/usr/share/mysql/charsets/Index.xml中一致

修改密码

systemctl start mariadb  // 启动MariaDBmysql -u root  -p        //开始 mysql无密码//设置密码mysql>set password for 'root'@'localhost' =password('123456');

导入数据库

MariaDB>create database  smsMariaDB>create database  file_urlsmysql -u root -p sms < /mnt/ntfs/load/mysql/sms.sql mysql -u root -p file_urls < /mnt/ntfs/load/mysql/file_urls.sql

远程连接设置

// 把所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。mysql> grant all privileges on *.* to root@'%'identified by '123456';
// 如果是新用户而不是root,则要先新建用户mysql>create user 'username'@'%' identified by 'password';  // 此时就可以进行远程连接了。

配置mysql python客户端

yum install python-devel    # 安装mysql-python时 依赖yum install mysql-devel 

mariadb数据库的相关命令

systemctl start mariadb //启动MariaDBsystemctl stop mariadb  //停止MariaDBsystemctl restart mariadb  //重启MariaDBsystemctl enable mariadb  //设置开机启动

安装PHP

sudo yum install  php-fpm php-mysql  phpsudo systemctl start php-fpmsudo systemctl enable php-fpm    // 开机启动,可以不设置

这时php-fpm已经安装完毕,但是需要配置一下Nginx。

修改Nginx配置文件

// 文件路径 /etc/nginx/nginx.conf,修改如下# For more information on configuration, see:#   * Official English Documentation: http://nginx.org/en/docs/#   * Official Russian Documentation: http://nginx.org/ru/docs/user nginx nginx;   # 修改worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;# Load dynamic modules. See /usr/share/nginx/README.dynamic.include /usr/share/nginx/modules/*.conf;events {    worker_connections 1024;}http {    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  /var/log/nginx/access.log  main;    sendfile            on;    tcp_nopush          on;    tcp_nodelay         on;    keepalive_timeout   65;    types_hash_max_size 2048;    include             /etc/nginx/mime.types;    default_type        application/octet-stream;    # Load modular configuration files from the /etc/nginx/conf.d directory.    # See http://nginx.org/en/docs/ngx_core_module.html#include    # for more information.    include /etc/nginx/conf.d/*.conf;    server {        listen       80;        server_name  example.com       # root         /usr/share/nginx/html;       # root       /fuzzy;        # Load configuration files for the default server block.        include /etc/nginx/default.d/*.conf;        location / {            root   /fuzzy;            index  index.php index.html index.htm;        }        location ~ \.php$ {            root           /fuzzy;            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            include        fastcgi_params;        }        error_page 404 /404.html;            location = /40x.html {        }        error_page 500 502 503 504 /50x.html;            location = /50x.html {        }    }# Settings for a TLS enabled server.##    server {#        listen       443 ssl http2 default_server;#        listen       [::]:443 ssl http2 default_server;#        server_name  _;#        root         /usr/share/nginx/html;##        ssl_certificate "/etc/pki/nginx/server.crt";#        ssl_certificate_key "/etc/pki/nginx/private/server.key";#        ssl_session_cache shared:SSL:1m;#        ssl_session_timeout  10m;#        ssl_ciphers HIGH:!aNULL:!MD5;#        ssl_prefer_server_ciphers on;##        # Load configuration files for the default server block.#        include /etc/nginx/default.d/*.conf;##        location / {#        }##        error_page 404 /404.html;#            location = /40x.html {#        }##        error_page 500 502 503 504 /50x.html;#            location = /50x.html {#        }#    }}

以上配置监听端口为 80,主目录为/fuzzy,在/fuzzy目录下新建一个名为phpinfo.php的文件用来展示phpinfo信息,
文件内容为:

<?php echo phpinfo(); ?>

从浏览器打开 http://<外网IP地址>:80/phpinfo.php,就能看到phpinfo信息了,说明php环境已经部署成功。

验证PHP安装成功后,需要将此phpinfo.php文件删除,线上环境尽量不要暴漏使用的软件版本及路径信息,以防被入侵者利用。

原创粉丝点击