CentOS6.3搭建lnmp环境

来源:互联网 发布:回答乐队 知乎 编辑:程序博客网 时间:2024/04/30 00:31
1.本文直接禁用掉了防火墙iptables和selinux:
/etc/init.d/iptables stop
chkconfig iptables off
vi /etc/selinux/config
SELINUX=enforcing 改成 SELINUX=disabled
补充:# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo //直接163下载相关的源
2.下载第三方源
wget http://www.atomicorp.com/installers/atomic
sh ./atomic
yum check-update

3.安装web服务器nginx
yum install nginx
chkconfig nginx on

4.安装数据库mysql
yum install mysql mysql-server
chkconfig mysqld on

5.安装php环境
yum install php 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
chkconfig php-fpm on


6.
vi /etc/nginx/conf.d/default.conf
(a)."index  index.html index.htm;" 改为 "index  index.html index.htm index.php;"
(b).
# 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  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}  
改成
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;
}

7.
vi  /etc/php.ini   #编辑
date.timezone = PRC     #在946行 把前面的分号去掉,改为date.timezone = PRC
#在386行 列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
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 = Off        #在432行 禁止显示php版本的信息

magic_quotes_gpc = On   #在745行 打开magic_quotes_gpc来防止SQL注入
open_basedir = .:/tmp/  #在380行,设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题,可注销此行,或者直接写上程序目录路径/var/www/html/www.osyunwei.com/:/tmp/
:wq!  #保存退出

8.
vi /etc/php-fpm.d/www.conf   #编辑
user = nginx   #修改用户为nginx
group = nginx   #修改组为nginx

9.
chown nginx:nginx /usr/share/nginx/html/ -R
chmod 755 /usr/share/nginx/html/ -R

10.reboot

11.
vi /usr/share/nginx/html/index.php
输入:
<?php
    phpinfo();
?>
在Windows浏览器输入:http://192.168.1.101/index.php
就可以看到结果了。