CentOS6.4编译安装LAMP:准备工作
前奏:编译安装LAMP前的准备工作:
(1)查看系统版本信息:
[root@localhost ~]# cat /etc/redhat-release
CentOS release 6.4 (Final)
(2)为centos6.4添加epel源:
[root@localhost ~]# rpm-ivh http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm Retrievinghttp://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm warning: /var/tmp/rpm-tmp.mgMNYU: Header V3RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:epel-release ########################################### [100%]
(3)修改字符集为英文,避免安装过程中出项不必要的错误而浪费编译时间进而影响工作效率:修改之后重新登录即可生效。
[root@localhost ~]# vim /etc/sysconfig/i18n LANG="en_US.UTF-8" SYSFONT="latarcyrheb-sun16" 临时修改为[root@localhost ~]# export LANG=en
(4)安装Yum加速组件
[root@localhost ~]# yum -y install yum-fastestmirror [root@localhost ~]# yum repolist [root@localhost ~]# yumclean all Loaded plugins: fastestmirror, security Cleaning repos: base epel extras updates Cleaning up Everything Cleaning up list of fastest mirrors
[root@localhost ~]# yummakecache #重新生成元数据,防止依赖关系被损坏
(5)安装编译软件等所需开发工具包组,记得包组要用英文下的双引号引起来,因为中间有空格,你还记得吗?shell里面用空格的时候会怎样?呵呵
[root@localhost ~]#yum -y groupinstall
"Desktop Platform Development" "Development tools" "Server Platform Development"
若是之前已经安装了也是需要进行这一步的,因为它会把系统自身需要的软件包更新到最新,从而进一步防止系统漏洞,这可是线上经验哦!这一步很有必要,因为前面做的epel源就是为此服务的哦!
(6)yum安装系统所需的必要工具
安装编译LAMP所需各种小工具gcc gcc-c++makeautomake autoconf kernel-devel
安装PHP所需依赖,如libxml2-developenssl-devel curl-devel libjpeg-devel libpng-devel等。
[root@localhost~]# yum -y install
gcc gcc-c++kernel-devel ntp vim-enhanced flex bison autoconf make automake bzip2-develncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-develfreetype-devel libXpm-devel gettext-devel pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devellibxml2-devel curl-devel libiculibicu-devel libmcrypt libmcrypt-devel libmhash libmhash-devel pcre-devellibtool-libs gd file patch mlocate diffutils readline-devel glibc-develglib2-devel libcap-devel
(7) 在编译安装LAMP之前,首先先卸载已存在的rpm包
首先是检查各个软件是否安装
[root@localhost ~]# rpm -q httpd package httpd is not installed [root@localhost ~]# rpm -q mysql package mysql is not installed [root@localhost ~]# rpm -q php package php is not installed
使用yum或rpm工具卸载系统曾经安装的lamp软件
rpm -e httpd rpm -e mysql rpm -e php yum -y remove httpd yum -y remove mysql-server mysql yum -y remove php yum -y remove php-mysql
(8)禁用SeLinux selinux可能会致使编译安装失败,我们先禁用它
[root@localhost ~]# setenforce 0 [root@localhost ~]# getenforce Permissive [root@localhost ~]# sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/sysconfig/selinux #永久禁用,需要重启生效。 [root@localhost ~]# grep ^SELINUX /etc/sysconfig/selinux SELINUX=disabled SELINUXTYPE=targeted
(9)开机启动优化,服务最小化原则
本着服务最小化的原则,本实例安装LAMP也正是为了此目的,关闭一切不需要的服务,目前只开放以下几个服务。
1>清理开机自启动的服务
思路:
1>通过脚本关闭全部的服务
[root@localhost ~]# for test in `chkconfig--list |grep 3:on|awk '{print $1}'`;do chkconfig --level 3 $test off;done
2>执行下面的命令开启需要开机启动的服务
[root@localhost ~]# for test in crondnetwork rsyslog sshd;do chkconfig --level 3 $test on;done
3>优化后的结果是自己想要的吗?
[root@localhost ~]# chkconfig --list |grep 3:on crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
总之就是一个原则,服务器最小化服务原则,专一
使用cmake工具编译安装MySQL5.5<一>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Centos6.4编译LAMP之使用cmake工具编译安装MySQL5.5
1、编译安装cmake工具
MySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具。
因此,我们首先要在系统中源码编译安装cmake工具。
#编译安装
使用下面的链接获取cmake下载地址版本列表:
http://wwwNaNake.org/cmake/resources/software.html
#MySQl下载列表:
http://download.softagency.net/MySQL/Downloads/
#所需源码包:
[root@MySQl55 mysql]# ls -lh total 27M -rw-r--r--. 1 root root 5.8M Jan 17 03:1200pxake-2.8.12.2.tar.gz -rw-r--r--. 1 root root 21M Mar 17 13:08 mysql-5.5.37.tar.gz
编译安装前MySQL的一些准备工作:
#临时修改主机名便于做实验清晰明了:
[root@MySQl55 ~]# hostname
MySQl55
创建MySql及其编译工具cmake存放目录,便于后续的更新管理:
[root@MySQl55 ~]# mkdir /appstores/mysql-pv mkdir: created directory `/appstore' mkdir: created directory `/appstore/mysql' [root@MySQl55 ~]# cd /appstore/mysql/ [root@MySQl55 mysql]# wget http://download.softagency.net/MySQL/Downloads/MySQL-5.5/mysql-5.5.37.tar.gz
[root@MySQl55 mysql]# wget http://wwwNaNake.org/files/v2.8/cmake-2.8.12.2.tar.gz
编译安装cmake
[root@MySQl55 mysql]# tar xfcmake-2.8.12.2.tar.gz [root@MySQl55 mysql]# cd cmake-2.8.12.2 [root@MySQl55 cmake-2.8.12.2]# ./configure [root@MySQl55 cmake-2.8.12.2]# echo $? 0 [root@MySQl55 cmake-2.8.12.2]# make&& make install [root@MySQl55 cmake-2.8.12.2]# echo $? 0
查看下软件包大小
[root@localhost mysql]# du -sh * 41M cmake-2.8.12.2 5.8M cmake-2.8.12.2.tar.gz 195M mysql-5.5.37 21M mysql-5.5.37.tar.gz
2、编译安装配置MySQL
#切换至 MySQL源码 解压目录
[root@MySQl55 mysql]# tar xfmysql-5.5.37.tar.gz [root@MySQl55 mysql]# cd mysql-5.5.37 [root@MySQl55 mysql-5.5.37]# #创建mysql用户和mysql组 [root@localhost ~]# groupadd mysql&& useradd -s /sbin/nologin -g mysql -M mysql [root@localhost ~]# grep mysql /etc/passwd/etc/group /etc/passwd:mysql:x:500:500::/home/mysql:/sbin/nologin /etc/group:mysql:x:500:
#使用cmake组织项目
[root@MySQl55 mysql-5.5.37]# cmake -DCMAKE_INSTALL_PREFIX=/lamp_01/mysql5.5 -DMYSQL_DATADIR=/data/mysql5_5 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0 [root@MySQL55 mysql-5.5.37]# echo $? 0
#安装
[root@MySQl55 mysql-5.5.37]# make&& make install [root@MySQl55 mysql-5.5.37]#echo $? 0
MySQL安装后的基本配置
#创建MySQL数据存放目录,并授权归MySQL用户和组所有
[root@MySQL55 ~]# mkdir /data/mysql55 -pv mkdir: created directory `/data' mkdir: created directory `/data/mysql55'
#设置权限
#创建MySQL用户以及MySQL组
[root@MySQL55 ~]# groupadd mysql &&useradd -s /sbin/nologin -g mysql -M mysql [root@MySQL55 ~]# chown -R mysql.mysql /data/mysql55/ [root@MySQL55~]# chown -R mysql.mysql /data/mysql55/ [root@MySQL55 ~]# ls -ld /data/mysql55/ drwxr-xr-x. 2 mysql mysql 4096 May 13 13:45/data/mysql55/
#复制MySQL配置文件
[root@MySQl55 mysql-5.5.37]# cp ./support-files/my-large.cnf/etc/my.cnf
将mysql的配置文件copy到/etc目录下,并更名为my.cnf 如果你想要设置一个选项文件,使用support-files目录中的一个作为模板。在这个目录中有5个模板文件,是根据不同机器的内存定制的。 进入mysql源码目录,查看所有以.cnf结尾的配置文件 /usr/local/mysql下面有5个my-xxxx.cnf文件my-small.cnf 最小配置安装,内存<=64M,数据数量最少my-large.cnf 内存=512Mmy-medium.cnf 32M<内存<64M,或者内存有128M,但是数据库与web服务器公用内存 my-huge.cnf 1G<内存<2G,服务器主要运行mysqlmy-innodb-heavy-4G.cnf 最大配置安装,内存至少4G [[email protected]]# ll support-files/*.cnf -rw-r--r--. 1 rootroot 4677 May 13 13:36support-files/my-huge.cnf -rw-r--r--. 1 rootroot 19759 May 13 13:36 support-files/my-innodb-heavy-4G.cnf -rw-r--r--. 1 rootroot 4651 May 13 13:36support-files/my-large.cnf -rw-r--r--. 1 rootroot 4662 May 13 13:36support-files/my-medium.cnf -rw-r--r--. 1 rootroot 2826 May 13 13:36 support-files/my-small.cnf
#配置开机自动启动
[root@MySQl55 mysql-5.5.37]# cp./support-files/mysql.server /etc/init.d/mysqld cp: overwrite `/etc/init.d/mysqld'? y [root@MySQl55 mysql-5.5.37]# chmod +700/etc/init.d/mysqld [root@MySQL55 mysql-5.5.37]# ls -l/etc/init.d/mysqld -rwx------. 1 root root 10878 May 13 13:55/etc/init.d/mysqld [root@MySQl55 mysql-5.5.37]# chkconfig--add mysqld [root@MySQl55 mysql-5.5.37]# chkconfig--level 2345 mysqld on
#查看是否已应用上
[root@MySQl55 mysql-5.5.37]# chkconfig--list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
#添加MySQL的软链接以适应init脚本
[root@MySQL55 ~]# ln -sv/lamp_01/mysql5.5/bin/mysql /usr/sbin/mysql `/usr/sbin/mysql' ->`/lamp_01/mysql5.5/bin/mysql' [root@MySQL55 ~]# ln -sv /lamp_01/mysql5.5/bin/mysqladmin /usr/sbin/mysqladmin `/usr/sbin/mysqladmin' ->`/lamp_01/mysql5.5/bin/mysqladmin' [root@MySQL55 ~]# ln -sv/lamp_01/mysql5.5/bin/mysqldump /usr/sbin/mysqldump `/usr/sbin/mysqldump' ->`/lamp_01/mysql5.5/bin/mysqldump'
#修改配置文件
[root@MySQl55 ~]# vim /etc/my.cnf
#在[mysqld]节点中添加:
25 [mysqld] 26 datadir = /data/mysql/ 27 log-error = /data/mysql/error.log 28 pid-file = /data/mysql/mysql.pid 29 tmpdir = /tmp
#保存退出
#初始化数据库
[root@MySQl55 ~]#
/lamp_01/mysql5.5/scripts/mysql_install_db--user=mysql --basedir=/lamp_01/mysql5.5/ --datadir=/data/mysql/
WARNING: The host 'MySQl55' could not belooked up with resolveip.
This probably means that your libclibraries are not 100 % compatible
with this binary MySQL version. The MySQLdaemon, mysqld, should work
normally with the exception that host nameresolving will not work.
This means that you should use IP addressesinstead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK
**************************************************************************
[root@MySQl55 ~]# echo $? 0
#启动MySQL
[root@MySQl55 ~]# service mysqld start
Starting MySQL..... SUCCESS!
#查看是否有mysql进程
[root@MySQl55 ~]# ps -ef |grep mysqld root 3363 1 0 06:09 pts/3 00:00:00 /bin/sh/lamp_01/mysql5.5/bin/mysqld_safe --datadir=/data/mysql/--pid-file=/data/mysql/mysql.pid mysql 3700 3363 2 06:09 pts/3 00:00:00 /lamp_01/mysql5.5/bin/mysqld--basedir=/lamp_01/mysql5.5 --datadir=/data/mysql/ --plugin-dir=/lamp_01/mysql5.5/lib/plugin--user=mysql --log-error=/data/mysql/error.log --pid-file=/data/mysql/mysql.pid--socket=/tmp/mysql.sock --port=3306 root 3727 12779 0 06:09 pts/3 00:00:00 grep mysqld
#查看是否有mysql端口
[root@MySQl55 ~]# netstat -tulanp |grep:3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3700/mysqld
#测试mysql,mysqladmin,mysqldump命令是否能正常使用
[root@MySQl55 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.37-log Sourcedistribution
Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
mysql> \q
Bye
一般都是没问题的,若有问题的话可以vim /etc/profile 添加MySQL的安装路径/bin目录,如安装路径为/usr/local/mysql55 则对应添加为 export PATH=$PATH:/usr/local/mysql55/bin 保存退出后 source /etc/profile使得立即生效!
#读取MySQL的版本信息
[root@MySQl55 ~]# mysqladmin version mysqladmin Ver 8.42 Distrib 5.5.37, for Linux on x86_64 Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved. Oracle is a registered trademark of OracleCorporation and/or its affiliates. Other names may be trademarksof their respective owners. Server version 5.5.37-log Protocol version 10 Connection Localhost via UNIXsocket UNIX socket /tmp/mysql.sock Uptime: 2 min 48 sec Threads: 1 Questions: 4 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables:26 Queries per second avg: 0.023
#到此MySQL编译安装已基本完成,后面会有MySQL详细的优化配置
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MySQL5.5以前的版本(如MySQL5.1.x)./configure 编译参考如下,线上环境的配置哦,可直接使用,哈哈!
./configure \
--prefix=/lamp2_01/mysql5.1.72 \
--with-unix-socket-path=/lamp2_01/mysql5.1.72/tmp/mysql.sock \
--localstatedir=/lamp2_01/mysql5.1.72/data \
--enable-assembler \
--enable-thread-safe-client \
--with-mysqld-user=mysql \
--with-big-tables \
--without-debug \
--with-pthread \
--enable-assembler \
--with-extra-charsets=complex \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile \
--with-plugins=partition,innobase \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Tips:要构建LAMP环境,首先需要安装MySql和Apache,最后才是安装PHP。当然了,具体是先编译安装Apache还是变编译MySQL都是可以的,只要是最后再编译PHP就可以了,因为在编译PHP程序的时候,在编译PHP的参数里面需要指定Apache的apxs工具所在的路径以及MySQL的安装路径;由于这里的PHP编译是以Apache的模块的方式来运行的,要是配置成FastCGI的形式安装顺序也许就无所谓了,因为到目前为止,笔者还没有尝试在多台机器上做过实验,所以不敢肯定的告诉您哦!
比如前端的是一台独立的Apache服务器,后面是一台独立的PHP程序服务器,在后面是一台独立的MySql数据库服务器,这个笔者下次会做实验的。
由于前面MySql5.已经编译完了,那么,我们就一气呵成,再来编译安装Apache的2.4最新版本!最后构建成一个完整的LAMP服务。
编译安装Httpd2.4.9
创建编译Apache源代码程序及其依赖的软件包的存放目录,便于后期管理。
[root@MySQL55 mysql]# mkdir/appstores/apache -pv mkdir: created directory`/appstores/apache'
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apache官方说:
与Apache 2.2.x相比,Apache 2.4.x提供了很多性能方面的提升,包括支持更大流量、更好地支持云计算、利用更少的内存处理更多的并发等。除此之外,还包括性能提升、内存利用、异步I/O的支持、动态反向代理设置、与时间驱动的Web服务器相当或更好的性能、更强大的处理资源分配能力,更便捷的缓存支持以及可定制的高速服务器和代理等。其它的功能还包括更简单的错误分析、更灵活的设置项、更强大的验证机制和更完整的文档。
Apache服务器项目管理委员会和Apache基金会主席JimJagielski表示,他们希望终端用户能真正地看到性能进步,Apache 2.4.x比许多以速度见长的Web服务器更快,例如 Nginx。
apache-2.2与新出的apache-2.4安装不同的地方在于,2.4版的已经不自带apr库,所以在安装apache-2.4之前,需要依次下载和安装apr、apr-util、以及pcre等Apache的相关依赖工具。
谷歌搜索关键字:downloads apr apr-util pcre就会得到它们的官网地址链接。
可到下来的地址去现在所需的apr和apr-util
http://www.apache.org/dist/apr/
[root@MySQl55 apache]# wget http://mirror.esocc.com/apache//apr/apr-1.5.1.tar.gz [root@MySQl55 apache]# wget http://www.apache.org/dist/apr/apr-util-1.5.3.tar.gz
谷歌搜索关键字:pcre downloads indexes
可以到下面的网址去下载pcre http://www.pcre.org/ [root@MySQL55 apache]# [root@MySQL55 apache]# wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz Apache下载列表: http://www.apache.org/dist/httpd/ [root@MySQl55 apache]# wget http://www.apache.org/dist/httpd/httpd-2.4.9.tar.gz
#OK了,工具已经准备齐备啦!可以动工了!
[root@MySQL55 apache]# ls -lhrt total 11M -rw-r--r--. 1 root root 854K Nov 17 01:52apr-util-1.5.3.tar.gz -rw-r--r--. 1 root root 6.5M Mar 17 01:22httpd-2.4.9.tar.gz -rw-r--r--. 1 root root 2.0M Apr 9 02:32 pcre-8.35.tar.gz -rw-r--r--. 1 root root 997K Apr 19 20:06apr-1.5.1.tar.gz [root@MySQL55 apache]# [root@MySQl55apache]# tar xf apr-1.5.1.tar.gz [root@MySQl55 apache]# cd apr-1.5.1 [root@MySQl55 apr-1.5.1]# ./configure--prefix=/usr/local/apr [root@MySQl55 apr-1.5.1]# echo $? 0 [root@MySQl55 apr-1.5.1]# make &&make install [root@MySQl55 apr-1.5.1]# echo $? 0 [root@MySQl55 apr-1.5.1]# cd ../ [root@MySQl55 apache]# tar xfapr-util-1.5.3.tar.gz [root@MySQl55 apache]# cd apr-util-1.5.3 [root@MySQl55 apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr/bin/apr-1-config [root@MySQl55 apr-util-1.5.3]# echo $? 0 [root@MySQl55 apr-util-1.5.3]# make&& make install [root@MySQl55 apr-util-1.5.3]# echo $? 0 [root@MySQl55 apache]# tar xfpcre-8.35.tar.gz [root@MySQl55 apache]# cd pcre-8.35 ./configure --prefix=/usr/local/pcre--with-apr=/usr/local/apr/bin/apr-1-config [root@MySQl55 pcre-8.35]# echo $? 0 [root@MySQl55 pcre-8.35]# make &&make install [root@MySQl55 pcre-8.35]# echo $? 0
#LAMP之编译安装 Apache2.4.9
[root@MySQl55 apache]# cd httpd-2.4.9 [root@MySQl55 httpd-2.4.9]# ./configure--prefix=/lamp_02/httpd24 --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so--enable-deflate=shared --enable-expires=shared --enable-ssl=shared--enable-headers=shared --enable-rewrite=shared --enable-static-support--with-mpm=worker [root@MySQl55 httpd-2.4.9]# echo $? 0 [root@MySQl55 httpd-2.4.9]# make &&make install [root@MySQl55 httpd-2.4.9]# echo $? 0
至此,httpd2.4已经编译完毕。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
编译安装PHP5.4.28
在编译PHP之前,先要解决两个问题:CentOS6.x 上 libmcrypt 的安装和可能有些系统找不到 libiconv 导致的错误。
#创建PHP及其依赖的安装包存放目录:
安装PHP了,就改名为PHP5吧!为了方便记忆
[root@php5_4 ~] # hostname php5_4 [root@php5_4 ~]# mkdir /appstores/php -pv mkdir: created directory `/appstores/php' [root@php5_4 ~]# cd /appstores/php/
检查安装PHP所需lib库
PHP程序在开发时会调用一些诸如gd等函数库,因此需要确认下面的lib库是否已经安装
[root@php5_4 ~]# rpm -qa zlib libxml libjpeg freetype libpng gdcurl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devellibpng-devel gd-devel curl-devel
libpng-1.2.49-1.el6_2.x86_64
freetype-2.3.11-14.el6_3.1.x86_64
curl-7.19.7-35.el6.x86_64
zlib-devel-1.2.3-29.el6.x86_64
libpng-devel-1.2.49-1.el6_2.x86_64
libxml2-devel-2.7.6-14.el6.x86_64
zlib-1.2.3-29.el6.x86_64
freetype-devel-2.3.11-14.el6_3.1.x86_64
也可以检查devel之类的
也可以使用下面的方式来检查这5个软件包也可以达到与上面一样的效果
[root@php5_4 ~]# rpm -qa zlib-devellibxml2-devel libjpeg-devel freetype-devel libpng-devel zlib-devel-1.2.3-29.el6.x86_64 libpng-devel-1.2.49-1.el6_2.x86_64 libxml2-devel-2.7.6-14.el6.x86_64 freetype-devel-2.3.11-14.el6_3.1.x86_64
1、安装PHP依赖库
# 安装 libmcrypt
libmcrypt下载地址链接列表:
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt [root@php5_4 ~]# # cd /appstore/php/ [root@php5_4 ~]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz [root@php5_4 ~]# tar xflibmcrypt-2.5.7.tar.gz [root@php5_4 ~]# cd libmcrypt-2.5.7 [root@ php5_4 libmcrypt-2.5.7]# ./configure --prefix=/usr/local/libmcrypt [root@ php5_4 libmcrypt-2.5.7]# make && make install
#安装 mhash
http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/ [root@php5_4 php]# wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz [root@ php5_4 php]# tar xfmhash-0.9.9.9.tar.gz [root@ php5_4 php]# cd mhash-0.9.9.9 [root@ php5_4 mhash-0.9.9.9]# ./configure--prefix=/usr/local/mhash [root@ php5_4 libmcrypt-2.5.7]# echo $? 0
#安装 mcrypt
http://sourceforge.net/projects/mcrypt/files/MCrypt/ [root@php5_4 php]# wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz [root@php5_4php]# /sbin/ldconfig #搜索出可共享的动态链接库 [root@php5_4 php]# tar xflibmcrypt-2.5.7.tar.gz [root@php5_4 php]# cd libmcrypt-2.5.7 [root@php5_4 libmcrypt-2.5.7]# ./configure--prefix=/usr/local/mcrypt [root@php5_4 libmcrypt-2.5.7]# make && make install [root@php5_4 libmcrypt-2.5.7]# echo $? 0
#安装 libiconv
https://www.gnu.org/software/libiconv/#downloading http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz [root@php5_4 php]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz [root@php5_4 php]# tar xflibiconv-1.14.tar.gz [root@php5_4 php]# cd libiconv-1.14 [root@php5_4 libiconv-1.14]# ./configure--prefix=/usr/local/libiconv [root@php5_4 libiconv-1.14]# make&& make install [root@php5_4 libiconv-1.14]# echo $? 0
#安装PHP
PHP镜像地址列表:
http://php.net/downloads.php [root@php5_4 php]# wget http://cn2.php.net/distributions/php-5.5.12.tar.bz2 [root@php5_4 php]# tar xfphp-5.5.12.tar.bz2 [root@php5_4 php]# cd php-5.5.12
进行到这一步了!
#生成配置
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@php5_4 php-5.5.12]#
./configure --prefix=/lamp_03/php5.4.28--with-mysql=/lamp_01/mysql5.5 --with-apxs2=/lamp_02/httpd24/bin/apxs--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d--with-openssl --with-zlib --with-bz2 --with-gettext --with-mhash=/usr/local/mhash --with-mcrypt=/usr/local/mcrypt --with-iconv=/usr/local/libiconv --with-curl--with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-pdo-mysql=/lamp_01/mysql5.5 --enable-gd-native-ttf --enable-bcmath--enable-mbstring --enable-zip --enable-soap --enable-sockets --enable-ftp--without-pear
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
安装php的时候,报错如下:
Configure: error: Please reinstall the BZip2distribution
解决方法如下:
[root@php5_4php-5.5.12]# yum -y install bzip2bzip2-devel
今天配置一台server的php支持curl的时候, 出现如下报错
checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution -
easy.h should be in /include/curl/
其实就是curl的dev包没有安装, 解决方案:
终端下
[root@php5_4php-5.5.12]# yum -y install curl-devel
然后就可以继续了
#编译
[root@php5_4 php-5.5.12]# make &&make install
编译参数解释:
--prefix=/lamp_03/php5.4.28 : 设置安装路径
--with-apxs2=/usr/local/apache/bin/apxs : 编译共享的 Apache2.0 模块
--with-config-file-path=/etc : 指定配置文件php.ini地址
--with-config-file-scan-dir=/etc/php.d : 指定额外的ini文件目录
--with-openssl : 编译OpenSSL支持
--with-zlib : 编译zlib支持
--enable-bcmath : 启用BC风格精度数学函数
--with-bz2 : BZip2支持
--with-gd : GD支持
--enable-gd-native-ttf : 启用TrueType字符串函数
--with-gettext : 启用GNU gettext支持
--with-mhash : mhash支持
--enable-mbstring : 启用支持多字节字符串
--with-mcrypt : 编译mcrypt加密支持
--enable-zip : 启用zip 读/写支持
--with-iconv=/usr/local/libiconv : iconv支持
--with-curl : CRUL支持
--enable-soap : SOAP支持
--enable-sockets : SOCKETS支持
--enable-ftp : FTP支持
--with-mysql=/usr/local/mysql : 启用mysql支持
--with-pdo-mysql=/usr/local/mysql : 启用pdo-mysql支持
--without-pear : 不安装PEAR
更多编译参数解释参考http://www.php.net/manual/zh/configure.about.php或者 ./configure --help 查看。
配置Apache支持PHP
修改主机名称使得实验一目了然
[root@LAMP ~]# hostname LAMP
[root@LAMP ~]# hostname
为PHP创建软链接:方便线上环境版本更新。
[root@LAMP ~]# ln -s /lamp_03/php5.4.28//lamp_03/php [root@LAMP ~]# ll /lamp_03/php lrwxrwxrwx. 1 root root 19 May 13 16:00/lamp_03/php -> /lamp_03/php5.4.28/
进入PHP源码目录,查看PHP的配置文件
[root@LAMP ~]# cd /appstores/php/php-5.5.12 [root@LAMP php-5.5.12]# ls -l php.ini* -rw-r--r--. 1 1001 1001 69486 Apr 29 16:04php.ini-development -rw-r--r--. 1 1001 1001 69516 Apr 29 16:04php.ini-production
#复制配置文件php.ini
[root@LAMP php-5.5.12]# cp php.ini-production /etc/php.ini
在Apache的配置文件Addtype applicaAddType application/x-gzip.gz.tgz这行下面中加入两行对PHP的文件类型解析(加在Apache配置文件最后也可,这里主要是为了一目了然)
对Apache设置之前需要做的一些操作:
[root@LAMP ~]# ln -s /lamp_02/httpd24//lamp_02/httpd [root@LAMP ~]# ls -l /lamp_02/httpd lrwxrwxrwx. 1 root root 17 May 13 16:10/lamp_02/httpd -> /lamp_02/httpd24/ [root@LAMP ~]# cp/lamp_02/httpd/conf/httpd.conf /lamp_02/httpd/conf/httpd.conf`date +%F` [root@LAMP ~]# diff /lamp_02/httpd/conf/httpd.conf/lamp_02/httpd/conf/httpd.conf2014-05-13
这里需要注意的是httpd2.2系列的版本是在311行左右
转到311行即AddType application/x-gzip.gz.tgz行的下一行添加以下两行对PHP的语句解析支持:
AddType application/x-httpd-php-source.phps AddType application/x-httpd-php .php .phtml
而2.4版本系列的相关配置是在376行左右,当然您也不必纠结于行数,只要在vim Apache的配置文件或者使用grep -n参数都是可以过滤出来在多少行的
[root@php5_4 ~]# grep -n AddType /lamp_02/httpd/conf/httpd.conf 362: # AddType allows you to add to or override the MIME configuration 365: #AddType application/x-gzip .tgz 376: AddType application/x-compress .Z 377: AddType application/x-gzip .gz .tgz 398: #AddType text/html .shtml
#对Apache的一些简单设置
#添加Apache用户和组,方便Apache服务使用哦!
[root@LAMP ~]# groupadd apache &&useradd -s /sbin/nologin -g apache -Mapache [root@LAMP ~]# grep apache /etc/passwd/etc/group /etc/passwd:apache:x:501:501::/home/apache:/sbin/nologin /etc/group:apache:x:501:
#修改完Apache配置之后记得要检查语法,避免启动时错误,浪费时间,影响业务
service httpd restart # 或 /etc/init.d/httpdrestart [root@LAMP ~]#/lamp_02/httpd/bin/apachectl -t Syntax OK [root@LAMP ~]#/lamp_02/httpd/bin/apachectl configtest Syntax OK
#启动Apache
[root@LAMP ~]# /lamp_02/httpd/bin/apachectlstart
#验证Apache进程是否启动
[root@LAMP ~]# ps -ef |grep httpd root 30584 1 0 16:28 ? 00:00:00 /lamp_02/httpd24/bin/httpd -kstart apache 30586 30584 0 16:28 ? 00:00:00 /lamp_02/httpd24/bin/httpd -kstart apache 30587 30584 0 16:28 ? 00:00:00 /lamp_02/httpd24/bin/httpd -kstart apache 30588 30584 0 16:28 ? 00:00:00 /lamp_02/httpd24/bin/httpd -kstart root 30671 30408 0 16:29 pts/1 00:00:00 grep httpd
#验证80端口是否启动
[root@LAMP ~]# netstat -tulanp |grep :80 tcp 0 0 :::80 :::* LISTEN 30584/httpd
#由端口反查进程
[root@LAMP ~]# lsof -i :80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 30584 root 4u IPv6 327633 0t0 TCP *:http (LISTEN) httpd 30586 apache 4u IPv6 327633 0t0 TCP *:http (LISTEN) httpd 30587 apache 4u IPv6 327633 0t0 TCP *:http (LISTEN) httpd 30588 apache 4u IPv6 327633 0t0 TCP *:http (LISTEN)
#写一个调用PHP版本的脚本
[root@LAMP ~]# cd /lamp_02/httpd/htdocs/ [root@LAMP htdocs]# ll total 4 -rw-r--r--. 1 root root 45 Jun 12 2007 index.html [root@LAMP htdocs]# vim index.php [root@LAMP htdocs]# cat index.php <?php phpinfo(); ?>
#运行 phpinfo() 函数,页面信息如下:
#最后再测试PHP连接MySql是否正常 首先是为MySQL设置密码: [root@LAMP ~]# mysqladmin -u root password"123.com"
测试代码如下:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@php5_4 htdocs]# cat test.php
<?php
$link_id=mysql_connect('localhost','root','123.com')or mysql_error();
if ($link_id) {
echo "<h1> mysql successfuly</h1>";
}
else {
echo mysql_error();
}
?>
[root@php
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++