共计 6253 个字符,预计需要花费 16 分钟才能阅读完成。
一直都是在虚拟机中做实验,头一次在真机安装 CentOS6.6 x86_64 位系统,并安装 LAMP 环境。提前安装必备的软件包,在安装过程中未出现错误;可以使用一键安装 LAMP 脚本执行。
DELL R420 服务器配置 E5-2403 双 cpu,4 核心 8 线程;
[root@localhost ~]# grep “model name” /proc/cpuinfo |uniq
model name: Intel(R) Xeon(R) CPU E5-2403 v2 @ 1.80GHz
[root@localhost ~]# grep -c “processor” /proc/cpuinfo
8
[root@localhost ~]# grep “core id” /proc/cpuinfo |sort |uniq|wc -l
4
Linux 版本及内核版本
[root@localhost ~]# cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m
[root@localhost ~]# uname -r
2.6.32-504.el6.x86_64
安装 LAMP 环境之前需要安装必备的包
yum install wget gcc gcc-c++ make re2c curl curl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel cmake bzip2 bzip2-devel pcre pcre-devel
软件版本:
apache 2.4.12 版本下载 http://mirrors.sohu.com/apache/httpd-2.4.12.tar.gz
MySQL 5.6.24 版本下载 http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.24.tar.gz
php5.6.8 版本下载 http://mirrors.sohu.com/php/php-5.6.8.tar.gz
apr apr-util 下载地址:http://mirrors.cnnic.cn/apache
libmcrypt 下载地址:ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt
编译安装 mysql 5.6.24
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
# make && make install
# echo $?
# 0
创建 mysql 用户,数据库目录,更改权限
1234 # useradd -M -s /sbin/nologin mysql
# mkdir -p /data/mysql
# chown -R mysql:mysql /data/mysql/
# chown -R mysql:mysql /usr/local/mysql/
初始化数据库
# cd /usr/local/mysql/scripts/
# ./mysql_install_db –basedir=/usr/local/mysql/ –datadir=/data/mysql/ –user=mysql
拷贝配置文件,修改 my.cnf
# cp /usr/local/mysql/my.cnf /etc/my.cnf
# vi /etc/my.cnf
[mysqld]
user=mysql
datadir=/data/mysql
default-storage-engine=MyISAM
拷贝启动脚本
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
添加 iptables 规则,允许 3306 端口,并保存防火墙设置。
12 # iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
# /etc/init.d/iptables save
启动 mysqld 服务,并加入开机启动;
# service mysqld start
# chkconfig –add mysqld
# chkconfig mysqld on
设置环境变量,最后一行加入以下内容,保存退出后,source 生效;
# vi /etc/profile
PATH=$PATH:/usr/local/mysql/bin
export PATH
# source /etc/profile
编辑 mysqld 启动脚本,找到 basedir 和 datadir 添加路径;
#vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
编译安装 apache2.4.12
CentOS6 yum 安装的 apr 版本已经不适用 httpd-2.4 版本了。所以,需要源码编译安装 apr 以及 apr-util
#cd /usr/local/src/
#wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz
#wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
编译安装 apr
[root@localhost src]# tar zxf apr-1.5.2.tar.gz
[root@localhost src]# cd apr-1.5.2
[root@localhost apr-1.5.2]# ./configure –prefix=/usr/local/apr
[root@localhost apr-1.5.2]# make && make install
[root@localhost apr-1.5.2]# echo $?
0
编译安装 apr-util
[root@localhost src]# tar zxf apr-util-1.5.4.tar.gz
[root@localhost src]# cd apr-util-1.5.4
[root@localhost apr-util-1.5.4]# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
[root@localhost apr-util-1.5.4]# make && make install
[root@localhost apr-util-1.5.4]# echo $?
0
检查开发环境,没有安装的话使用 yum 安装;
[root@localhost ~]# rpm -qa gcc cmake pcre-devel libmcrypt
libmcrypt-2.5.8-9.el6.x86_64
gcc-4.4.7-11.el6.x86_64
cmake-2.8.12.2-4.el6.x86_64
pcre-devel-7.8-6.el6.x86_64
编译安装 apache
[root@localhost src]# tar zxf httpd-2.4.12.tar.gz
[root@localhost src]# cd httpd-2.4.12
[root@localhost httpd-2.4.12]# ./configure –prefix=/usr/local/apache2 –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util/ –with-pcre –enable-mods-shared=most –enable-so
[root@localhost httpd-2.4.12]# echo $?
0
apache 执行命令目录加入配置文件,生效;
[root@localhost ~]# vi /etc/profile
PATH=$PATH:/usr/local/apache2/bin
[root@localhost ~]# . /etc/profile
添加 iptables 规则,允许 80 端口,并保存防火墙设置。
# iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
# /etc/init.d/iptables save
编辑启动脚本,更改权限,并加入系统服务,设置开机启动;
[root@localhost apache2]# vi /etc/init.d/httpd
[root@localhost apache2]# chmod 755 /etc/init.d/httpd
[root@localhost apache2]# chkconfig –add httpd
[root@localhost apache2]# chkconfig httpd on
检查 apache 配置参数;-l 列出加载的静态模块 - M 列出所有加载的模块;
[root@localhost ~]# apachectl -t
Syntax OK
[root@localhost ~]# apachectl -l
[root@localhost ~]# apachectl -M
编译安装 php 5.6.8
[root@localhost src]# tar zxvf php-5.6.8.tar.gz
[root@localhost src]# cd php-5.6.8
[root@localhost php-5.6.8]# ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs –with-config-file-path=/usr/local/php/etc –with-mysql=/usr/local/mysql –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –with-iconv-dir –with-zlib-dir –with-bz2 –with-openssl –with-mcrypt –enable-soap –enable-gd-native-ttf –enable-mbstring –enable-sockets –enable-exif –disable-ipv6
[root@localhost php-5.6.8]# make && make install
[root@localhost php-5.6.8]# echo $?
0
拷贝 php 配置文件
[root@localhost php-5.6.8]# cp /usr/local/src/php-5.6.8/php.ini-production /usr/local/php/etc/php.ini
修改时区
[root@localhost php-5.6.8]# vi /usr/local/php/etc/php.ini
date.timezone =Asia/Shanghai
配置 php 与 apache
1、修改 AddType 参数,红色为新添加
[root@localhost php-5.6.8]# vi /usr/local/apache2/conf/httpd.conf
# AddType allows you to add to or override the MIME configuration
#AddType application/x-gzip .tgz
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
#AddType text/html .shtml
2、修改 index.html,红色为新添加
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
3、修改 severname,红色为新添加
#ServerName www.example.com:80
ServerName localhost:80
4、测试解析 php,在 /usr/local/apache2/htdocs/ 目录下,写一个测试 php 文件
[root@localhost php-5.6.8]# cat /usr/local/apache2/htdocs/test.php
<?php
echo “PHP 解析正常 \n”;
?>
[root@localhost htdocs]# /etc/init.d/httpd restart
[root@localhost htdocs]# curl localhost/test.php
PHP 解析正常
或者写一个 phpinfo();
至此 LAMP 环境搭建完毕。
LAMP 平台安装 Xcache 和 Memcached 加速网站运行 http://www.linuxidc.com/Linux/2015-06/118835.htm
CentOS 7 下搭建 LAMP 平台环境 http://www.linuxidc.com/Linux/2015-06/118818.htm
CentOS 6.5 系统安装配置 LAMP(Apache+PHP5+MySQL) 服务器环境 http://www.linuxidc.com/Linux/2014-12/111030.htm
Ubuntu 14.04 配置 LAMP+phpMyAdmin PHP(5.5.9) 开发环境 http://www.linuxidc.com/Linux/2014-10/107924.htm
Ubuntu 14.10 下安装 LAMP 服务图文详解 http://www.linuxidc.com/Linux/2014-12/110082.htm
更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-07/120403.htm