CentOS 6.x 使用包管理器安装配置Apache+PHP+MySql

本文介绍如何在Linux环境下安装并配置Apache Web服务器、PHP解析器和MySQL数据库,包括详细的步骤与配置项说明。

Apache:

    安装:

        yum install httpd     #根据提示,输入Y安装即可成功安装

    配置:  

        vi /etc/httpd/conf/httpd.conf
            #AddHandler cgi-script .cgi    →    AddHandler cgi-script .cgi .pl (允许扩展名为.pl的CGI脚本运行)
            Options Indexes MultiViews FollowSymLinks    →    Options MultiViews FollowSymLinks(不在浏览器上显示树状目录结构)
            ServerSignature On    →    ServerSignature Off (在错误页中不显示Apache的版本)
            DirectoryIndex index.html index.html.var    →    DirectoryIndex index.html index.htm Default.html Default.htm index.php Default.php index.html.var (设置默认首页文件,增加index.php)
            (338行左右)AllowOverride None    →    AllowOverride All (允许.htaccess)
            Options Indexes FollowSymLinks    →    Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)
            MaxKeepAliveRequests 100    →    MaxKeepAliveRequests 1000 (增加同时连接数)
            KeepAlive Off    →    KeepAlive On (允许程序性联机)
            ServerTokens OS    →    ServerTokens Prod (在出现错误页的时候不显示服务器操作系统的名称)

            #ServerName www.example.com:80    →    ServerName localhost:80 #这里设置为你自己的域名,如果没有域名,可以设置为localhost

            

            <VirtualHost *:80>    #虚拟主机
                ServerAdmin webmaster@dummy-host.example.com
                DocumentRoot /var/www/html/www.sample.com
                ServerName www.sample.com
                ErrorLog logs/www.sample.com-error_log
                CustomLog logs/www.sample.com-access_log common
            </VirtualHost>

        :wq! #保存退出        

        chkconfig httpd on #设为开机启动,查看chkconfig --list httpd

        service httpd start       

        rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html  #删除默认测试页

    基本信息

        Apache目录:/etc/httpd
        web根目录:/var/www/html

PHP:

    安装:

        yum install php    #根据提示,输入Y安装即可成功安装

        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  #安装PHP组件,使 PHP5 支持 MySQL

    配置:

        vi /etc/php.ini

            ;date.timezone =    →    date.timezone = PRC

            magic_quotes_gpc = Off    →    magic_quotes_gpc = On #在745行 打开magic_quotes_gpc来防止SQL注入

            display_errors = Off    #调试开启,生产关闭

            expose_php = On    #是否禁止显示php版本的信息

            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    #列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

            open_basedir = .:/var/www/html/:/tmp/  #设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题,可以注销此行,或者直接写上程序的目录/data/www.osyunwei.com/:/tmp/。/etc/httpd/conf.d/vhost.conf中设置了open_basedir之后, 虚拟用户就不会再自动继承php.ini中的open_basedir设置值了,这就难以达到灵活的配置措施, 所以建议您不要在/etc/httpd/conf.d/vhost.conf中设置此项限制。可以在php.ini中设置open_basedir = .:/tmp/

             short_open_tag = Off    →    short_open_tag = ON #支持php短标签

MySql:

   

     安装:

            yum install mysql mysql-server

    配置:

            mysql_secure_installation    为root账户设置密码

            chkconfig mysqld on    #设为开机启动 

            

            service mysql start    #启动

            service mysql restart    #重启

            service mysql stop    #停止



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值