首页 > 代码库 > lamp编译详解
lamp编译详解
首先确认系统环境:centos6.4 min版本
1、安装需要的开发环境
yum groupinstall "Development Tools" "Server Platform Development" -y
2、下载并安装依赖的包(由于编译的是httpd2.4的版本对apr有更高要求)
wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.2.tar.gz
wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.0.tar.gz
3、开始编译安装依赖包
同步时间:ntpdate time.nist.gov
tar -xf apr-1.6.2.tar.gz
cd apr-1.6.2
./configure --prefix=/usr/local/apr
make && make install
tar xf apr-util-1.6.0.tar.gz
cd apr-util-1.6.0
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
如果在apr-util编译时报错:
解决办法:yum install expat-devel
4、编译httpd2.4
wget http://apache.fayea.com//httpd/httpd-2.4.25.tar.gz
tar xf httpd-2.4.25.tar.gz
cd httpd-2.4.25
由于系统上已经安装了rpm包的httpd所以存在用户apache
[root@zabbix httpd-2.4.25]# id apache
uid=48(apache) gid=48(apache) groups=48(apache)
[root@zabbix httpd-2.4.25]# rpm -qa pcre*
pcre-7.8-6.el6.x86_64
安装依赖包pcre-devel
yum -y install pcre-devel
./configure --prefix=/usr/local/apache2.4 --sysconf=/etc/httpd2.4 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make && make install
将2.4启动的脚本添加到环境变量:
[root@zabbix local]# vim /etc/profile.d/apache2.sh
export PATH=/usr/local/apache2.4/bin:$PATH
[root@zabbix local]# . /etc/profile.d/apache2.sh
[root@zabbix local]# echo $PATH
/usr/local/apache2.4/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
启动httpd2.4服务:
apachectl start
编译安装mysql:
1、创建相应的账户和组
cat /etc/passwd|grep mysql 查看是否存在mysql账号
groupadd -r mysql
useradd -g mysql -r -s /sbin/nologin -M mysql 创建mysql组和mysql账号
2、创建mysql数据目录,并授权
mkdir /data/mydata -pv 创建mysql数据目录
chown -R mysql:mysql /data/mydata 将数据目录的所属组所属用户修改
由于编译的是mysql5.6的版本,所以需要使用cmake
3、下载并安装cmake
下载cmake:
wget https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz
安装cmake:
tar xf cmake-3.7.2.tar.gz
cd cmake-3.7.2
./bootstrap
gmake
make install
4、编译安装mysql
下载mysql源文件:
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.36.tar.gz
tar xf mysql-5.6.36.tar.gz
cd mysql-5.6.36
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mydata \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DWITH_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
5、初始化mysql
chown -R mysql:mysql /usr/local/mysql 修改属组属主
cd /usr/local/mysql/scripts 执行数据初始化
./mysql_install_db --user=mysql --datadir=/data/mydata 执行此步报错:
[root@wadeson scripts]# ./mysql_install_db --user=mysql --datadir=/data/mydata
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run ‘make install‘ to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
解决办法:
解决办法:加上--basedir=/usr/local/mysql
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mydata
cp support-files/my-default.cnf /etc/my.cnf 复制配置文件
增加到配置文件:
【mysqld】
basedir = /usr/local/mysql
datadir = /data/mydata
socket = /tmp/mysql.sock 增加套接字文件
cp support-files/mysql.server /etc/init.d/mysqld 复制启动脚本
vim /etc/profile.d/mysqld.sh
export PATH=$PATH:/usr/local/mysql/bin
. /etc/profile.d/mysqld.sh
chkconfig --add mysqld
chkconfig --list|grep mysqld
[root@wadeson mysql]# service mysqld start
Starting MySQL.Logging to ‘/data/mydata/wadeson.err‘.
. SUCCESS!
[root@wadeson mysql]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 4086/sshd
tcp 0 0 :::22 :::* LISTEN 4086/sshd
tcp 0 0 :::3306 :::* LISTEN 87380/mysqld
编译安装php5.6版本:
1、下载php源码包:http://php.net/releases/
tar xf php-5.6.30.tar.bz2
cd php-5.6.30
编译前yum安装必要的环境
yum install -y libxml2 libxml2-devel bzip2-devel
然后执行编译:
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-mcrypt --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-gd
报错如下:
configure: error: jpeglib.h not found.
解决办法:
yum -y install libjpeg-devel
继续执行,依然报错:
configure: error: png.h not found.
解决办法:
yum -y install libpng-devel
再次执行,还是报错:
configure: error: freetype-config not found
解决办法:
yum install freetype-devel
依然执行./configure,报错:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决办法:
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar xf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install
最后再次执行编译参数,成功
make && make install
上述部分编译参数解释:
--prefix=/usr/local/php:定义安装的路径
--with-mysql=/usr/local/mysql :指定mysql安装目录
--with-mysqli=/usr/local/mysql/bin/mysql_config
--enable-xml :支持扩展标记语言
--enable-sockets :支持sockets
--with-mcrypt :提供加密支持
--with-config-file-path=/etc :在/etc目录下生成配置文件/etc/php.ini
--with-config-file-scan-dir=/etc/php.d :在/etc/php.d目录下有分配置文件
--with-bz2 :支持bz2压缩
--enable-maintainer-zts:支持线程的模块,如果使用prefork请不要加入该选项,可通过命令httpd -V显示当前加载的模块
查看当前编译的httpd2.4支持的mpm:
[root@wadeson ~]# /usr/local/apache2.4/bin/httpd -V
AH00557: httpd: apr_sockaddr_info_get() failed for wadeson
AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName‘ directive globally to suppress this message
Server version: Apache/2.4.25 (Unix)
Server built: Jul 7 2017 00:38:29
Server‘s Module Magic Number: 20120211:67
Server loaded: APR 1.6.2, APR-UTIL 1.6.0
Compiled using: APR 1.6.2, APR-UTIL 1.6.0
Architecture: 64-bit
Server MPM: prefork 支持的prefork模块,于是php没有上述选项
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/usr/local/apache2.4"
-D SUEXEC_BIN="/usr/local/apache2.4/bin/suexec"
-D DEFAULT_PIDLOG="logs/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="/etc/httpd2.4/mime.types"
-D SERVER_CONFIG_FILE="/etc/httpd2.4/httpd.conf"
复制php.ini主配置文件:
cp php.ini-production /etc/php.ini
然后将httpd与php进行连接,因为httpd是编译安装的2.4的版本:
[root@wadeson httpd2.4]# pwd
/etc/httpd2.4
[root@wadeson httpd2.4]# ll
total 124
drwxr-xr-x. 2 root root 4096 Jul 7 00:40 extra
-rw-r--r--. 1 root root 18991 Jul 7 16:22 httpd.conf
-rw-r--r--. 1 root root 18759 Jul 7 15:46 httpd.conf.bak
-rw-r--r--. 1 root root 13077 Jul 7 00:40 magic
-rw-r--r--. 1 root root 60855 Jul 7 00:40 mime.types
drwxr-xr-x. 3 root root 4096 Jul 7 00:40 original
在http.conf配置文件中加入以下:
DirectoryIndex index.html index.php
AddType application/x-httpd-php-source .phps
AddHandler php5-script .php
AddType text/html .php
并且确认php的模块已经被启用:(因为这种模式是和httpd模块的方式)
LoadModule php5_module modules/libphp5.so (这是针对prefork模式)
区分:
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
然后在网站目录编写index.php测试页面:
[root@wadeson htdocs]# cat index.php
<?php
phpinfo();
?>
然后测试是否与数据库mysql连接:
[root@wadeson htdocs]# vim index.php
<?php
phpinfo();
$link = mysql_connect(‘127.0.0.1‘,‘root‘,‘‘);
if ($link)
echo "successful";
else
echo "failure";
mysql_close()
?>
/usr/local/php/bin/php -i:查看所有配置信息
为php5.6增加xcache模块:
wget http://xcache.lighttpd.net/pub/Releases/3.0.1/xcache-3.0.1.tar.gz
tar xf xcache-3.0.1.tar.gz
cd xcache-3.0.1
/usr/local/php/bin/phpize
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make && make install 后执行报错
报错如下:
.0.1/xcache.c -fPIC -DPIC -o .libs/xcache.o
/root/tools/xcache-3.0.1/xcache.c: In function ??zif_xcache_get_special_value?ˉ:
/root/tools/xcache-3.0.1/xcache.c:324: error: ??IS_CONSTANT_ARRAY?ˉ undeclared (first use in this function)
/root/tools/xcache-3.0.1/xcache.c:324: error: (Each undeclared identifier is reported only once
/root/tools/xcache-3.0.1/xcache.c:324: error: for each function it appears in.)
make: *** [xcache.lo] Error 1
上面的内容会报错,原因是php5.6 xcache3.0并不支持,所以官网下载最新版,所以还是多去官网或权威网站比较好
于是下载新版本:
wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
tar xf xcache-3.2.0.tar.gz
cd xcache-3.2.0
/usr/local/php/bin/phpize
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make && make install
出现下面所示:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
[root@wadeson xcache-3.2.0]# ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
total 1264
-rwxr-xr-x. 1 root root 589332 Jul 7 15:46 opcache.so
-rwxr-xr-x. 1 root root 701379 Jul 7 16:48 xcache.so
把主配置文件放到php的碎片配置小分队
[root@wadeson xcache-3.2.0]# mkdir /etc/php.d
[root@wadeson xcache-3.2.0]# cp xcache.ini /etc/php.d/
修改/etc/php.d/xcache.ini文件中的指定地方
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/xcache.so
重启服务:
[root@wadeson httpd2.4]# /usr/local/apache2.4/bin/apachectl restart
于是整个lamp环境已经编译成功
note:
如果在编译php遇见了其他错误可以参考如下内容:
http://www.poluoluo.com/jzxy/201505/364819.html
lamp编译详解
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。