LAMP环境官方最新源码编译安装
Posted xuxingzhuang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LAMP环境官方最新源码编译安装相关的知识,希望对你有一定的参考价值。
前言
Linux+Apache+mysql/MariaDB+Perl/php/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注。从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案.
环境
- 系统
- Red Hat Enterprise Linux Server release 6.4
- 软件
- httpd-2.4.20 + mysql-5.7.12 + php-5.5.36
- 编译环境
- -前提你系统必须具备编译安装的环境,如不具备先进行编译环境的安装
编译安装Apache前预准备
首先编译安装Apache之前我们要先解决依赖关系 http-2.4.20安装前解决依赖关系先安装apr、apr-util和pcre,安装这apr和apr-util软件包有两种方式
第一、升级本机RPM包
第二、进行源码编译安装,此处我们通用源码编译安装
安装Apache前的依赖包的安装
- 编译安装apr(apr-1.5.2.tar.gz)
下载地址: http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz
[root@server1 src]# tar zxvf apr-1.5.2.tar.gz
[root@server1 src]# cd apr-1.5.2
[root@server1 apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@server1 apr-1.5.2]# make && make install
- 编译安装apr-util(apr-util-1.5.4.tar.gz)
下载地址: http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz
[root@server1 src]# tar zxvf apr-util-1.5.4.tar.gz
[root@server1 apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #编译安装apr-util必须指定apr的安装位置
[root@server1 apr-util-1.5.4]# make && make install
- 编译安装pcre (pcre-8.38.tar.gz) ## 此处你也可以进行本地RPM包的安装
下载地址: https://sourceforge.net/projects/pcre/files/pcre/8.38/pcre-8.38.tar.gz/download
[root@server1 src]# tar zxvf pcre-8.38.tar.gz
[root@server1 src]# cd pcre-8.38
[root@server1 pcre-8.38]# ./configure --prefix=/usr/local/pcre
[root@server1 src]# make && make install
编译安装Apache
下载地址: http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.20.tar.gz
[root@server1 src]# tar zxvf httpd-2.4.20.tar.gz
[root@server1 src]# cd httpd-2.4.20
[root@server1 httpd-2.4.20]# ./configure \\
--prefix=/usr/local/apache --sysconfdir=/etc/httpd \\
--enable-so --enable-ssl --enable-cgi --enable-rewrite \\
--with-zlib --with-pcre=/usr/local/pcre \\
--with-apr=/usr/local/apr \\
--with-apr-util=/usr/local/apr-util \\
--enable-mods-shared=most --enable-mpms-shared=all \\
--with-mpm=event
[root@server1 httpd-2.4.20]# make && make install
选项解释:
--prefix=/usr/local/apache # 指定安装目录
--sysconfdir=/etc/httpd # 指定配置文件安装路径
--enable-so --enable-ssl #允许运行时加载DSO模块 # 启动ssl加密功能
--enable-cgi --enable-rewrite # 启用cgi协议 #启用URL重写功能
--with-zlib --with-pcre # 指定pcre的安装路径
--with-apr=/usr/local/apr #指定apr的安装路径
--with-apr-util=/usr/local/apr-util # 指定apr-util的安装路径
--enable-modules=most # 启用大多数共享模块
--enable-mpms-shared=most #启用MPM大多数参数
--with-mpm=event #指定使用的MPM的类型
- 启动Apache服务并验证
[root@server1 bin]# ./apachectl start # 找到我们编译安装时指定的安装路径下bin目录下
[root@server1 bin]# crul http://localhost # 验证apache是否可以正常访问
- 修改apache的配置文件并设置PidFile路径(默认在/usr/local/apache/logs/httpd.pid)
[root@server1 bin]# ./apachectl stop # 先停止apache服务
[root@server1 bin]# vim /etc/httpd/httpd.conf # 添加以下内容
PidFile "/var/run/httpd.pid"
[root@server1 bin]# ./apachectl start
- 编写服务脚本/etc/init.d/httpd,让其可以使用service起停,并可以加到服务列表中
[root@server1 ~]# vim /etc/init.d/httpd #添加以下内容
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \\
# html files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
<1> 给脚本添加执行权限
[root@server1 ~]# chmod +x /etc/init.d/httpd
[root@server1 ~]# service httpd start
Starting httpd: [ OK ]
[root@server1 ~]# service httpd status
httpd (pid 3365) is running...
<2> 将httpd服务加到服务列表中,并设置在235级别开机启动
[root@server1 ~]# chkconfig --add httpd
[root@server1 ~]# chkconfig httpd --level 235 on
[root@server1 ~]# chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:off 5:on 6:off
- 将/usr/local/apache/bin加入到PATH路径中去,让其中的命令可以进行全局执行
[root@server1 ~]# vim /etc/profile.d/apache.sh # 脚本的名字必须要以.sh命名
export PATH=$PATH:/usr/local/apache/bin
编译安装MySQL前预准备
安装前预准备,创建用户和组,在Mysql5.5以后版本中编译工具变成了cmake,编译前确认系统已安装cmake编译工具。
- 建立mysql组和用户,并将mysql用户添加到mysql组
[root@server1 src]# groupadd mysql
[root@server1 src]# useradd -g mysql mysql
- 编译安装cmake工具(cmake-3.5.2.tar.gz)
下载地址: https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz –no-check-certificate
[root@server1 src]# tar zxvf cmake-3.5.2.tar.gz
[root@server1 src]# cd cmake-3.5.2
[root@server1 cmake-3.5.2]# ./bootstrap --prefix=/usr/local/cmake
[root@server1 cmake-3.5.2]# gmake & gmake install #默认安装到/usr/local/bin/cmake
[root@server1 ~]# vim /etc/profile.d/cmake.sh # 将/usr/local/bin加到PATH中
export PATH=$PATH:/usr/local/cmake/bin
- 创建mysql数据文件存放的目录
[root@server1 ~]# fdisk /dev/sdb # 分一个10G大小的分区
[root@server1 ~]# pvcreate /dev/sdb1
[root@server1 ~]# pvcreate /dev/sdb1
[root@server1 ~]# vgcreate myvg /dev/sdb1
[root@server1 ~]# lvcreate -L +10G -n mysql_date myvg
[root@server1 ~]# mke2fs -jv /dev/myvg/mysql_data
[root@server1 ~]# mkdir -p /mydata/mysql_data #建立数据存放目录
[root@server1 ~]# vim /etc/fstab # 设置开机自动挂载
/dev/myvg/mysql_data /mydata ext3 defaults 0 0
[root@server1 ~]# mount -a # 重新加载
[root@server1 /]# chown -R mysql.mysql /mysql_date/ # 将目录属主属组给改为mysql
[root@server1 /]# chmod o-rx mysql_date/mydata/ # 设置其他人没有任何权限
编译安装MySQL
下载地址:wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12.tar.gz
[root@server1 src]# tar zxvf mysql-5.7.12.tar.gz
[root@server1 mysql-5.7.12]#cmake . \\
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \\
-DMYSQL_DATADIR=/mysql_date/mydata \\
-DDOWNLOAD_BOOST=1 \\
-DWITH_BOOST=../boost_1_59_0 \\
-DSYSCONFDIR=/etc \\
-DMYSQL_USER=mysql \\
-DWITH_MYISAM_STORAGE_ENGINE=1 \\
-DWITH_INNOBASE_STORAGE_ENGINE=1 \\
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \\
-DWITH_MEMORY_STORAGE_ENGINE=1 \\
-DWITH_READLINE=1 \\ MySQL的readline library
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \\
-DMYSQL_TCP_PORT=3306 \\
-DENABLED_LOCAL_INFILE=1 \\
-DENABLE_DOWNLOADS=1 \\
-DWITH_PARTITION_STORAGE_ENGINE=1 \\
-DEXTRA_CHARSETS=all \\
-DDEFAULT_CHARSET=utf8 \\
-DDEFAULT_COLLATION=utf8_general_ci \\
-DWITH_DEBUG=0 \\
-DMYSQL_MAINTAINER_MODE=0 \\
-DWITH_SSL:STRING=bundled \\
-DWITH_ZLIB:STRING=bundled
[root@server1 mysql-5.7.12]# make && make install
参数解释:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql # MySQL安装的根目录
-DMYSQL_DATADIR=/mysql_date/mydata # MySQL数据库文件存放目录
-DDOWNLOAD_BOOST=1 #从MySQL 5.7.5开始Boost库是必需的
-DWITH_BOOST=../boost_1_59_0 # boost库安装目录
-DSYSCONFDIR=/etc # MySQL配置文件所在目录
-DMYSQL_USER=mysql # MySQL用户名
-DWITH_MYISAM_STORAGE_ENGINE=1 # MySQL的数据库引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 # MySQL的数据库引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 # MySQL的数据库引擎
-DWITH_MEMORY_STORAGE_ENGINE=1 # MySQL的数据库引擎
-DWITH_READLINE=1 # MySQL的readline library
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock # MySQL的通讯目录
-DMYSQL_TCP_PORT=3306 # MySQL的监听端口
-DENABLED_LOCAL_INFILE=1 # 启用加载本地数据
-DENABLE_DOWNLOADS=1 # MySQL编译时允许自主下载相关文件
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all # 使MySQL支持所有的扩展字符
-DDEFAULT_CHARSET=utf8 # 设置MySQL的默认字符集为utf8
-DDEFAULT_COLLATION=utf8_general_ci #设置MySQL的默认字符校对
-DWITH_DEBUG=0 # 禁用调试模式
-DMYSQL_MAINTAINER_MODE=0
-DWITH_SSL:STRING=bundled # 设置MySQL通讯时支持ssl协议
-DWITH_ZLIB:STRING=bundled # 允许MySQL使用zlib library
- 更改mysql安装目录的属主属组并添加mysql环境变量
[root@server1 mysql]# chown -R mysql.mysql .
[root@server1 mysql]# vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
- 加入服务列表并设置为开机自启
[root@server1 ~]# cd /usr/local/mysql/support-files/
[root@server1 support-files]# cp mysql.server /etc/init.d/mysqld
[root@server1 support-files]# chmod +x /etc/init.d/mysqld # 添加一个执行权限
[root@server1 support-files]# chkconfig mysqld on
[root@server1 support-files]# chkconfig mysqld --level 2345 on
[root@server1 support-files]# chkconfig --list mysqld
[root@server1 support-files]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
- 修改mysql的配置文件,以下内容为自选
[root@server1 ~]# vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
skip-name-resolve
skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
初始化MySQL自身的数据库
- ##“-–initialize”会生成一个随机密码(~/.mysql_secret),而”–initialize-insecure”不会生成密码 ##user表示指定用户 ##basedir表示mysql的安装路径,# datadir表示数据库文件存放路径
[root@server1 ~]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mysql_date/mydata/
- 启动MySQL数据库
[root@server1 ~]# mysqld_safe –user=mysql –datadir=/mysql_date/mydata/ ## datadir指定数据目录
[root@server1 ~]# service mysqld start
Starting MySQL [ OK ]
- 查看MySQL服务的进程和端口
[root@server1 ~]# ps -ef | grep mysqld
root 31618 1 0 16:22 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/mysql_date/mydata --pid-file=/mysql_date/mydata/server1.pid
mysql 32370 31618 0 16:22 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mysql_date/mydata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql_date/mydata/mysql-error.log --open-files-limit=65535 --pid-file=/mysql_date/mydata/server1.pid --socket=/tmp/mysql.sock --port=3306
root 34026 29191 1 16:59 pts/1 00:00:00 grep mysqld
[root@server1 ~]# netstat -an | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
- 初始化MySQL数据库的root用户密码
[root@typecodes mysql]# mysql_secure_installation
............省略前面的过程............
Press y|Y for Yes, any other key for No: y #需要修改密码,所以输入y
There are three levels of password validation policy:
LOW Length >= 8 #只需要长度大于或等于8】
MEDIUM Length >= 8, numeric, mixed case, and special characters #还需要包含数字、大小写和类似于@#%等特殊字符
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file #还需要包含字典文件
............省略剩下的过程............
- 将MySQL数据库的动态链接库共享至系统链接库
[root@server1 ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib [root@server1 ~]# ldconfig -v # 让系统重新读取库文件
- 测试登陆MySQL数据库
[root@server1 ~]# mysql -u root -p
Enter password: # 输入之前设置的密码
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 4
Server version: 5.7.12-log Source distribution
Copyright (c) 2000, 2016, 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支持mcrypt扩展,还需要下载的php扩展包(mcrypt-2.6.8.tar.gz、libmcrypt-2.5.8.tar.gz、mhash-0.9.9.9.tar.gz)
下载地址:
http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz
http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
安装顺序( libmcrypt –> mhash –> mcrypt )
- 编译安装libmcrypt(libmcrypt-2.5.8.tar.gz)
[root@server1 src]# tar zxvf libmcrypt-2.5.8.tar.gz
[root@server1 src]# cd libmcrypt-2.5.8
[root@server1 libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt
[root@server1 libmcrypt-2.5.8]# make && make install
[root@server1 libmcrypt-2.5.8]# vim /etc/ld.so.conf.d/libmcrypt.conf # 此选项为将libmcrypt的库文件能让系统找到,不然后面编译安装mcrypt会报错
/usr/local/libmcrypt/lib
[root@server1 libmcrypt-2.5.8]# ldconfig -v # 重新加载库文件
- 编译安装mhash(mhash-0.9.9.9.tar.gz)
[root@server1 src]# tar -zxvf mhash-0.9.9.9.tar.gz
[root@server1 src]# cd mhash-0.9.9.9
[root@server1 mhash-0.9.9.9]# ./configure
[root@server1 mhash-0.9.9.9]# make && make install
[root@server1 mhash-0.9.9.9]# vim /etc/ld.so.conf.d/mhash.conf # 做添加mhash的库文件让系统找到,不然后面编译安装mcrypt会报错
/usr/local/mhash/lib
[root@server1 mhash-0.9.9.9]# ldconfig -v # 重新加载库文件
- 编译安装mcrypy(mcrypt-2.6.8.tar.gz)
[root@server1 src]# tar zxvf mcrypt-2.6.8.tar.gz
[root@server1 src]# cd mcrypt-2.6.8
[root@server1 mcrypt-2.6.8]# ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt/
[root@server1 mcrypt-2.6.8]# make && make install
编译安装PHP
下载地址:http://cn2.php.net/get/php-5.5.36.tar.bz2/from/this/mirror
[root@server1 src]# tar -zxvf php-5.5.36.tar.gz
[root@server1 php-5.5.36]#./configure
--prefix=/usr/local/php \\
--with-mysql=mysqlnd --with-openssl \\
--with-mysqli=mysqlnd \\
--enable-mbstring --with-freetype-dir \\
--with-jpeg-dir --with-png-dir \\
--with-zlib --with-libxml-dir=/usr \\
--enable-xml --enable-sockets \\
--with-apxs2=/usr/local/apache/bin/apxs \\
--with-mcrypt --with-config-file-path=/etc \\
--with-config-file-scan-dir=/etc/php.d \\
--with-bz2 --enable-maintainer-zts
[root@server1 php-5.5.36]# make && make install
参数解释;
--prefix=/usr/local/php # 指定php安装的路径
--with-mysql=mysqlnd --with-openssl # 指定mysql的安装目录 #支持ssl功能
--with-mysqli=mysqlnd # 可以让mysql与php结合的接口
--enable-mbstring --with-freetype-dir # 指定可以支持中文非一个字节能表示语言 # 加载freetype的头文件,可以支持不同字体
--with-jpeg-dir --with-png-dir # 支持jpep格式图片 #支持pnp格式图片
--with-zlib --with-libxml-dir=/usr # 支持压缩库 # 指定xml的库路径
--enable-xml --enable-sockets #支持扩展标记语言 # 支持套接字的通信功能
--with-mcrypt --with-config-file-path=/etc # 支持额外的加密功能的库 # 指定php配置文件的路径(/etc/php.ini)
--with-config-file-scan-dir=/etc/php.d # 支持php文件的附件配置文件(/etc/php.d/*.ini)
--with-bz2 --enable-maintainer-zts #支持bz2的压缩库 # 此选项是否安装取决于你的Apache工作的mpm模式,
说明:
1、这里为了支持apache的worker或event这两个MPM,编译时使用了–enable-maintainer-zts选项。【prefork不需要加载】【event或work
mpm工作模式必须要加此选项】 验证Apache mpm工作模式命令:httpd -M
2、如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了。mysqlnd从php5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),但从PHP 5.4开始它就是默认设置了。 ./configure –with-mysql=mysqlnd –with-pdo-mysql=mysqlnd
–with-mysqli=mysqlnd
- 为php提供配置文件:
[root@server1 php-5.5.36]# cp php.ini-production /etc/php.ini
- 编辑apache配置文件httpd.conf,以apache支持php
[root@server1 ~]# vim /etc/httpd/httpd.conf
<1> 添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<2> 定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
- 重启apache服务
[root@server1 ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@server1 ~]# netstat -an | grep :80 # apache已启动,并监听80端口
tcp 0 0 :::80 :::* LISTEN
- 编辑Apache的网页测试是否支持php、
[root@server1 ~]# cd /usr/local/apache/htdocs/
[root@server1 htdocs]# vim index.php
<?php
phpinfo();
?>
打开浏览器进行web测试访问
- 编辑Apache的网页测试php是否可以连接MySQL、
[root@server1 htdocs]# vim index.php
<?php
$conn=mysql_connect('localhost','root','xuxingzhuang');
if ($conn)
echo "Success...";
else
echo "Failure...";
?>
打开浏览器进行web测试访问
- 关闭MySQL服务再来测试
[root@server1 htdocs]# service mysqld stop
Shutting down MySQL. [ OK ]
[root@server1 htdocs]# service mysqld status
MySQL is not running [FAILED]
[root@server1 htdocs]# netstat -an | grep 3306
打开浏览器进行web测试访问
到此为止我们基于源码安装的LAMP就搭建好了,在搭建环境的期间出现了好多问题,经过各种的google和前车之鉴,最终还是搭建好了,博客以后还会继续更新。
以上是关于LAMP环境官方最新源码编译安装的主要内容,如果未能解决你的问题,请参考以下文章