CentOS 6.2搭建mysql+nginx+php平台。

CentOS 6.2搭建mysql+nginx+php平台。 - 1

CentOS 6.2搭建mysql+nginx+php平台。 - 3

在此感谢天涯大大之前送的VPS供我学习,在此献上一个lnmp平台搭建教程,搭建平台是centos6.2
这次为了节省本站空间,就不放图片了,如果有什么不懂,请留言

1.安装nginx

yum install nginx      #安装nginx

 2.安装mysql

yum install mysql mysql-server      #安装mysql
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf  #复制配置文件到etc目录,如提示已经存在请按下Y覆盖
mysql_secure_installation           #为root用户设置数据库密码

在mysql_secure_installation输入后,直接按回车跳过输入root密码,按下Y确认设置mysql密码,之后输入新的密码,再次输入确保两次密码一致,接下来会问题你是否删除匿名用户,建议选择Y,之后选择是否禁止ROOT用户远程登录,这个根据自己需求设置,接下会让你选择是否删除test数据库,直接回车不用管,最后一次选择人你是否重载权限表,选择y,就设置好了

3.安装PHP

yum install php           #安装php
yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm       #安装PHP组件,按下Y确认

4.配置nginx(涉及到编辑配置文件之前建议先备份)

vim /etc/nginx/nginx.conf           #编辑配置文件

(忽略注释)在第一句 user                    nginx之间添加一个nginx,修改nginx运行账号
然后保存退出

vim /etc/nginx/conf.d/default.conf       #编辑配置文件

在这个文件中添加index.php默认文档,位置自己找。
然后找到类似以下语句

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
    include        fastcgi_params;
  }
#取消上面这段话的注释,修改script_filename部分,改为$document_root$fastcgi_script_name

2.配置php(涉及到编辑配置文件之前建议先备份)

vim /etc/php.ini                #编辑php配置文档

找到date.timezone,取消注释,在等于后面添加PRC,解决时差
找到disable_functions,在等于后面添加禁用的函数(这些参数根据需求添加删除)

disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

找到expose_php,将On改成Off可以禁止PHP的版本显示
找到magic_quotes_gpc,将Off改成On防止SQL注入
找到open_basedir在等于后面添加.:/tmp/防止PHP木马跨站攻击

3.配置PHPfastCGI(涉及到编辑配置文件之前建议先备份)

vim /etc/php-fpm.d/www.conf                  #编辑fastcgi配置文件

修改user参数为nginx用户
修改group参数为nginx组

4.启动以及测试

service mysqld start                   #启动mysql
service php-fpm start                  #启动php-fpm
service nginx start                    #启动nginx
chkconfig mysqld on                    #将mysql添加到系统自启动
chkconfig php-fpm on                   #将fastcgi添加到自启动
chkconfig nginx on                     #将nginx添加到自启动

现在可以访问下自己机子的IP了,会有nginx的默认网页,或者也可以删除index.html,新建一个index.php

 添加以上代码查看PHP信息。

CentOS 6.2搭建mysql+nginx+php平台。 - 5

 

4 thoughts on “CentOS 6.2搭建mysql+nginx+php平台。”

Leave a Reply

Your email address will not be published. Required fields are marked *