共计 7023 个字符,预计需要花费 18 分钟才能阅读完成。
首先确保系统可以联网。设置 IP 地址以及虚拟机安装 linux 在此略过。本文采用 CentOS 6.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 后检测是否成功
如图所示
下面关于 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
LAMP 结合 NFS 构建小型博客站点 http://www.linuxidc.com/Linux/2015-08/121029.htm
本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-04/130356.htm