CentOS 6 手动配置Lamp

Posted lnxcode

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 6 手动配置Lamp相关的知识,希望对你有一定的参考价值。

1.安装系统
简易安装
http://www.91linux.com/html/2014/CentOS_0415/9726.html
复杂安装:先创建一张空磁盘再挂在ISO
http://www.centoscn.com/image-text/setup/2013/0816/1263.html

centos: roottoor

2.安装Vmtools
http://jingyan.baidu.com/article/6dad5075ca4d6da123e36e34.html
3.设置固定IP
192.168.1.211
4.安装Apache
默认iptables开启,只在iptables开放了22端口

默认Apache版本

默认安装Apache版本,但是服务没有开启
[[email protected] 桌面]# rpm -qa |grep httpd
httpd-tools-2.2.15-26.el6.centos.i686
httpd-2.2.15-26.el6.centos.i686
[[email protected] 桌面]# service httpd status
httpd 已停
[[email protected] 桌面]# yum search httpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile

  • base: mirrors.tuna.tsinghua.edu.cn
  • extras: mirrors.tuna.tsinghua.edu.cn
  • updates: mirrors.tuna.tsinghua.edu.cn
    ============================== N/S Matched: httpd ==============================
    libmicrohttpd-devel.i686 : Development files for libmicrohttpd
    libmicrohttpd-doc.noarch : Documentation for libmicrohttpd
    httpd.i686 : Apache HTTP Server
    httpd-devel.i686 : Development interfaces for the Apache HTTP server
    httpd-manual.noarch : Documentation for the Apache HTTP server
    httpd-tools.i686 : Tools for use with the Apache HTTP Server
    libmicrohttpd.i686 : Lightweight library for embedding a webserver in
    : applications
    mod_auth_mellon.i686 : A SAML 2.0 authentication module for the Apache Httpd
    : Server
    mod_dav_svn.i686 : Apache httpd module for Subversion server
    mod_dnssd.i686 : An Apache HTTPD module which adds Zeroconf support

Name and summary matches only, use "search all" for everything.
yum 安装Apache

[[email protected] 桌面]# yum install httpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile

  • base: mirrors.tuna.tsinghua.edu.cn
  • extras: mirrors.tuna.tsinghua.edu.cn
  • updates: mirrors.tuna.tsinghua.edu.cn
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.i686 0:2.2.15-26.el6.centos will be updated
    ---> Package httpd.i686 0:2.2.15-54.el6.centos will be an update
    --> Processing Dependency: httpd-tools = 2.2.15-54.el6.centos for package: httpd-2.2.15-54.el6.centos.i686
    --> Running transaction check
    ---> Package httpd-tools.i686 0:2.2.15-26.el6.centos will be updated
    ---> Package httpd-tools.i686 0:2.2.15-54.el6.centos will be an update
    --> Processing Dependency: libssl.so.10(libssl.so.10) for package: httpd-tools-2.2.15-54.el6.centos.i686
    --> Processing Dependency: libcrypto.so.10(libcrypto.so.10) for package: httpd-tools-2.2.15-54.el6.centos.i686
    --> Running transaction check
    ---> Package openssl.i686 0:1.0.0-27.el6 will be updated
    ---> Package openssl.i686 0:1.0.1e-48.el6_8.3 will be an update
    --> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Updating:
httpd i686 2.2.15-54.el6.centos updates 833 k
Updating for dependencies:
httpd-tools i686 2.2.15-54.el6.centos updates 79 k
openssl i686 1.0.1e-48.el6_8.3 updates 1.5 M

Transaction Summary

Upgrade 3 Package(s)

Total download size: 2.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): httpd-2.2.15-54.el6.centos.i686.rpm | 833 kB 00:00
(2/3): httpd-tools-2.2.15-54.el6.centos.i686.rpm | 79 kB 00:00
(3/3): openssl-1.0.1e-48.el6_8.3.i686.rpm | 1.5 MB 00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 3.3 MB/s | 2.4 MB 00:00
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
Userid : CentOS-6 Key (CentOS 6 Official Signing Key) [email protected]
Package: centos-release-6-4.el6.centos.10.i686 (@anaconda-CentOS-201303020136.i386/6.4)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : openssl-1.0.1e-48.el6_8.3.i686 1/6
Updating : httpd-tools-2.2.15-54.el6.centos.i686 2/6
Updating : httpd-2.2.15-54.el6.centos.i686 3/6
Cleanup : httpd-2.2.15-26.el6.centos.i686 4/6
Cleanup : httpd-tools-2.2.15-26.el6.centos.i686 5/6
Cleanup : openssl-1.0.0-27.el6.i686 6/6
Verifying : httpd-2.2.15-54.el6.centos.i686 1/6
Verifying : openssl-1.0.1e-48.el6_8.3.i686 2/6
Verifying : httpd-tools-2.2.15-54.el6.centos.i686 3/6
Verifying : openssl-1.0.0-27.el6.i686 4/6
Verifying : httpd-tools-2.2.15-26.el6.centos.i686 5/6
Verifying : httpd-2.2.15-26.el6.centos.i686 6/6

Updated:
httpd.i686 0:2.2.15-54.el6.centos

Dependency Updated:
httpd-tools.i686 0:2.2.15-54.el6.centos openssl.i686 0:1.0.1e-48.el6_8.3

Complete!

开机启动Apache
chkconfig --list | grep httpd

[[email protected] 桌面]# chkconfig --list |grep httpd
httpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭

chkconfig httpd on  设置httpd每次开机自己启动,但并不现在就启动。运行级别2345都为on
service httpd start     现在启动httpd服务,但是下次开机不会自动启动

[[email protected] 桌面]# chkconfig --list |grep httpd
httpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
service httpd status
[[email protected] 桌面]# service httpd status
httpd (pid 3346) 正在运行...
iptables中开放80端口
此时只能虚拟机本机访问80端口,因为iptables中没有开放80端口
此时iptables的运行级别2345都是on
关闭iptables
关闭命令: service iptables stop
永久关闭防火墙:chkconfig iptables off
查看iptables状态 :service iptables status

查看当前iptables状态
    iptables -L -n
    service iptables status

默认iptables中只开放了22端口
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/rc.d/init.d/iptables save  或者 service iptables save #保存配置 
/etc/rc.d/init.d/iptables restart 或者 service iptables restart #重启服务
    
成功

5.安装mysql
http://www.centoscn.com/mysql/2014/1211/4290.html
http://blog.csdn.net/xinxin19881112/article/details/46873811
http://www.linuxidc.com/Linux/2015-01/111413.htm
http://blog.csdn.net/xxd851116/article/details/22947891

安装检查
rpm -qa |grep mysql
yum list installed | grep mysql

[[email protected] 桌面]# rpm -qa |grep mysql
mysql-libs-5.1.66-2.el6_3.i686
[[email protected] 桌面]# yum list installed | grep mysql
mysql-libs.i686 5.1.66-2.el6_3 @anaconda-CentOS-201303020136.i386/6.4

安装命令
yum install mysql
yum install mysql-server
yum install mysql-devel
(yum -y install mysql-server mysql mysql-devel)
安装过程没有出现输入用户名密码的地方,也没有远程访问的设置

安装成功后检查

[[email protected] 桌面]# rpm -qa |grep mysql
mysql-libs-5.1.73-7.el6.i686
mysql-devel-5.1.73-7.el6.i686
mysql-5.1.73-7.el6.i686
mysql-server-5.1.73-7.el6.i686
[[email protected] 桌面]# yum list installed | grep mysql
mysql.i686 5.1.73-7.el6 @base
mysql-devel.i686 5.1.73-7.el6 @base
mysql-libs.i686 5.1.73-7.el6 @base
mysql-server.i686 5.1.73-7.el6 @base
开机启动MySQL
service mysqld status
chkconfig --list | grep mysqld
chkconfig mysqld on
service mysqld start

查看端口:netstat -tnlp,显示3306 已经开启
查看iptables开放端口:service iptables status

ptables中添加3306端口
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save  或者 service iptables save #保存配置 
/etc/rc.d/init.d/iptables restart 或者 service iptables restart #重启服务

[[email protected] 桌面]# service iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3306
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
4 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
5 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
6 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
7 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num target prot opt source destination

MySQL设置
用户名:root
密码: toor
 
 
root 可以空密码登陆
匿名账户也可以登陆
设置root密码

mysql -u root root空密码登陆
select user,host,password from mysql.user; 查看用户信息

设置root用户的密码
set password for [email protected]=password (‘在这里填入root密码‘);
set password for [email protected]=password (‘在这里填入root密码‘);
set password for [email protected]=password (‘在这里填入root密码‘); 绿色的是主机名

匿名账户登录

删除匿名账户登录

删除匿名登录账号
delete from mysql.user where user=‘‘;
刷新
flush privileges;

允许远程连接

CREATE USER ‘root‘@‘%‘ IDENTIFIED BY ‘您的密码‘; ← 增加root用户指定可以任意IP登录,如果想限制只能让指定IP登录请把%替换成IP地址

GRANT ALL PRIVILEGES ON * . * TO ‘root‘@‘%‘ IDENTIFIED BY ‘你的密码‘ WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ; ← 给新添加的root增加权限

刷新
flush privileges;

Navicat 连接成功

6.安装php
安装前检查
rpm -qi php
rpm -qi | grep php
默认没有安装php

yum search all php搜索所有扩展

安装php和扩展
yum install php (没有安装php-devel)

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
php i686 5.3.3-48.el6_8 updates 1.1 M
Installing for dependencies:
php-cli i686 5.3.3-48.el6_8 updates 2.2 M
php-common i686 5.3.3-48.el6_8 updates 531 k

Transaction Summary

Install 3 Package(s)

Total download size: 3.9 M
Installed size: 13 M

重启apache使php生效  /etc/init.d/httpd restart或者service httpd restart

测试php安装是否成功

    此时可以在目录:/var/www/html/下建立一个PHP文件
代码:

<?php phpinfo(); ?>

成功

安装php扩展

yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
按自己需求安装扩展(yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mcrypt php-mbstring php-bcmath php-mhash libmcrypt libmcrypt-devel)
安装完成

重启apache使php生效 /etc/init.d/httpd restart或者service httpd restart

<?php
$test=mysql_connect("localhost","root","toor");
if($test)
echo ‘OK‘;
else
echo ‘NO OK‘;

?>

访问此文件成功
<?php
$servername = "localhost";
$username = "root";
$password = "toor";

// 创建连接
$conn = new mysqli($servername, $username, $password);

// 检测连接
if ($conn->connect_error)
die("连接失败: " . $conn->connect_error);

echo "连接成功";
?>

访问此文件成功
  1. 安装phpmyadmin
    8.Apache 配置
    /etc/httpd/conf 中httpd.conf

ServerRoot "/etc/httpd" 配置文件位置
Listen 80 监听端口
DocumentRoot "/var/www/html" 访问目录

目录访问权限
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

DirectoryIndex index.html index.html.var

AccessFileName .htaccess

.htaccess

以上是关于CentOS 6 手动配置Lamp的主要内容,如果未能解决你的问题,请参考以下文章

CentOS 6 配置静态IP及路由

centos6.6怎么用命令配置ip

Centos 6.5双网卡双IP双网关配置

Centos 6.5双网卡双IP双网关配置

CentOS6源码安装LAMP----基于fastcgi方式(2台机器)

CentOS6.8手动安装MySQL5.6