设为首页 收藏本站
查看: 936|回复: 0

VM搭建LAMP和局域网内访问之 转

[复制链接]

尚未签到

发表于 2015-8-19 13:33:38 | 显示全部楼层 |阅读模式

(2012-11-06 14:29:17)
转载▼
标签:
it
分类: WEB

1.apache:
[iyunv@localhost liuhan]# yum install httpd
...
启动
[iyunv@localhost liuhan]# /etc/init.d/httpd start
Starting httpd:
查看运行状态
[iyunv@localhost liuhan]# /etc/init.d/httpd status
httpd (pid  2633) is running...
http://localhost 或 http://127.0.0.1 ,看到 Apache 2 Test Page 页面.
修改配置文件:修改侦听端口 80 -> 8080
[iyunv@localhost liuhan]# nano /etc/httpd/conf/httpd.conf
...
#Listen 12.34.56.78:80
Listen 8080
重启动服务
/etc/init.d/httpd restart
apache2 这个版本的结构:
/etc/httpd/conf/httpd.conf :最主要的配置文件;
/etc/httpd/conf.d/*.conf :这个是 CentOS 的特色,如果你不想修改原始配置文件 httpd.conf 的话,其他配置的在此独立配置,启动 apache 时,这个文件就会被读入到主要配置文件;
/usr/lib/httpd/modules :apache 支持很多的模块,您想要使用的模块默认都放置在此目录;
/var/www/html :这里是 CentOS 默认的“首页”目录;
/var/www/error :默认的系统错误信息,主机设置错误或浏览器端要求的数据错误,在浏览器上出现的错误提示就以这里的信息为主;
/var/www/icons :提供 apache 的一些小图标;
/var/www/cgi-bin :默认一些可执行的 CGI 程序放置的目录;
/var/log/httpd :日志文件目录,这里的文件很容易变的很大,需要提供足够的空间;
/usr/sbin/apachectl :这是 Apache 的主要执行文件,这个执行文件其实是 shell script ,它可以主动检测系统上的一些设置值,好让您启动 Apache 时更简单;
/usr/sbin/httpd :这是主要的 apache 的二进制文件;
/usr/bin/htpasswd :当您想登陆某些网页时,需要输入账号与密码。那么Apache本身就提供一个最基本的密码保护方式,该密码的产生就是通过这个命令实现的。
2.mysql:
[iyunv@localhost liuhan]# yum install mysql mysql-server
...
启动 MySQL
[iyunv@localhost liuhan]# /etc/init.d/mysqld start
Starting mysqld:                                           [  OK  ]
为 root 用户设置一个密码
[iyunv@localhost liuhan]# mysqladmin -u -root -p password liuhan@big
Enter password:
mysqladmin: Can't turn off logging; error: 'Access denied; you need the SUPER privilege for this operation'
[iyunv@localhost liuhan]# /etc/init.d/mysqld stop
Stopping mysqld:                                           [  OK  ]
启动
mysql> update user set password=password('liuhan@9') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> quit
Bye
[iyunv@localhost liuhan]# mysql -u root -p
Enter password:
...
mysql>
MySQL 有几个重要目录与文件:
/etc/my.cnf :这是Mysql的配置文件,包括 mysql 数据库的优化;
/usr/lib/mysql :这个目录是 MySQL 数据库放置的位置,务必在备份时将此目录完整的备份下来。
3,php:
[iyunv@localhost liuhan]# yum install php
然后需要必须重新启动 Apache :
[iyunv@localhost liuhan]# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

Apache 网站的默认文档的路径是 /var/www/html ,在这个目录里创建一个简单文件 info.php ,并且在浏览器中调用 http://localhost/info.php 将会显示很多 PHP5 的安装信息.
[iyunv@localhost liuhan]# nano /var/www/html/info.php
[iyunv@localhost liuhan]# cat /var/www/html/info.php
< ? php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
? >
4,PHP5 支持 MySQL:
[iyunv@localhost liuhan]# yum search ph
...
php.i686 : PHP scripting language for creating dynamic web sites
php-bcmath.i686 : A module for PHP applications for using the bcmath library
php-cli.i686 : Command-line interface for PHP
php-common.i686 : Common files for PHP
php-dba.i686 : A database abstraction layer module for PHP applications
php-devel.i686 : Files needed for building PHP extensions
php-embedded.i686 : PHP library for embedding in applications
php-gd.i686 : A module for PHP applications for using the gd graphics library
php-imap.i686 : A module for PHP applications that use IMAP
php-intl.i686 : Internationalization extension for PHP applications
php-ldap.i686 : A module for PHP applications that use LDAP
php-mbstring.i686 : A module for PHP applications which need multi-byte string
                  : handling
php-mysql.i686 : A module for PHP applications that use MySQL databases
php-odbc.i686 : A module for PHP applications that use ODBC databases
php-pdo.i686 : A database access abstraction module for PHP applications
php-pear.noarch : PHP Extension and Application Repository framework
php-pecl-apc.i686 : APC caches and optimizes PHP intermediate code
php-pgsql.i686 : A PostgreSQL database module for PHP
php-process.i686 : Modules for PHP script using system process interfaces
php-pspell.i686 : A module for PHP applications for using pspell interfaces
php-recode.i686 : A module for PHP applications for using the recode library
php-snmp.i686 : A module for PHP applications that query SNMP-managed devices
php-soap.i686 : A module for PHP applications that use the SOAP protocol
php-tidy.i686 : Standard PHP module provides tidy library support
php-xml.i686 : A module for PHP applications which use XML
php-xmlrpc.i686 : A module for PHP applications which use the XML-RPC protocol
php-zts.i686 : Thread-safe PHP interpreter for use with the Apache HTTP Server
...
[iyunv@localhost liuhan]# yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
...

[iyunv@localhost liuhan]# yum install php-mysql
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
Setting up Install Process
Package php-mysql-5.3.3-14.el6_3.i686 already installed and latest version
Nothing to do
重启pache
在浏览器中重新加载 http://localhost/info.php 这个页面,就能看到多了刚刚安装的 MySQL 模块。
5. 设置 Apache 和 MySQL 开机启动
[iyunv@localhost liuhan]# chkconfig --levels 3 httpd on
[iyunv@localhost liuhan]# chkconfig --list httpd
httpd              0:off    1:off    2:off    3:on    4:off    5:off    6:off
[iyunv@localhost liuhan]# chkconfig --levels 3 mysqld on
[iyunv@localhost liuhan]# chkconfig list mysqld
chkconfig version 1.3.49.3 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.
usage:   chkconfig [--list] [--type <type>] [name]
         chkconfig --add <name>
         chkconfig --del <name>
         chkconfig --override <name>
         chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>
6:访问LAMP


把httpd.conf里监听端口设置回80#Listen 12.34.56.78:80
Listen 80

[iyunv@localhost liuhan]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[iyunv@localhost liuhan]# /etc/rc.d/init.d/iptables saved
Usage: iptables {start|stop|restart|condrestart|status|panic|save}
[iyunv@localhost liuhan]# /etc/rc.d/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[iyunv@localhost liuhan]# /etc/init.d/iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]
[iyunv@localhost liuhan]#
在我的win7下输入http://192.168.56.129/info.php就可以访问虚拟机里的lamp了。

局域网内其它PC访问LAMP:
把NAT改为桥接模式,自动获取或者手动配置就行。

Use bridged networking(桥接模式)
    在这种模式下,VMWare虚拟出来的操作系统就像是局域网中的一台独立的主机,它可以访问网内任何一台机器。在桥接模式下,你需要手工为虚拟系统配置IP地址、子网掩码,而且还要和宿主机器处于同一网段,这样虚拟系统才能和宿主机器进行通信。同时,配置好网关和DNS的地址后,以实现通过局域网的网关或路由器访问互联网。
Use network address translation(NAT模式)
使用NAT模式,就是让虚拟系统借助NAT(网络地址转换)功能,通过宿主机器所在的网络来访问公网。也就是说,使用NAT模式可以实现在虚拟系统里访问互联网。NAT模式下的虚拟系统的TCP/IP配置信息是由VMnet8(NAT)虚拟网络的DHCP服务器提供的,无法进行手工修改,因此虚拟系统也就无法和本局域网中的其他真实主机进行通讯。采用NAT模式最大的优势是虚拟系统接入互联网非常简单,只需要宿主机器能访问互联网,你不需要配置IP地址,子网掩码,网关,但是DNS地址还是要根据实际情况填的。添加DNS地址除了在网卡属性中填写,还可以在虚拟机中的“虚拟网络编辑器”中的NAT选项卡中点击“编辑”按钮中来添加。
如果仅仅是让虚拟机能上网,两种模式都可以的,用桥接的话只要你在局域网内有合法的地址,比如你的ADSL猫是带路由功能的,如果是在单位,那就要网管给你合法IP才行(现在公司都是mac和ip绑定的)。
现在是主机和虚拟机互通,如果你的adsl带路由功能,那关闭虚拟机的dhcp,选桥接,检查2机是否分配同网段的IP,关闭防火墙。  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-101181-1-1.html 上篇帖子: ubuntu一键安装LAMP 及一键卸载 下篇帖子: LAMP环境搭建(Ubuntu)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表