DELL R420服务器搭建LAMP环境

一直都是在虚拟机中做实验,头一次在真机安装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环境搭建完毕。

相关推荐