源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-11-03 18:32 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Ubuntu Server 11.10安装配置lamp(Apache+MySQL+PHP)
[b]准备篇:[/b] [b]1、配置防火墙,开启80端口、3306端口[/b] 说明:Ubuntu默认安装是没有开启任何防火墙的,为了服务器的安全,建议大家安装启用防火墙设置,这里推荐使用iptables防火墙。 whereis iptables #查看系统是否安装防火墙 iptables: /sbin/iptables /usr/share/iptables /usr/share/man/man8/iptables.8.gz #表示已经安装iptables apt-get install iptables #如果默认没有安装,请运行此命令安装防火墙 iptables -L #查看防火墙配置信息,显示如下: ##################################################### Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination ##################################################### nano /etc/iptables.default.rules #添加以下内容 ################################################################################################## *filter # Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0 -A INPUT -i lo -j ACCEPT # Accepts all established inbound connections -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # Allows all outbound traffic # You could modify this to only allow certain traffic -A OUTPUT -j ACCEPT # Allows HTTP and MySQLconnections from anywhere (the normal ports for websites) -A INPUT -p tcp --dport 80 -j ACCEPT -A INPUT -p tcp --dport 3306 -j ACCEPT # Allows SSH connections for script kiddies # THE -dport NUMBER IS THE SAME ONE YOU SET UP IN THE SSHD_CONFIG FILE -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT # Now you should read up on iptables rules and consider whether ssh access # for everyone is really desired. Most likely you will only allow access from certain IPs. # Allow ping -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT # log iptables denied calls (access via 'dmesg' command) -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7 # Reject all other inbound - default deny unless explicitly allowed policy: -A INPUT -j REJECT -A FORWARD -j REJECT COMMIT ################################################################################################## ctrl+o #保存 ctrl+x #退出 备注:80是指web服务器端口、3306是指MySQL数据库链接端口、22是指SSH远程管理端口 iptables-restore < /etc/iptables.default.rules #使防火墙规则生效 nano /etc/network/if-pre-up.d/iptables #创建文件,添加以下内容,使防火墙开机启动 ########################################################## #!/bin/bash /sbin/iptables-restore </etc/iptables.default.rules ########################################################## chmod +x /etc/network/if-pre-up.d/iptables #添加执行权限 [b]安装篇[/b] [b]一、安装apache[/b] apt-get install apache2 #安装apache,根据提示输入y安装 service apache2 start #启动apache service apache2 restart #重启 apt-get install chkconfig #安装chkconfig chkconfig apache2 on #开机启动apache [b]二、安装MySQL[/b] apt-get install mysql-server #安装mysql,根据提示输入y安装 安装过程中,会跳出输入root密码的界面 输入2次密码,继续自动安装 [img]http://files.jb51.net/file_images/article/201610/2016100723454924.jpg[/img] [img]http://files.jb51.net/file_images/article/201610/2016100723454925.jpg[/img] service mysql start #启动 chkconfig mysql on #开机启动mysql service mysql restart #重启 [b]三、安装php[/b] 1、apt-get install php5 #安装php5,根据提示输入y安装 2、安装PHP组件,使PHP支持 MySQL 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 /etc/init.d/mysql restart #重启mysql /etc/init.d/apache2 restart #重启apache2 ln -s /etc/php5/apache2/php.ini /etc/php.ini #把php配置文件链接到系统默认位置 [b]配置篇[/b] 一、Apache配置 cp /etc/apache2/apache2.conf /etc/apache2/apache2.confbak #备份 nano /etc/apache2/apache2.conf #编辑 ServerTokens Prod #在出现错误页的时候不显示服务器操作系统的名称 ServerSignature Off #在在错误页中不显示apache2的版本 MaxKeepAliveRequests 1000 #修改为1000(默认为100,增加同时连接数) ServerName localhost   #添加apache2默认服务名 ctrl+o #保存 ctrl+x #退出 nano /etc/apache2/sites-enabled/000-default #编辑 Options MultiViews FollowSymLinks #不在浏览器上显示树状目录结构 ctrl+o #保存 ctrl+x #退出 nano /etc/apache2/mods-enabled/dir.conf   #编辑,设置默认主页顺序 DirectoryIndex index.html  index.php  index.htm ctrl+o #保存 ctrl+x #退出 a2enmod rewrite #激活apache2伪静态模块mod rewrite [b]二、配置php[/b] nano /etc/php5/apache2/php.ini #编辑 date.timezone = PRC #在946行 把前面的分号去掉,改为date.timezone = PRC 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 #在386行 列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。 expose_php = Off #在432行 禁止显示php版本的信息 magic_quotes_gpc = On #在745行 打开magic_quotes_gpc来防止SQL注入 open_basedir = .:/tmp/ #在380行,设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题,可注销此行,或者直接写上程序目录路径/var/www/www.osyunwei.com/:/tmp/ ctrl+o #保存 ctrl+x #退出 测试篇 cd /var/www #进入默认站点目录 nano index.php #新建测试文件
<?php
phpinfo();
?>
ctrl+o #保存 ctrl+x #退出 chown www-data.www-data -R /var/www #添加目录所有者 chmod 700 -R /var/www #设置目录权限 在客户端浏览器输入服务器IP地址,可以看到相关的配置信息! [b]备注:[/b] apache2默认站点目录是:/var/www 权限设置:chown www-data.www-data -R /var/www apache2虚拟主机配置文件:/etc/apache2/sites-enabled/000-default #虚拟主机配置文件 MySQL数据库目录是:/var/lib/mysql 权限设置:chown mysql.mysql -R /var/lib/mysql
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部