基于centOS6.7搭建LAMP(httpd-2.4.18+mysql-5.5.47+php-5.6.16)环境

首先确保系统可以联网。设置IP地址以及虚拟机安装linux在此略过。本文采用centos6.7 64位minimal版、php5.6.16、httpd-2.4.18、mysql-5.5.47版搭建lamp环境。默认设置软件下载目录/usr/local/src,软件安装目录/app/local/下,安装顺序是apache→mysql→php。通过搜狐镜像获取apache、mysql、php
搜狐镜像:http://mirrors.sohu.com/

wget http://mirrors.sohu.com/apache/httpd-2.4.18.tar.gz#若是提示没有wget命令则yum -y install wget

wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.47.tar.gz

wget http://mirrors.sohu.com/php/php-5.6.12.tar.bz2

wget http://www.apache.org/dist/apr/apr-1.5.2.tar.gz

wget http://www.apache.org/dist/apr/apr-util-1.5.4.tar.gz

wget https://sourceforge.net/projects/pcre/files/pcre/8.10/pcre-8.10.tar.gz

wget http://xmlsoft.org/sources/libxml2-2.7.4.tar.gz

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz

wget ftp://ftp.cn.debian.org/gentoo/distfiles/zlib-1.2.5.1.tar.gz

wget http://zlib.net/zlib-1.2.8.tar.gz

wget https://sourceforge.net/projects/libpng/files/libpng12/1.2.56/libpng-1.2.56.tar.xz

wget http://www.ijg.org/files/jpegsrc.v9b.tar.gz

wget https://sourceforge.net/projects/freetype/files/freetype2/2.4.12/freetype-2.4.12.tar.bz2

wget https://github.com/libgd/libgd/archive/gd-2.1.1.tar.gz

wget http://ftp.ntu.edu.tw/gnu/autoconf/autoconf-2.53.tar.gz

wget https://github.com/libgd/libgd/releases/download/gd-2.1.1/libgd-2.1.1.tar.bz2

wget https://cmake.org/files/v3.1/cmake-3.1.3.tar.gz

首先安装相应的库文件:
yum -y install xz  libXpm-devel lua-devel libxslt-devel gcc gcc-c++libjpeg libjpeg-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

新建相应的目录和用户和用户组:

mkdir -p /app/local/{php,apache,mysql,data}
groupadd -g 500 www
useradd -u 500 -g 500 -G 500 -s /sbin/nologin www

groupadd mysql

useradd -g mysql mysql -s /bin/false

#cd /usr/local/src/

#tar zxvf  apr-1.5.2.tar.gz

#cd apr-1.5.2

#./configure --prefix=/usr/local/apr

报错提示:cannot remove `libtoolT’: No such file or directory ,

解决办法:编辑 configure文件,查找 $RM "$cfgfile" 这个地方,用#注释掉,然后就可以了

#./configure --prefix=/usr/local/apr

#make && make install

#cd ../

#tar zxvf apr-util-1.5.4.tar.gz

#cd apr-util-1.5.4

#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config

#make && make install

#cd../

#tar zxvf pcre-8.10.tar.gz

#cd pcre-8.10

#./configure --prefix=/usr/local/pcre

#make && make install

#cd ../

安装Apache

#tar zxvf httpd-2.4.18.tar.gz

#cd httpd-2.4.18

#./configure --prefix=/app/local/apache --enable-mods-shared=all --enable-so --enable-proxy-ajp --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre

#make && make install

#cd ../

#chown -R www:www /app/local/apache/htdocs/

#chmod 755 /app/local/apache/htdocs/

先配置一下httpd.conf
找到;ServerName www.example.com:80
改为ServerName localhost:80
#/app/local/apache/bin/apachectl -k start

在浏览器下输入ip地址查看apache是否成功启动
如果没有的话 可能是selinux和防火墙没有做相应设置
vi /etc/sysconfig/iptables
在端口22下一行加入80 3306端口配置(分别是apache和mysql的端口)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
:wq保存退出
service iptables restart #重启防火墙使配置生效
然后在关闭selinux
vi /etc/sysconfig/selinux
改为SELINUX=disabled
:wq#保存退出
setenforce 0 #使配置立即生效
然后安装mysql,首先安装cmake
#tar zxvf cmake-3.1.3.tar.gz
#cd cmake-3.1.3
#./configure
#make && make install
#cd ../
#tar zxvf mysql-5.5.47.tar.gz
#cd mysql-5.5.47
#cmake -DCMAKE_INSTALL_PREFIX=/app/local/mysql -DMYSQL_DATADIR=/app/local/data -DSYSCONFDIR=/etc
#make && make install
#cd ../
#chown -R mysql:mysql /app/local/data
# cp /app/local/mysql/support-files/my-innodb-heavy-4G.cnf /etc/my.cnf
#ln -s /app/local/mysql/my.cnf /etc/my.cnf
#cd /app/local/mysql/
#./scripts/mysql_install_db --user=mysql --basedir=/app/local/mysql --datadir=/app/local/data
#cp support-files/mysql.server /etc/init.d/mysql
#chkconfig mysql on
#service mysql start
#cd /usr/local/src
最后安装php
#tar zxvf libxml2-2.7.4.tar.gz
#cd libxml2-2.7.4
#./configure --prefix=/usr/local/libxml2

报错提示:cannot remove `libtoolT’: No such file or directory ,

解决办法:编辑 configure文件,查找 $RM "$cfgfile" 这个地方,用#注释掉,然后就可以了

#./configure --prefix=/usr/local/libxml2

#make && make install

#cd ../

#tar zxvf libmcrypt-2.5.7.tar.gz

#cd libmcrypt-2.5.7

#./configure --prefix=/usr/local/libmcrypt

#make && make install

#cd ../

#tar zxvf zlib-1.2.8.tar.gz

#cd zlib-1.2.8

#./configure

#make && make install

#cd ../

#xz -d libpng-1.2.56.tar.xz

#tar -xvf libpng-1.2.56.tar

#cd libpng-1.2.56

#./configure --prefix=/usr/local/libpng

#make && make install

#cd ../

#mkdir -p /usr/local/jpeg6/{bin,lib,include,man}

#mkdir /usr/local/jpeg6/man/man1

#tar zxvf jpegsrc.v9b.tar.gz

#cd jpeg-9b/

#./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static

#make && make install

#cd ../

#tar jxvf freetype-2.4.12.tar.bz2

#cd freetype-2.4.12

#./configure -prefix=/usr/local/freetype

#make && make install

#cd ../

#tar zxvf autoconf-2.53.tar.gz

#cd autoconf-2.53

#./configure

#make && make install

#cd ../

#tar jxvf libgd-2.1.1.tar.bz2

#cd libgd-2.1.1

#./configure --prefix=/usr/local/gd2  --with-zlib=/usr/local/zlib --with-jpeg=/usr/local/jpeg6 --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype/

#make && make install

#cd ../

#tar jxvf php-5.6.12.tar.bz2

#cd php-5.6.12

#./configure --prefix=/app/local/php --with-config-file-path=/app/local/php/etc --with-apxs2=/app/local/apache/bin/apxs --with-mysql --with-libxml-dir=/usr/local/libxml2 --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg6 --with-freetype-dir=/usr/local/freetype --with-gd=/usr/local/gd2 --with-zlib-dir=/usr/local/zlib --with-mcrypt=/usr/local/libmcrypt --with-mysqli --with-xpm-dir=/usr/lib64 --enable-soap --enable-mbstring=all --enable-sockets

#make && make install

#cd ../

#cp /usr/local/src/php-5.6.12/php.ini-production /app/local/php/etc/php.ini
#vi /app/local/php/etc/php.ini
找到;date.timezone
改为date.timezone=PRC
保存退出
配置apache解析php:
#vi /app/local/apache/conf/httpd.conf

找到;ServerName www.example.com:80
改为ServerName localhost:80
找到:AddType application/x-gzip .gz .tgz
在该行下面添加:AddType application/x-httpd-php .php
找到DirectoryIndex index.html 
改为:DirectoryIndex index.html index.htm index.php
找到User daemon Group daemon
注释后添加:User www
                    Group www

找到: Options  Indexes FollowSymLinks
修改为:Options   FollowSymLinks
找到:AllowOverride None
修改为:AllowOverride All

equire all granted

最后保存退出#/app/local/apache/bin/apachectl -t#测试httpd.conf 如果有错误,会有提示, 如果是正确的则显示为 “Syntax OK”

#/app/local/apache/bin/apachectl  start

#ps -ef|grep httpd

root     12130  1259  0 15:49 pts/0    00:00:00 grep httpd
root     23172     1  0 14:13 ?        00:00:00 /app/local/apache/bin/httpd -k start
www      23173 23172  0 14:13 ?        00:00:02 /app/local/apache/bin/httpd -k start
www      23174 23172  0 14:13 ?        00:00:02 /app/local/apache/bin/httpd -k start
www      23175 23172  0 14:13 ?        00:00:02 /app/local/apache/bin/httpd -k start

说明已经启动
#vi /app/local/apache/htdocs/info.php

<?php
phpinfo();
?>
保存退出后在浏览器输入ip地址/info.php后检测是否成功

如图所示

基于centOS6.7搭建LAMP(httpd-2.4.18+mysql-5.5.47+php-5.6.16)环境

基于centOS6.7搭建LAMP(httpd-2.4.18+mysql-5.5.47+php-5.6.16)环境

上一篇:Tomcat服务器绑定域名的配置


下一篇:Tomcat服务器下 catalina.out 日志开关