紫葡紫萄 發表於 2023-8-1 00:00:00

Ubuntu Server 11.10安装配置lamp(Apache+MySQL+PHP)

<p>
        <strong>准备篇:</strong></p>
<p>
        <strong>1、配置防火墙,开启80端口、3306端口</strong></p>
<p>
        说明:ubuntu默认安装是没有开启任何防火墙的,为了服务器的安全,建议大家安装启用防火墙设置,这里推荐使用iptables防火墙。<br>
        whereis iptables #查看系统是否安装防火墙<br>
        iptables: /sbin/iptables /usr/share/iptables /usr/share/man/man8/iptables.8.gz #表示已经安装iptables<br>
        apt-get install iptables #如果默认没有安装,请运行此命令安装防火墙<br>
        iptables -l #查看防火墙配置信息,显示如下:</p>
<p>
        #####################################################<br>
        chain input (policy accept)<br>
        target prot opt source destination</p>
<p>
        chain forward (policy accept)<br>
        target prot opt source destination</p>
<p>
        chain output (policy accept)<br>
        target prot opt source destination<br>
        #####################################################<br>
        nano /etc/iptables.default.rules #添加以下内容<br>
        ##################################################################################################<br>
        *filter<br>
        # allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0<br>
        -a input -i lo -j accept<br>
        # accepts all established inbound connections<br>
        -a input -m state --state established,related -j accept<br>
        # allows all outbound traffic<br>
        # you could modify this to only allow certain traffic<br>
        -a output -j accept<br>
        # allows http and mysqlconnections from anywhere (the normal ports for websites)<br>
        -a input -p tcp --dport 80 -j accept<br>
        -a input -p tcp --dport 3306 -j accept<br>
        # allows ssh connections for script kiddies<br>
        # the -dport number is the same one you set up in the sshd_config file<br>
        -a input -p tcp -m state --state new --dport 22 -j accept<br>
        # now you should read up on iptables rules and consider whether ssh access<br>
        # for everyone is really desired. most likely you will only allow access from certain ips.<br>
        # allow ping<br>
        -a input -p icmp -m icmp --icmp-type 8 -j accept<br>
        # log iptables denied calls (access via 'dmesg' command)<br>
        -a input -m limit --limit 5/min -j log --log-prefix "iptables denied: " --log-level 7<br>
        # reject all other inbound - default deny unless explicitly allowed policy:<br>
        -a input -j reject<br>
        -a forward -j reject<br>
        commit<br>
        ##################################################################################################<br>
        ctrl+o #保存<br>
        ctrl+x #退出</p>
<p>
        <br>
        备注:80是指web服务器端口、3306是指mysql数据库链接端口、22是指ssh远程管理端口<br>
        iptables-restore &lt; /etc/iptables.default.rules #使防火墙规则生效<br>
        nano /etc/network/if-pre-up.d/iptables #创建文件,添加以下内容,使防火墙开机启动<br>
        ##########################################################<br>
        #!/bin/bash<br>
        /sbin/iptables-restore &lt;/etc/iptables.default.rules<br>
        ##########################################################<br>
        chmod +x /etc/network/if-pre-up.d/iptables #添加执行权限</p>
<p>
        <strong>安装篇</strong></p>
<p>
        <strong>一、安装apache</strong></p>
<p>
        apt-get install apache2 #安装apache,根据提示输入y安装<br>
        service apache2 start #启动apache<br>
        service apache2 restart #重启<br>
        apt-get install chkconfig #安装chkconfig<br>
        chkconfig apache2 on #开机启动apache</p>
<p>
        <strong>二、安装mysql</strong></p>
<p>
        apt-get install mysql-server #安装mysql,根据提示输入y安装<br>
        安装过程中,会跳出输入root密码的界面<br>
        输入2次密码,继续自动安装</p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="Ubuntu Server 11.10安装配置lamp(Apache+MySQL+PHP)" alt="Ubuntu Server 11.10安装配置lamp(Apache+MySQL+PHP)" height="381" src="https://zhuji.jb51.net/uploads/img/202305/6fd7eee4799941d4e530443cdf858e52.jpg" width="642"></p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="Ubuntu Server 11.10安装配置lamp(Apache+MySQL+PHP)" alt="Ubuntu Server 11.10安装配置lamp(Apache+MySQL+PHP)" height="385" src="https://zhuji.jb51.net/uploads/img/202305/acde03ee152373ee1d5409752831f117.jpg" width="642"></p>
<p>
        service mysql start #启动<br>
        chkconfig mysql on #开机启动mysql<br>
        service mysql restart #重启</p>
<p>
        <strong>三、安装php</strong></p>
<p>
        1、apt-get install php5 #安装php5,根据提示输入y安装<br>
        2、安装php组件,使php支持 mysql<br>
        apt-get install php5-mysql php5-gd libjpeg8-dev php5-imap php5-ldap php5-odbc php*-pear php*-xml php5-xmlrpc php5-mcrypt php5-mhash libmcrypt* libmcrypt-dev php-fpdf<br>
        /etc/init.d/mysql restart #重启mysql<br>
        /etc/init.d/apache2 restart #重启apache2<br>
        ln -s /etc/php5/apache2/php.ini /etc/php.ini #把php配置文件链接到系统默认位置</p>
<p>
        <strong>配置篇</strong></p>
<p>
        一、apache配置<br>
        cp /etc/apache2/apache2.conf /etc/apache2/apache2.confbak #备份<br>
        nano /etc/apache2/apache2.conf #编辑<br>
        servertokens prod #在出现错误页的时候不显示服务器操作系统的名称<br>
        serversignature off #在在错误页中不显示apache2的版本<br>
        maxkeepaliverequests 1000 #修改为1000(默认为100,增加同时连接数)<br>
        servername localhost   #添加apache2默认服务名<br>
        ctrl+o #保存<br>
        ctrl+x #退出<br>
        nano /etc/apache2/sites-enabled/000-default #编辑<br>
        options multiviews followsymlinks #不在浏览器上显示树状目录结构<br>
        ctrl+o #保存<br>
        ctrl+x #退出<br>
        nano /etc/apache2/mods-enabled/dir.conf   #编辑,设置默认主页顺序<br>
        directoryindex index.html  index.php  index.htm<br>
        ctrl+o #保存<br>
        ctrl+x #退出<br>
        a2enmod rewrite #激活apache2伪静态模块mod rewrite</p>
<p>
        <strong>二、配置php</strong></p>
<p>
        nano /etc/php5/apache2/php.ini #编辑<br>
        date.timezone = prc #在946行 把前面的分号去掉,改为date.timezone = prc<br>
        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<br>
        #在386行 列出php可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。<br>
        expose_php = off #在432行 禁止显示php版本的信息<br>
        magic_quotes_gpc = on #在745行 打开magic_quotes_gpc来防止sql注入<br>
        open_basedir = .:/tmp/ #在380行,设置表示允许访问当前目录(即php脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题,可注销此行,或者直接写上程序目录路径/var/www/www.osyunwei.com/:/tmp/<br>
        ctrl+o #保存<br>
        ctrl+x #退出</p>
<p>
        测试篇<br>
        cd /var/www #进入默认站点目录<br>
        nano index.php #新建测试文件</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlighterplain" id="highlighter_238803">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                        <div class="line number2 index1 alt1">
                                                                2</div>
                                                        <div class="line number3 index2 alt2">
                                                                3</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="plain plain">&lt;?php</code>
</div>
                                                                <div class="line number2 index1 alt1">
                                                                        <code class="plain plain">phpinfo();</code>
</div>
                                                                <div class="line number3 index2 alt2">
                                                                        <code class="plain plain">?&gt;</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
</div>
<p>
        ctrl+o #保存<br>
        ctrl+x #退出<br>
        chown www-data.www-data -r /var/www #添加目录所有者<br>
        chmod 700 -r /var/www #设置目录权限<br>
        在客户端浏览器输入服务器ip地址,可以看到相关的配置信息!</p>
<p>
        <strong>备注:</strong></p>
<p>
        apache2默认站点目录是:/var/www<br>
        权限设置:chown www-data.www-data -r /var/www<br>
        apache2虚拟主机配置文件:/etc/apache2/sites-enabled/000-default #虚拟主机配置文件<br>
        mysql数据库目录是:/var/lib/mysql<br>
        权限设置:chown mysql.mysql -r /var/lib/mysql</p>
頁: [1]
查看完整版本: Ubuntu Server 11.10安装配置lamp(Apache+MySQL+PHP)