首页 > 代码库 > Linux下源码安装LAMP(CentOS 6.8 + Apache2.4 + MySQL5.5 + PHP7)环境
Linux下源码安装LAMP(CentOS 6.8 + Apache2.4 + MySQL5.5 + PHP7)环境
一、简介
PHP已经走过了20年的历史,PHP7对于上一版本的PHP5.*,在性能方面有了跨越式的提升,当然也有一些新增的特性和改变,具体大家可以参考网上更为详细的相关资料文档。
二、系统环境
系统平台:CentOS release 6.8 (Final)
Apache版本:httpd-2.4.6.tar.gz
MySQL 版本:mysql-5.5.53.tar.gz
PHP版本:php-7.1.0.tar.gz
三、安装前准备
1、库文件准备
在安装PHP之前,应先安装PHP需要的最新版本库文件,例如libxml2、libmcrypt以及GD2库等文件。安装GD2库是为了让PHP支持GIF、PNG和JPEG等图片格式,所以在安装GD2库之前还要先安装最新的zlib、libpng、freetype和jpegsrc等库文件。而且中间还会穿插安装一些软件,读者可以按照本节提供的顺序安装。
autoconf-2.69.tar.gz
freetype-2.3.5.tar.gz
libgd-2.1.0.tar.gz
jpegsrc.v7.tar.gz
libmcrypt-2.5.8.tar.gz
libpng-1.2.31.tar.gz
libxml2-2.7.8.tar.gz
zlib-1.2.7.tar.gz
apr-1.5.2.tar.gz
apr-util-1.3.8.tar.gz
pcre-8.32.tar.gz
curl-7.52.1.tar.gz
2、安装系统所需要的相关库文件
如果没有安装则用 yum
# yum -y install make gcc gcc-c++ libaio
3、卸载默认的低版本环境
目前发行的Linux操作系统,如果选择默认全部安装,就已经安装好了LAMP环境,但是相对版本都比较低。
a. 卸载Apache
# rpm -qa |grep httpd
说明:检查是否已经安装了httpd软件包
# rpm -e httpd-2.2.3-63.el5.centos --nodeps
说明:卸载软件包, --nodeps 如果有依赖关系,也强制卸载
# rm -rf /etc/httpd
说明:到原来的apache安装目录下,将其所有的安装目录和文件都删掉
b. 卸载Mysql
# rpm -qa | grep mysql
说明:卸载mysql
c. 卸载Php
# rpm -qa | grep php
说明:卸载PHP
4、关闭selinux,清空防火墙规则
5、使用ssh shell将windows下的13个源码包上传到/usr/local/src 目录下
6、将*.tar.gz源码包逐一解压
四、安装LAMP
1、安装libxml2
# cd /usr/local/src/libxml2-2.7.8
# ./configure --prefix=/usr/local/libxml2
# make && make install
2、安装libmcrypt
# cd /usr/local/src/libmcrypt-2.5.7
# ./configure --prefix=/usr/local/libmcrypt
# make && make install
3、安装zlib
# cd /usr/local/src/zlib-1.2.7
# ./configure --prefix=/usr/local/zlib
# make && make install
4、安装libpng
# cd /usr/local/src/libpng-1.2.10
# ./configure --prefix=/usr/local/libpng
# make && make install
5、安装jpeg7
这个软件包安装有些特殊,其它软件包安装时如果目录不存在,会自动创建,但这个软件包安装时需要手动创建。
# mkdir /usr/local/jpeg7
# mkdir /usr/local/jpeg7/bin
# mkdir /usr/local/jpeg7/lib
# mkdir /usr/local/jpeg7/include
# mkdir -p /usr/local/jpeg7/man/man1
# cd /usr/local/src/jpeg-7
# ./configure --prefix=/usr/local/jpeg7/ --enable-shared --enable-static
# make && make install
6、安装freetype
# cd /usr/local/src/freetype-2.3.5
# ./configure --prefix=/usr/local/freetype
# make
# make install
7、安装autoconf
# cd /usr/local/src/autoconf-2.69
# ./configure
# make && make install
8、安装GD库
# cd /usr/local/src/libgd-2.1.0
# ./configure -prefix=/usr/local/gd2 \
--enable-m4_pattern_allow \
--with-jpeg=/usr/local/jpeg7 \
--with-png=/usr/local/libpng/ \
--with-zlib=/usr/local/zlib/ \
--with-freetype=/usr/local/freetype
# make
#make install
9、安装xpm
# yum -y install libXpm-devel.x86_64
10、安装apr
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr
如果报错:
config.status: executing libtool commands
rm: cannot remove `libtoolT‘: No such file or directory
config.status: executing default commands
# yum -y install libtool
11、安装apr-util
# cd apr-util-1.3.8
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make install
12、安装pcre
# cd pcre-8.32
# ./configure --prefix=/usr/local/pcre
13、安装curl
# cd curl-7.52.1
# ./configure --prefix=/usr/local/curl
# make
# make install
14、安装Apache
# cd /usr/local/src/httpd-2.4.6
# ./configure --prefix=/usr/local/apache2 \
# --with-pcre=/usr/local/pcre \
# --with-apr=/usr/local/apr \
# --with-apr-util=/usr/local/apr-util \
# --with-z=/usr/local/zlib
# --enable-so \
# --enable-expires=shared \
# --enable-rewrite=shared \
# --enable-static-support
15、配置Apache
a.设置apache
根目录:ServerRoot "/usr/local/apache2"
管理员邮箱:ServerAdmin admin@example.com
域名设置:ServerName 127.0.0.0 注:写服务器真实IP地址
b.修改所有文件的权限
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
Satisfy all
</Directory>
<Directory "/usr/local/apache2/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
c.配置根目录
DocumentRoot "/usr/local/apache2/htdocs"
d.配置根目录的权限
<Directory "/usr/local/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Require all granted
</Directory>
e.配置欢迎页(首页)
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
f.加载PHP模块和开启其他扩展
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
Addtype application/x-httpd-php .php .phtml
16、安装MySQL
MySQL自5.5版本以后,就开始使用cmake编译工具了。
tar.gz形式源码编译安装mysql时间要很久,但是用户可以自定义目录结构。
a. 安装系统所需要的库文件及MySQL所依赖的库文件
# yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*
b. 安装cmake
# wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
# yum -y install cmake
c. 编译安装MySQL 5.5.53
# /usr/sbin/groupadd mysql
# /usr/sbin/useradd -g mysql mysql
# tar -zxvf mysql-5.5.53.tar.gz
# cd mysql-5.5.53
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
# -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
# -DEXTRA_CHARSET=all \
#-DDEFAULT_CHARSET=utf8 \
#-DDEFAULT_COLLATION=utf8_general_ci \
#-DWITH_MYISAM_STORAGE_ENGINE=1 \
#-DWITH_INNOBASE_STORAGE_ENGINE=1 \
#-DWITH_READLINE=1 \
#-DENABLED_LOCAL_INFILE=1 \
#-DMYSQL_DATADIR=/usr/local/mysql/data \
#-DWITH_SSL=yes -DMYSQL_USER=mysql
d. 执行安装,需要等待较长时间
# make
# make install
e. 改变目录拥有者和所属组
# chmod +w /usr/local/mysql
# chown -R mysql:mysql /usr/local/mysql
# ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16
# cd support-files
# cp my-large.cnf /etc/my.cnf #复制默认配置文件,适合大型服务器
# cp mysql.server /etc/init.d/mysqld # 复制启动文件
17、配置并启动MySQL
# vi /etc/my.cnf
a.在[mysqld]下面添加
socket = /usr/local/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/mysql_error.log
pid-file = /usr/local/mysql/data/mysql.pid
tmpdir = /tmp
user = mysql
b.在[client]下面添加
socket = /usr/local/mysql/mysql.sock
c.初始化mysql
# /usr/local/mysql/scripts/mysql_install_db \
# --basedir=/usr/local/mysql \
# --datadir=/usr/local/mysql/data \
# --user=mysql
d.将mysql加入服务,开机自启动
# cd /usr/local/mysql/bin
# cp -p /usr/local/mysql/bin/mysqld /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# vi /etc/init.d/mysqld (查找并修改以下内容)
basedir=/usr/local/mysql
datadir=/var/mysql/data
# chkconfig --add mysqld
# chkconfig --level 345 mysqld on
e.为MySQL配置环境变量,方便以后的使用
# export PATH=/usr/local/mysql/bin:$PATH
f.启动 mysql
# service mysqld start
g.为MySQL设置密码
# mysql_secure_installation
18、安装PHP
# cd /usr/local/src/php-7.1.0
# ./configure --prefix=/usr/local/php \
# --with-mysqli=/usr/local/mysql/bin/mysql_config \
# --with-apxs2=/usr/local/apache2/bin/apxs \
# --with-libxml-dir=/usr/local/libxml2/ \
# --enable-sockets --enable-xml \
# --with-curl=/usr/local/curl \
# --with-pdo-mysql=/usr/local/mysql/ \
# --with-jpeg-dir=/usr/local/jpeg7/ \
# --with-png-dir=/usr/local/libpng \
# --with-gd=/usr/local/gd2/ \
# --with-freetype-dir=/usr/local/freetype/ \
# --with-xpm-dir=/usr/include/X11/xpm.h
# make
# make install
19、创建配置PHP文件
# cp -p php.ini-development /usr/local/php/etc/php.ini #复制配置文件,适合开发者
五、测试
1、编写info.php文件,查看php配置详细
# vi /usr/local/apache2/htdocs/info.php
<?php phpinfo(); ?>
本文出自 “marks” 博客,请务必保留此出处http://2477785.blog.51cto.com/2467785/1900045
Linux下源码安装LAMP(CentOS 6.8 + Apache2.4 + MySQL5.5 + PHP7)环境