资讯详情

MySQL数据库之web环境搭建之Linux--nginx-php-mysql

本文主要介绍给大家。MySQL数据库之web环境搭建之Linux--nginx-php-mysql ,通过具体内容向您展示,希望向您学习MySQL有助于数据库。

环境:LinuxCentsOs6.732位

任务:搭建web环境:Linux--nginx-php-mysql

(1)安装PHP包括一些附加件:1yuminstallphpphp-mysqlphp-gdphp-imapphp-ldapphp-mbstringphp-odbcphp-pearphp-xmlphp-xmlrpc

(2)安装MySQL客户端及服务器:yum-yinstallmysql#安装客户端可以找到yumsearchmysqlyuminstallmysql-server#安装服务器chkconfig--level345mysqlon#设置mysql自启动可以不要servicemysqldstart#开启mysql服务mysql_secure_installation#设置mysql用户根据英文提示完成配置,需要给root用户设置密码#其他按需设置,一般回车到底第一次使用mysql没有密码直接密码,然后提示root用户设置密码,然后直接返回OK了。

(3)安装nginx:#直接yum需要更新安装yum源,方法和文件如下:#1.在/etc/yum.repos.d新建文件夹nginx.repo文件cd/etc/yum.repos.dvimnginx.repo#添加以下内容:[nginx]name=nginxrepobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1#查看yum更新是否完成:yumlist|grepnginx返回内容(类似,不同版本可能会有差异):nginx.i3861.10.1-1.el6.ngx@nginxnginx-debug.i3861.8.0-1.el6.ngxnginxnginx-debuginfo.i3861.10.1-1.el6.ngxnginxnginx-module-geoip.i3861.10.1-1.el6.ngxnginxnginx-module-image-filter.i3861.10.1-1.el6.ngxnginxnginx-module-njs.i3861.10.1.0.0.20160414.1c50334fbea6-1.el6.ngxnginxnginx-module-perl.i3861.10.1-1.el6.ngxnginxnginx-module-xslt.i3861.10.1-1.el6.ngxnginxnginx-nr-agent.noarch2.0.0-9.el6.ngxnginxpcp-pmda-nginx.i6863.10.9-6.el6base#yum源更新完成,开始安装nginxyuminstall-ynginx#安装完成

(4)安装php-fpm使nginx解释php(说法不标准):

这个地方是最重要的地方,因为默认情况下Nginx和PHP他们之间没有感觉。以前很多朋友都建过。Apache PHP,Apache PHP模块文件是在编译后生成的Nginx PHP需要PHP只有生成可执行文件才能使用fastcgi技术来实现Nginx与PHP只要我们安装它并启用它FastCGI即可。我们这次安装PHP不仅使用了FastCGI,而且还用了PHP-FPM这样的东东,PHP-FPM说白了就是管理FastCGI作为管理器的管理器PHP在安装中存在插件PHP要想使用PHP-FPM时就需要把PHP-FPM以补丁的形式安装到PHP中,而且PHP要与PHP-FPM版本一致,这是必须的,记住!12yuminstall-yphp-fpm#如有必要,可先查找,yumsearchphp-fpm#依赖可能需要更新,yum会搞定...只需看安装完成就可以了。

(5)配置1.配置ngingx:#nginx配置文件在/etc/nginx/下和/etc/nginx/conf.d(1)/etc/nginx/文件以下配置文件是nginx.conf配置文件不需要配置#nginx.conf配置解释:http://blog.csdn.net/tjcyjd/article/details/50695922(2)/etc/nginx/conf.d以下配置文件default.confcd/etc/nginx/conf.dvimdefault.confserver{listen80;server_namelocalhost;#charsetkoi8-r;#access_log/var/log/nginx/log/host.access.logmain;location&nsp;/ {root/usr/share/nginx/html;index  index.html index.htm;#修改为:index  index.html index.htm index.php;} #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;} # proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ .php$ {#    proxy_pass   http://127.0.0.1;#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#nginx 不像Apache 它是将php文件交给php执行才能正常显示,通过上句可以它是通过 9000 端口发给PHP的#location ~ .php$ {root           html;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME/script$fastcgi_script_name;#修改为:fastcgi_param  SCRIPT_FILENAME   /usr/share/nginx/html$fastcgi_script_name;#/usr/share/nginx/html   为php文件所在地址include        fastcgi_params;} # deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /.ht {#    deny  all;#}} 2.配置php-fpm : #配置文件为: /etc/php-fpm.conf 和 /etc/php-fpm.d/www.conf #因为其默认配置中监听的端口为 9000 所以不需要修改,可以直接使用

注意:这段代码在修改后要把前面的#号注释删掉!

location ~ .php$ {

root           html;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME   /script$fastcgi_script_name;

#修改为:fastcgi_param  SCRIPT_FILENAME   /usr/share/nginx/html$fastcgi_script_name;

#/usr/share/nginx/html   为php文件所在地址

include        fastcgi_params;

}

(6)测试#在 /usr/share/nginx/html 下#将自带的 index.html 重命名或者删除cd /usr/share/nginx/html#重命名:mv index.html index.html.bak#删除:rm -f index.html #新建php文件:vim index.php <?phpphpinfo ();?>  #开启服务:service nginx restartservice php-fpm restart  #主机访问:127.0.0.1

本文由职坐标整理并发布,希望对同学们学习MySQL有所帮助,更多内容请关注职坐标数据库MySQL数据库频道!

标签: 2dvim综合传感器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台