您的位置:首页 > 运维架构 > Apache

Linux+Apache+PHP+MYSQL环境配置学习笔记

2011-11-18 15:26 851 查看
CentOS6.0下部署环境配置

1、从关机开始

# shutdown -h now 表示立即关机

# halt 这是更简单的关机命令 杀死所有进程

# reboot 重启系统

# logout 注销系统

# passwd 修改当前登录用户密码

2、虚拟机中使用DHCP自动获取IP的方法:

一:虚拟机使用host-only方式,centos自动获取IP,跟运行VM的机器一样的网段

二:虚拟机使用NAT网络,那VMware要开启NAT和DHCP服务,centos也是自动获取IP设置好后,需要重启网络服务eth0

3、网络连接配置

# cat -n /etc/sysconfig/network-scripts/ifcfg-eth0 查看配置文件内容

# vi /etc/sysconfig/network-scripts/ifcfg-eth0 修改网络配置文件,设置以下内容

DEVICE=eth0

BOOTPROTO=dhcp 如果是静态IP设置为:static

TYPE=Ethernet

HWADDR=00:03:47:2C:D5:40

ONBOOT=yes

# service network restart 重启网络服务

# ifconfig 查看网络连接配置信息

# ctrl+c 停止ping

# ctrl+l 清屏

4、使用yum命令安装软件包

# yum install vsftpd 安装ftp

# service vsftpd start 启动ftp

# yum install httpd 安装appache

# service httpd start 启动httpd服务

# service httpd stop 停止httpd服务

# yum install php 安装php

# yum remove php 卸载所有php

# chkconfig 查看哪些服务是开机自动启动 2~5都是on表示为自动启动

# chkconfig httpd on 设置httpd服务为开机自动启动

# chkconfig httpd off 取消自动启动

5、文件目录操作

# cd /etc 进入etc目录

# cd .. 返回上一级目录

# cd / 返回根目录

# pwd 查看当前目录

# dir 查看当前目录下有哪些文件

# ls -a 列出所有文件

# ls -l 列出包括隐藏文件

# ls | more 列出文件并分页显示

6、使用vi编辑文档文件

# vi index.php 表示打开或创建index.php文件

# 按Insert或I键进入编辑模式

编辑好文件后,# 按ESC键退加命令模式

# :w 保存当前文件

# :q 不保存直接退出

# :x 先存后退出

# cat -n index.php 查看文件内容

7、打开防火墙端口

# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT

# /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT

# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

# /etc/rc.d/init.d/iptables save 或者 # service iptables save 保存修改

# service iptables status 查看防火墙信息

# netstat -ntlp 查看端口使用情况

8、安装Apahce, PHP, Mysql, 以及php连接mysql库组件(一次性完成)

# yum -y install httpd php mysql mysql-server php-mysql

//安装apache扩展

# yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

//安装php的扩展

# yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc

//安装mysql扩展

# yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql

9、MYSQL访问

刚装好的mysql没有为root用户设置密码

# mysql 连接mysql

mysql> exit 退出mysql

在进入mysql后,可使用SQL语句,查询用户信息等,语句末尾用分号";"结束

mysql> select user,host,password from mysql.user; 可以看到用户密码为空,存在匿名用户

mysql> delete from mysql.user where user=''; 删除匿名用户

mysql> use mysql 切换到数据库

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;赋予任何主机访问数据库的权限

mysql> FLUSH PRIVILEGES; 刷新权限,使修改生效

mysql> set password for root@localhost=password('这里填密码'); 设置用户密码

mysql> set password for root@mycentos=password('这里填密码'); 设置用户密码

mysql> set password for root@127.0.0.1=password('这里填密码'); 设置用户密码

mysql> set password for root@'%'=password('这里填密码'); 设置用户密码 % 代表任何主机

# mysql -u root -p 使用用户名和密码连接mysql
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: