php+mysql(5.1)+apache+centos 编译安装

领导要求先保证php环境稳定,然后再去考虑其他,例如性能,安全等等,所以先参考yum的php+mysql+apache的配置来建造。so,就是这样子,按照yum的软件版本和配置重新编译安装php套件环境。

列一下整个过程的大纲:

  1. 安装的软件的版本和配置和模块确认和下载
    1. 检查版本、配置、模块
    2. 下载
  2. 安装apache
    1. configure
    2. make
    3. make install
    4. 启动
    5. 检查
  3. 安装mysql
    1. configure
    2. make
    3. make install
    4. 初始化数据库
    5. 启动
    6. 检查
  4. 安装php
    1. configure
    2. make
    3. make install
    4. 配置
    5. 启动
    6. 检查

1. 安装的软件的版本和配置和模块确认和下载

查看配置参数和模块:

mysql:
查看版本

rpm -qa |grep mysql
mysql-server-5.1.73-3.el6_5.x86_64
mysql-5.1.73-3.el6_5.x86_64
mod_auth_mysql-3.0.0-11.el6_0.1.x86_64
apr-util-mysql-1.3.9-3.el6_0.1.x86_64
mysql-devel-5.1.73-3.el6_5.x86_64
mysql-libs-5.1.73-3.el6_5.x86_64

查看配置

cat /usr/lib64/mysql/mysqlbug |grep configure
CONFIGURE_LINE=”./configure ‘–build=x86_64-redhat-linux-gnu’ ‘–host=x86_64-redhat-linux-gnu’ ‘–target=x86_64-redhat-linux-gnu’ ‘–program-prefix=’ ‘–prefix=/usr’ ‘–exec-prefix=/usr’ ‘–bindir=/usr/bin’ ‘–sbindir=/usr/sbin’ ‘–sysconfdir=/etc’ ‘–datadir=/usr/share’ ‘–includedir=/usr/include’ ‘–libdir=/usr/lib64’ ‘–libexecdir=/usr/libexec’ ‘–localstatedir=/var’ ‘–sharedstatedir=/var/lib’ ‘–mandir=/usr/share/man’ ‘–infodir=/usr/share/info’ ‘–with-readline’ ‘–with-ssl=/usr’ ‘–without-debug’ ‘–enable-shared’ ‘–with-embedded-server’ ‘–localstatedir=/var/lib/mysql’ ‘–with-unix-socket-path=/var/lib/mysql/mysql.sock’ ‘–with-mysqld-user=mysql’ ‘–with-extra-charsets=all’ ‘–with-big-tables’ ‘–with-pic’ ‘–with-plugin-innobase’ ‘–with-plugin-innodb_plugin’ ‘–with-plugin-partition’ ‘–enable-local-infile’ ‘–enable-largefile’ ‘–enable-thread-safe-client’ ‘–disable-dependency-tracking’ ‘build_alias=x86_64-redhat-linux-gnu’ ‘host_alias=x86_64-redhat-linux-gnu’ ‘target_alias=x86_64-redhat-linux-gnu’ ‘CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC’ ‘CXXFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -felide-constructors -fno-rtti -fno-exceptions'”

apache :
版本查看:

rpm -qa |grep httpd
httpd-tools-2.2.15-31.el6.centos.x86_64
httpd-manual-2.2.15-31.el6.centos.noarch
httpd-2.2.15-31.el6.centos.x86_64
httpd-devel-2.2.15-31.el6.centos.x86_64

无法完整的查看配置

/usr/sbin/httpd -l
Compiled in modules:
core.c
prefork.c
http_core.c
mod_so.c
/usr/sbin/httpd -V
Server version: Apache/2.2.15 (Unix)
Server built: Jul 23 2014 14:17:29
Server’s Module Magic Number: 20051115:25
Server loaded: APR 1.3.9, APR-Util 1.3.9
Compiled using: APR 1.3.9, APR-Util 1.3.9
Architecture: 64-bit
Server MPM: Prefork
threaded: no
forked: yes (variable process count)
Server compiled with….
-D APACHE_MPM_DIR=”server/mpm/prefork”
-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=128
-D HTTPD_ROOT=”/etc/httpd”
-D SUEXEC_BIN=”/usr/sbin/suexec”
-D DEFAULT_PIDLOG=”run/httpd.pid”
-D DEFAULT_SCOREBOARD=”logs/apache_runtime_status”
-D DEFAULT_LOCKFILE=”logs/accept.lock”
-D DEFAULT_ERRORLOG=”logs/error_log”
-D AP_TYPES_CONFIG_FILE=”conf/mime.types”
-D SERVER_CONFIG_FILE=”conf/httpd.conf”

cat /etc/httpd/modules/mod_
mod_actions.so mod_authn_dbm.so mod_authz_owner.so mod_dav.so mod_ext_filter.so mod_log_forensic.so mod_proxy_ftp.so mod_status.so
mod_alias.so mod_authn_default.so mod_authz_user.so mod_dbd.so mod_filter.so mod_logio.so mod_proxy_http.so mod_substitute.so
mod_asis.so mod_authn_file.so mod_autoindex.so mod_deflate.so mod_headers.so mod_mime_magic.so mod_proxy_scgi.so mod_suexec.so
mod_auth_basic.so mod_authnz_ldap.so mod_cache.so mod_dir.so mod_ident.so mod_mime.so mod_proxy.so mod_unique_id.so
mod_auth_digest.so mod_authz_dbm.so mod_cern_meta.so mod_disk_cache.so mod_include.so mod_negotiation.so mod_reqtimeout.so mod_userdir.so
mod_authn_alias.so mod_authz_default.so mod_cgid.so mod_dumpio.so mod_info.so mod_proxy_ajp.so mod_rewrite.so mod_usertrack.so
mod_authn_anon.so mod_authz_groupfile.so mod_cgi.so mod_env.so mod_ldap.so mod_proxy_balancer.so mod_setenvif.so mod_version.so
mod_authn_dbd.so mod_authz_host.so mod_dav_fs.so mod_expires.so mod_log_config.so mod_proxy_connect.so mod_speling.so mod_vhost_alias.so

cat /etc/httpd/conf/httpd.conf |less
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule substitute_module modules/mod_substitute.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule version_module modules/mod_version.so

只知道它使用了动态编译模块,模块的数量不少,使用的mpm是prefork模式,其他都看不出来了。

php:

/usr/bin/php -i |grep configure
PHP Warning: Directive ‘register_globals’ is deprecated in PHP 5.3 and greater in Unknown on line 0
Configure Command => ‘./configure’ ‘–build=x86_64-redhat-linux-gnu’ ‘–host=x86_64-redhat-linux-gnu’ ‘–target=x86_64-redhat-linux-gnu’ ‘–program-prefix=’ ‘–prefix=/usr’ ‘–exec-prefix=/usr’ ‘–bindir=/usr/bin’ ‘–sbindir=/usr/sbin’ ‘–sysconfdir=/etc’ ‘–datadir=/usr/share’ ‘–includedir=/usr/include’ ‘–libdir=/usr/lib64’ ‘–libexecdir=/usr/libexec’ ‘–localstatedir=/var’ ‘–sharedstatedir=/var/lib’ ‘–mandir=/usr/share/man’ ‘–infodir=/usr/share/info’ ‘–cache-file=../config.cache’ ‘–with-libdir=lib64’ ‘–with-config-file-path=/etc’ ‘–with-config-file-scan-dir=/etc/php.d’ ‘–disable-debug’ ‘–with-pic’ ‘–disable-rpath’ ‘–without-pear’ ‘–with-bz2’ ‘–with-exec-dir=/usr/bin’ ‘–with-freetype-dir=/usr’ ‘–with-png-dir=/usr’ ‘–with-xpm-dir=/usr’ ‘–enable-gd-native-ttf’ ‘–without-gdbm’ ‘–with-gettext’ ‘–with-gmp’ ‘–with-iconv’ ‘–with-jpeg-dir=/usr’ ‘–with-openssl’ ‘–with-pcre-regex=/usr’ ‘–with-zlib’ ‘–with-layout=GNU’ ‘–enable-exif’ ‘–enable-ftp’ ‘–enable-magic-quotes’ ‘–enable-sockets’ ‘–enable-sysvsem’ ‘–enable-sysvshm’ ‘–enable-sysvmsg’ ‘–with-kerberos’ ‘–enable-ucd-snmp-hack’ ‘–enable-shmop’ ‘–enable-calendar’ ‘–without-sqlite’ ‘–with-libxml-dir=/usr’ ‘–enable-xml’ ‘–with-system-tzdata’ ‘–enable-force-cgi-redirect’ ‘–enable-pcntl’ ‘–with-imap=shared’ ‘–with-imap-ssl’ ‘–enable-mbstring=shared’ ‘–enable-mbregex’ ‘–with-gd=shared’ ‘–enable-bcmath=shared’ ‘–enable-dba=shared’ ‘–with-db4=/usr’ ‘–with-xmlrpc=shared’ ‘–with-ldap=shared’ ‘–with-ldap-sasl’ ‘–with-mysql=shared,/usr’ ‘–with-mysqli=shared,/usr/lib64/mysql/mysql_config’ ‘–enable-dom=shared’ ‘–with-pgsql=shared’ ‘–enable-wddx=shared’ ‘–with-snmp=shared,/usr’ ‘–enable-soap=shared’ ‘–with-xsl=shared,/usr’ ‘–enable-xmlreader=shared’ ‘–enable-xmlwriter=shared’ ‘–with-curl=shared,/usr’ ‘–enable-fastcgi’ ‘–enable-pdo=shared’ ‘–with-pdo-odbc=shared,unixODBC,/usr’ ‘–with-pdo-mysql=shared,/usr/lib64/mysql/mysql_config’ ‘–with-pdo-pgsql=shared,/usr’ ‘–with-pdo-sqlite=shared,/usr’ ‘–with-sqlite3=shared,/usr’ ‘–enable-json=shared’ ‘–enable-zip=shared’ ‘–without-readline’ ‘–with-libedit’ ‘–with-pspell=shared’ ‘–enable-phar=shared’ ‘–with-tidy=shared,/usr’ ‘–enable-sysvmsg=shared’ ‘–enable-sysvshm=shared’ ‘–enable-sysvsem=shared’ ‘–enable-posix=shared’ ‘–with-unixODBC=shared,/usr’ ‘–enable-fileinfo=shared’ ‘–enable-intl=shared’ ‘–with-icu-dir=/usr’ ‘–with-enchant=shared,/usr’ ‘–with-recode=shared,/usr’

2. 安装的软件的版本和配置和模块确认和下载:

(可以通过rpm -qa mysql或者yum install mysql 类似这样查看软件的版本)

centos 版本:6.5 x64 官网下载或者163源下载

中国centos网
http://www.centoscn.com/plus/download.php?open=2&id=2196&uhash=1dacefcfd3a0ece94e06c929

官网
http://isoredirect.centos.org/centos/6.5/isos/

chinaunix
http://download.chinaunix.net/download/0013000/12271.shtml

163源
http://mirrors.163.com/centos/6.5/isos/

apache 版本:2.2.27

http://httpd.apache.org/download.cgi#apache22

mysql 版本:5.1.733

去官网下载的话需要注册一个账号然后选择源码的下载
http://dev.mysql.com/downloads/file.php?id=453362

php版本:5.3.28

http://cn2.php.net/get/php-5.3.28.tar.gz/from/a/mirror

安装相关的库,开发工具,编译软件,调用的模块和软件

yum -y install gcc
yum -y install make
yum -y install gcc-c++
yum -y install apr
yum -y install pcre*
yum -y install apr-util*
yum -y install libtool
yum -y install openssl
yum -y install openssl-devel
(因为心脏漏洞的关系centos的openssl要升级到1.0.1e-16以上)
#####检查:
#####[root@localhost app]# rpm -q --changelog openssl-1.0.1e | grep CVE-2014-0160
#####- fix CVE-2014-0160 - information disclosure in TLS heartbeat extension
#####代表已修复
yum -y install enchant-devel
yum -y install libjpeg* libpng* gmp*
yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc perl-DBD-MySQL unixODBC-devel
yum -y install libXpm*
yum -y install libicu*
yum -y install aspell-devel
yum -y install libedit-dev*
yum -y install recode-dev*
yum -y install net-snmp-devel
yum -y install libtidy-dev*
yum -y install libxml2

开始安装

安装顺序是有讲究的,因为php需要调用apache 和mysql的配置,所以需要先安装apache和mysql,而后者的他们不需要固定的安装顺序。
编译安装一般是3个顺序,configure,make,make install

1.安装apache

进入apache的源码包解压目录,运行以下命令:
首先是配置编译参数—configure

./configure \
–with-mpm=prefork \
–enable-so \
–enable-mods-shared=most \
–prefix=/app/apache2227 \
–with-apr-util=/usr/bin/apu-1-config

备注:

 1. 使用--enable-mods-shared=most是跟--enable-so搭配使用的,most是指将大部分常用的模块编译成动态模块,动态模块就是需要load加载的模块,好处是
    加载和卸载方便,坏处就是效率上没有静态编译快,在小规模使用上一般差距不大,所以我使用动态编译模块。
 2. --with-apr-util是翻译过来APR(Apache portable Run-time libraries,Apache可移植运行库),主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。具体参考百度百科或者wiki
 3. --with-mpm=prefork则只使用prefork模块,Possible MPMs are beos, mpmt_os2, prefork, and worker.一般prefork常用且好用。

然后是进行编译—make

make -j4

最后是进行安装—install

make install

引用参考:
1. http://httpd.apache.org/docs/2.2/install.html
2. http://httpd.apache.org/docs/2.2/programs/configure.html
3. http://apr.apache.org/

启动apache

/app/apache2227/bin/apachctl start

检查

ps -ef |grep httpd
netstat -atnp|grep 80

(一般会使用80,根据配置文件的listen端口而定)
访问一个apache的网页文件,可以将一个普通的html文件放进去htdoc的目录来访问,也可以直接访问看到apache的官方页面

2.安装mysql

进入mysql的源码包解压目录,将以下命令放在一个可执行的shell文件里面(因为命令过长的关系,写到shell文件里会好很多),
具体步骤是

1.vi test.sh
2.粘贴进去
3.保存退出:wq!
4.检查文件内容是否正确
5.授予可执行权限chmod +x test.sh
6. sh test.sh执行(可以sh -x test.sh执行来观察执行过程)
7.make -j4
8.make install

粘贴到shell文件的编译参数如下:

CFLAGS=”-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC ” CXXFLAGS=”-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -felide-constructors -fno-rtti -fno-exceptions”
./configure \
–disable-dependency-tracking \
–prefix=/app/mysql51733 \
–sysconfdir=/app/mysql51733 \
–datadir=/app/mysql51733/data \
–libdir=/usr/lib64 \
–with-readline \
–without-debug \
–enable-shared \
–with-embedded-server \
–with-unix-socket-path=/var/lib/mysql/mysql.sock \
–with-mysqld-user=mysql \
–with-extra-charsets=all \
–with-big-tables \
–with-pic \
–with-plugins=partition,innobase,innodb_plugin \
–enable-local-infile \
–enable-largefile \
–enable-thread-safe-client \
–with-client-ldflags=-all-static \
–with-mysqld-ldflags=-all-static

备注:

1.  -sysconfdir是my.cnf的路径
2.  -without-debug取消debug模式,有效提供效率
3.  -with-extra-charsets=all安装所有字符集
4.  -enable-local-infile允许本地导入数据,例如
5.  -libdir是指生成的mysql的相关库文件的目录
6.  -enable-local-infile:启用对LOAD DATA LOCAL INFILE语法的支持,即用sql可以导入本地文件到数据库
7.  -with-readline是一个行编辑库,这个是跟shell的readline参数是一样的,mysql也是这样使用
8.  -with-unix-socket-path指定socket的位置和名字
9.  -with-big-tables支持超过4G以上的大表
10.  --enable-assembler:使用汇编模式;(文档说明:compiling in x86 (and sparc) versions of common string operations, which should result in more performance.  汇编x86的普通操作符,可以提高性能)
11.  --with-pic Try to use only PIC/non-PIC objects,PIC是跟gcc 内核和硬件有关的,具体百度,这里是both的作用,所以加也无妨。
12.  --with-plugins=partition,innobase,innodb_plugin支持不同的引擎,例如innobase
13.  --enable-thread-safe-client很有名的参数,让mysqlclient支持线程的意思
14.  --with-mysqld-ldflags=-all-static 静态编译MySQL服务器端;(据说静态链接提高13%性能,嘛,静态编译的速度总是会快一点的)
15.  --with-client-ldflags=-all-static 静态编译MySQL客户端;(据说静态链接提高13%性能)

引用参考:

 1. http://dev.mysql.com/doc/refman/5.1/en/source-configuration-options.html
 2. https://linuxtoy.org/archives/readline.html
 3. http://docs.linuxtone.org/ebooks/Optimze/Interrupt%20in%20Linux.pdf

troubleshooting

  • 编译MySQL的过程中提示:
    >/bin/rm: cannot remove `libtoolt’: No such file or directory

解决:
网上说并且官方也有提到用这个方法,但是不行

1. 确认libtool是否已经安装,如果没有安装的话,则先安装libtool
    yum -y install libtool
2. 分别执行以下三条命令:
    autoreconf --force --install
    libtoolize --automake --force
    automake --force --add-missing
    再重新编译安装,问题解决!

我用这个方法的:
这时直接打开 configure,把 $RM “$cfgfile” 那行删除掉,重新再运行 ./configure 就可以了。

  • 配置configure完成后进行make的时候会出现一个问题,提示无法找到mysqlclient的库

需要

cp -r /usr/lib64/mysql /app/mysql51733/lib64

原因是因为编译安装mysql的时候自定义安装目录后却没有修改他的lib64库的使用路径,理论上会用相对路径,跟随安装安装目录一起变化,但是5.1的mysql没有这样做,用的是的绝对路径/usr/lib64/mysql,所以需要手动复制到指定的目录

至此完成mysql安装

  • 安装完成后需要初始化数据库,但5.1会出现这个问题,这是一个已知的在mysql5.1的bug
/app/mysql51733/bin/mysql_install_db --user=mysql --basedir=/app/mysql51733/ --datadir=/app/mysql51733/data

FATAL ERROR: Could not find errmsg.sys

The following directories were searched:

    /app/mysql51733//share/english
    /app/mysql51733//share/mysql/english

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.

需要

cp /app/mysql51733/data/mysql/english/errmsg.sys /app/mysql51733/share/english/
cp /app/mysql51733/data/mysql/*.sql /app/mysql51733/share/

引用参考:
1. http://bugs.mysql.com/bug.php?id=38828

  • 复制源码包的配置文件

cp support-files/的my-small.cnf, my-medium.cnf, my-large.cnf, and my-huge.cnf 复制为指定目录的my.cnf,分别对应不同使用等级的mysql配置,不过实际上还是针对生产环境做修改的
需要注意的是:

  1. my.cnf里面需要配置datadir位置,不然的话会造成mysql启动失败,因为mysql.server启动脚本如果检查到没有datadir值就会只用默认值来启动,而一般编译我们都没有默认目录的。

目前这个安装是我建议复制到/app/mysql51733/my.cnf这里

引用参考:
1. http://dev.mysql.com/doc/refman/5.6/en/option-files.html

复制源码包的启动脚本到系统守护程序管理目录,可以方便启动关闭和做自动启动

cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
service mysql start
Starting MySQL [确定]

例如开机自动启动

chkconfig –add mysql
有的系统需要下面的,表示3,4,5等级的启动都要开启,3代表命令行界面,5代表图形界面
chkconfig –level 345 mysql on

检查是否成功启动
ps -ef |grep mysql

root 7167 1658 0 06:03 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe –user=mysql
mysql 7405 7167 0 06:03 pts/0 00:00:00 /usr/local/mysql/bin/mysqld –basedir=/usr/local/mysql –datadir=/data/mysql/data –plugin-dir=/usr/local/mysql/lib/plugin –user=mysql –log-error=/data/mysql/data/testyuan.err –pid-file=/data/mysql/data/testyuan.pid –socket=/tmp/mysql/mysql.sock –port=3306

netstat -atnp|grep 3306

/app/mysql51733/bin/mysql -uroot -p

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.4-m7 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

php安装

进入php源码目录,运行以下命令,(因为太长的关系,所以最好将其写进一个shell文件,然后执行这个shell脚本)

./configure –libdir=/app/php5328/lib64 –with-libdir=lib64 \
–prefix=/app/php5328 \
–includedir=/app/php5328/include \
–with-apxs2=/app/apache2227/bin/apxs \
–sysconfdir=/app/php5328 \
–with-config-file-path=/app/php5328 \
–with-config-file-scan-dir=/app/php5328/php.d \
–disable-debug \
–with-pic \
–disable-rpath \
–without-pear \
–with-bz2 \
–with-freetype-dir=/usr \
–with-png-dir=/usr \
–with-xpm-dir=/usr \
–enable-gd-native-ttf \
–without-gdbm \
–with-gettext \
–with-gmp \
–with-iconv \
–with-jpeg-dir=/usr \
–with-openssl \
–with-pcre-regex=/usr \
–with-zlib \
–with-layout=GNU \
–enable-exif \
–enable-ftp \
–enable-magic-quotes \
–enable-sockets \
–enable-sysvsem \
–enable-sysvshm \
–enable-sysvmsg \
–enable-ucd-snmp-hack \
–enable-shmop \
–enable-calendar \
–without-sqlite \
–with-libxml-dir=/usr \
–enable-xml \
–enable-pcntl \
–enable-mbstring=shared \
–enable-mbregex \
–with-gd=shared \
–enable-bcmath=shared \
–enable-dba=shared \
–with-db4=/usr \
–with-xmlrpc=shared \
–with-ldap=shared \
–with-ldap-sasl \
–with-mysql=/app/mysql51733 \
–with-mysqli=shared,/app/mysql51733/bin/mysql_config \
–enable-dom=shared \
–with-pgsql=shared \
–enable-wddx=shared \
–with-snmp=shared,/usr \
–enable-soap=shared \
–with-xsl=shared,/usr \
–enable-xmlreader=shared \
–enable-xmlwriter=shared \
–with-curl=shared,/usr \
–enable-pdo=shared \
–with-pdo-odbc=shared,unixODBC,/usr \
–with-pdo-mysql=shared,/app/mysql51733/bin/mysql_config \
–with-pdo-pgsql=shared,/usr \
–with-pdo-sqlite=shared,/usr \
–with-sqlite3=shared,/usr \
–enable-json=shared \
–enable-zip=shared \
–without-readline \
–with-libedit \
–with-pspell=shared \
–enable-phar=shared \
–with-tidy=shared,/usr \
–enable-sysvmsg=shared \
–enable-sysvshm=shared \
–enable-sysvsem=shared \
–enable-posix=shared \
–with-unixODBC=shared,/usr \
–enable-fileinfo=shared \
–enable-intl=shared \
–with-icu-dir=/usr \
–with-enchant=shared,/usr \
–with-recode=shared,/usr \
–enable-zip

备注:
很多配置,只说重要的,模块是按需而定。一般的类库,例如gd,pcre,curl,zlib,iconv等都通过yum来安装,因为位置都统一,所以安装和使用起来都方便。

 1.--with-mysql 指定连接的mysql
 2.--with-mysqli mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。
 3.--with-apxs2 编译共享的 Apache 2.0 模块,就是将php以模块的方式编译,利用apache的apxs来生成php模块,给apache调用
 4.--with-config-file-path 指定php.ini的位置
 5.--with-gd  使用gd库,gd,jpeg,png,freetype都是跟图形制图有关的,所以需要一起使用,以便达到好的效果,而这些软件一般都通过yum安装,使用默认目录/usr方便处理他们之间的关联和寻找
 6.--with-jpeg-dir 使用jpeg
 7.--with-png-dir 使用png
 8.--with-freetype-dir 使用freetype
 9.--with-pcre-regex perl的正则库的位置
 10.--with-curl 让php使用curl,curl是一个强大的上传下载工具

一般来说,php编译会出现较多的问题是缺少需要的库,你调用了某个模块,但是你系统却没有这个库,这样的时候很多时候会提示not found之类,通过yum将包都安装好后就不会有问题了。

make

make install
安装完成后可以看到php的安装目录有文件,并且php模块已经生成在apache的moudle目录下面libphp5.so

  • 复制源码包里面的phpini模板到php.ini的指定目录
    cp php.ini-production /app/php5328/php.ini (因为编译的时候指定了php.ini的位置)

  • 修改部分php.ini配置(按需)
    修改时区

    ;date.timezone =
    改为
    date.timezone = Asia/Shanghai

  • 修改使用的模块
    找到; extension_dir = “./”; On windows:; extension_dir = “ext”
    添加一行 extension_dir = “/app/php5328/lib64/20090626/” 这里是模块的位置
    然后进行模块加载
    如:extension=bcmath.so

  • 配置apache使用php模块并支持php后缀的文件
    编辑httpd.conf
    在LoadModule的行附件增加一行

    LoadModule php5_module modules/libphp5.so
    (如果需要改端口还需要改Listen,如果需要改运行用户还需要改User)

  • 在AddType 行附件添加下面2行

    AddType application/x-httpd-php .php .php3
    AddType application/x-httpd-php-source .phps
    保存退出

  • 使用vhost配置(方便管理)
    vhost配置如下
    在httpd.conf下增加监听端口8093,如果不需要的话,可以直接用80,但要加端口的话必须先监听

    Listen 8093

    然后编辑conf/extra/http-vhosts.conf

    注释掉
    #NameVirtualHost *:80
    添加下面的段落

    #ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot “/app/apache2227/htdocs/test”
    #ServerName dummy-host.example.com
    #ServerAlias www.dummy-host.example.com
    ErrorLog “logs/8093-error_log”
    CustomLog “logs/8093-access_log” common

    保存退出

    重启apache

    /app/apache2227/bin/apachectl restart

    测试:
    将一个phpinfo.php的页面放到/app/apache2227/htdocs/test目录下

    访问http://IP:8093/phpinfo.php 就可以看到效果了。

引用参考:

 1.http://php.net/manual/zh/configure.about.php
 2.http://php.net/manual/zh/faq.installation.php
 3.http://php.net/manual/zh/faq.using.php 关于 register_globals 对我有什么影响?http://php.net/manual/zh/ini.core.php#ini.register-globals
 4.http://php.net/manual/zh/ini.core.php
 5.http://php.net/manual/zh/ini.php

全程安装完成。感谢。

    原文作者:线上猛如虎
    原文地址: https://segmentfault.com/a/1190000000664596
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞