某互联网企业技术发展史(四)配置nginx和mysql兼容Yii框架,上传网站并调试成功...

2024-05-10 02:44:30
昨天安装好了php、nginx和squid,今天配置mysql和nginx,使nginx兼容Yii框架,并上传网站,将网站调试和配置好。

1, 首先配置下php的时区
# vi /etc/php.ini
date.timezone = "Asia/Chongqing"
# service php-fpm restart
若没有配置时区,php页面可能会出现如下错误:
date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead

2,配置mysql数据库
默认情况下mysql只有root用户,并只可以本地登录,昨天已经修改了root的密码。
我们将创建一个新用户,并且为管理员级别,且可以远程登录,这样我们就可以使用mysql administrator tool进行远程管理,mysql远程管理端口是3306,在下一步将配置防火墙允许3306端口。
先用root登录mysql,查询账号信息:
# mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor.    Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.67 Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

查询账号信息:

mysql> select host, user,password from user;
+--------------+------+-------------------------------------------+
| host                 | user | password                                                                    |
+--------------+------+-------------------------------------------+
| localhost        | root | *3DC3333qE11EEF04038E306BC8779D651 |
| 127.0.0.1        | root |                                                                                     |
| localhost        |            |                                                                                     |
+--------------+------+-------------------------------------------+
3 rows in set (0.00 sec)

添加可远程登录的新管理员账号:

mysql> GRANT ALL PRIVILEGES ON *.* TO testroot@"%" IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
查询当前账号信息:
mysql> select host, user,password from user;

+--------------+-------+-------------------------------------------+
| host                 | user    | password                                                                    |
+--------------+-------+-------------------------------------------+
| localhost        | root    | *3DC8AE44442111DE11EEF04038E306BC8779D651 |
| 127.0.0.1        | root    |                                                                                     |
| localhost        |             |                                                                                     |
| %                 | testroot | *3DC8AE08411DE11EEF04038E306BC8779D651 |
+--------------+-------+-------------------------------------------+
4 rows in set (0.00 sec)

删除匿名账户:

mysql> delete from user where user='';
3, 配置防火墙,允许远程登录mysql管理
# iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
或者
# vim /etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT

这样,就可以使用mysql管理工具使用testroot账号远程登录进行管理了。
4,导入网站数据库,创建网站数据库用户
使用mysql管理工具将数据库备份还原到该服务器数据库中;
为网站创建普通账号testweb,只允许本地登录,赋予该账号对网站数据库的读写更新等权限。
这样网站就可以使用该账号连接数据库了。
5,上传网站源代码和Yii框架
Yii框架位于网站根目录下yii目录: 
/var/www/html/yii
网站目录位于根目录下的testweb目录下:
/var/www/html/testweb
配置网站数据库信息。
5,配置nginx支持Yii框架
由于网站使用了Yii框架,需要nginx实现rewrite的功能。
nginx配置如下:
/etc/nginx/nginx.conf
user    nginx;
worker_processes    4;

error_log    /var/log/nginx/error.log warn;
pid                /var/run/nginx.pid;

events {
        worker_connections    50000;
}

http {
        include             /etc/nginx/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    /var/log/nginx/access.log    main;

sendfile                on;
        #tcp_nopush         on;
        keepalive_timeout    65;
        gzip    on;

include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/default.conf
server {
        listen             8080;
        server_name    localhost;

charset utf-8;
        access_log    /var/log/nginx/log/host.access.log    main;

location / {
                root     /var/www/html;
                index    index.html index.htm default.htm default.html index.php default.php;

add_header Content-Type "text/html; charset=UTF-8";
                add_header Content-Encoding "gzip";
        }

# Disable logging for favicon
                location = /favicon.ico {
                                log_not_found off;
                                access_log off;
                }

# Disable logging for robots.txt
                location = /robots.txt {
                                allow all;
                                log_not_found off;
                                access_log off;
                }

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
                location ~ /\. {
                                deny all;
                                access_log off;
                                log_not_found off;
                }

location ~* \.(jpg|jpeg|png|gif|css|js|swf|mp3|avi|flv|xml|zip|rar)$ {
                                expires 7d;
                                gzip on;
                                gzip_types    text/plain application/x-javascript text/css application/xml;
                                root /var/www/html;
                }

location ~ /.svn/* {
                                deny all;
                                access_log off;
                                log_not_found off;
                }

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                root                     /var/www/html;
                fastcgi_pass     127.0.0.1:9000;
                fastcgi_index    index.php;
                fastcgi_param    SCRIPT_FILENAME    $document_root$fastcgi_script_name;
                fastcgi_param    PATH_INFO $fastcgi_script_name;
                include                fastcgi_params;
        }

# yii configuration
                include conf.d/yii.common.conf.internal;

#error_page    404                            /404.html;

# 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;
        }
}

/etc/nginx/conf.d/yii.common.conf.internal
# BEGIN yiiframework.conf
# Block access to protected, framework, and nbproject (artifact from Netbeans)
location ~ /(yii|protected|framework|nbproject) {
        deny all;
        access_log off;
        log_not_found off;
}

# Block access to theme-folder views directories
location ~ /themes/\w+/views {
        deny all;
        access_log off;
        log_not_found off;
}

# Attempt the uri, uri+/, then fall back to yii's index.php with args included
# Note: old examples use IF statements, which nginx considers evil, this approach is more widely supported
location /testweb {
                index index.php;
        try_files $uri $uri/ /testweb/index.php?$args;
}

重启nginx:
# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]

浏览器中输入网址:http://192.168.1.18/testweb/ 即可访问到网站内容,请求首先经过squid,再转发到nginx,然后经过php解析器。
至此,网站初步配置基本完成,剩下调优和细化的工作了。

转载于:https://blog.51cto.com/babyhe/1166999

某互联网企业技术发展史(四)配置nginx和mysql兼容Yii框架,上传网站并调试成功...相关推荐

  1. nginx与mysql传输过程_某互联网企业技术发展史(四)配置nginx和mysql兼容Yii框架,上传网站并调试成功...

    昨天安装好了php.nginx和squid,今天配置mysql和nginx,使nginx兼容Yii框架,并上传网站,将网站调试和配置好. 1, 首先配置下php的时区 # vi /etc/php.in ...

  2. centos7二进制安装php,Centos7下编译安装配置Nginx+PHP+MySql环境

    序言 这次玩次狠得.除了编译器使用yum安装,其他全部手动编译.哼~ 看似就Nginx.PHP.MySql三个东东,但是它们太尼玛依赖别人了. 没办法,想用它们就得老老实实给它们提供想要的东西. 首先 ...

  3. linux nginx编译安装mysql_Centos7下编译安装配置Nginx+PHP+MySql环境

    序言 这次玩次狠得.除了编译器使用yum安装,其他全部手动编译.哼~ 看似就Nginx.PHP.MySql三个东东,但是它们太尼玛依赖别人了. 没办法,想用它们就得老老实实给它们提供想要的东西. 首先 ...

  4. phpfpm怎么连接mysql_配置nginx、mysql、php-fpm的方法

    mac下使用homebrew安装安装.配置nginx.mysql.php-fpm的方法. 一.前话: 1.1.环境选择: 重新在mac上配置php,原本mac上就自带有apach.php以及pgsql ...

  5. windows7 nginx php mysql_windows7配置Nginx+php+mysql的详细教程

    最近在学习php,想把自己的学习经历记录下来,并写一些经验,仅供参考交流.此文适合那些刚刚接触php,想要学习并想要自己搭建Nginx+php+mysql环境的同学. 当然,你也可以选择集成好的安装包 ...

  6. Nginx 代理转发阿里云OSS上传的实现代码

    这篇文章主要介绍了Nginx 代理转发阿里云OSS上传的实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧 前言 因为小程序上传需要https,服务器https用的是 ...

  7. 电商生鲜网站开发(四)——后台开发:商品模块-图片上传/多条件拼接sql

    电商生鲜网站开发(四)--后台开发:商品模块-图片上传/多条件拼接sql 增加商品 上传图片 更新商品 删除商品 批量上下架 图片上传功能 文件名UUID 通用唯一识别码(Universally Un ...

  8. Centos配置Jenkins实现Android自动打包并上传到蒲公英

    本篇文章来自 徐永红  的投稿,给大家讲解Centos配置Jenkins实现Android自动打包并上传到蒲公英,希望对大家有所帮助. 徐永红 的博客地址: https://xuyonghong.cn ...

  9. 迟到的总结(四)--springmvc的系统学习之文件上传、ajaxjson处理

    前序:本篇主要将springmvc框架中文件的上传,json数据的配置.由于视频中的文件上传的实现运用到io流,属于比较老的方式,故本篇将重点不放在代码的实现,主要目的是过一下配置文件.改天再择取时间 ...

最新文章

  1. Android Handler sendMessage和 sendMessageDelayed的使用
  2. 百度谷歌等联合推出机器学习基准 加速AI软硬件发展
  3. Android开发--Json数据的解析
  4. MATLAB实战系列(三十四)-MATLAB基于PCA-LDA模糊神经网络的人脸识别
  5. 量子计算101:浅谈其需求、前景和现实
  6. virtualenv创建python项目虚拟环境
  7. HTML5学习笔记四: 列表, 块和布局
  8. [react] React的displayName有什么作用?
  9. 方维系统登陆弹窗,登陆后自动刷新当前页的实现方法
  10. 快速打开内网服务器文件,Linux服务器局域网(内网)快速传输文件
  11. 关系传递闭包Warshall算法之思想的一种解说
  12. java中UUID类生成32位随机数(附加 6 位随机数)
  13. word刷子刷格式_用word格式刷快速调整文档格式-word技巧-电脑技巧收藏家
  14. 新浪微博架构和FEED架构分析--人人架构
  15. 前端战五渣学前端——模板引擎(Handlebars.js)
  16. 视频怎么转为GIF,如何制作GIF
  17. windows7计算机无法到达,win7电脑突然无法进入到安全模式了怎么办?
  18. mysql 中文截断_Mysql入库汉字被截断问题
  19. RiPro美化二开详细修改路径介绍
  20. 计算机操作系统实验指导linux版,操作系统实验指导书(linux版).doc

热门文章

  1. Android NDK开发之旅34 NDK 手把手带你入门直播技术
  2. iOS--动画demo--Launch Image淡出效果
  3. hdu 5011(博弈)
  4. processing link链接
  5. 百度危矣:乱评程苓峰《360的章鱼手要抢谁家饭碗?》
  6. 关于CSS属性display:none和visible:hidden的区别
  7. 由浅入深:自己动手开发模板引擎——解释型模板引擎
  8. CSS属性之字体(Font)
  9. Spark安装与学习
  10. mysql带BETTEEN ADN 关键字的查询