CentOS 6.5编译安装LAMP分离环境的搭建

LAMP分离环境的搭建:

环境说明:

CentOS 6.5最小化安装,安装相应的组件:

[[email protected] ~]# yum groupinstall -y"Development tools"

[[email protected] ~]# yum groupinstall -y"Server Platform Development"

准备三台主机:

http: 192.168.1.217

MySQL:192.168.1.218

PHP:192.168.1.1.219

准备的软件包:

[[email protected] ap]# ll

total 92228

-rw-r--r-- 1 root   root    826885 May 22 13:09 apr-1.5.2.tar.bz2

-rw-r--r-- 1 root   root    694427 May 22 13:09 apr-util-1.5.4.tar.bz2

-rw-r--r--. 1 root root  5691656 Jul 9 00:55 cmake-2.8.8.tar.gz

-rwxr--r-- 1 nobody nobody 12490656 Apr 1717:59 Discuz_X3.2_SC_UTF8.zip

-rwxr--r-- 1 nobody nobody  5054838 May 21 17:20 httpd-2.4.12.tar.bz2

-rwxr--r-- 1 nobody nobody   634589 May 22 13:09 libmcrypt-2.5.6.tar.gz

-rwxr--r-- 1 nobody nobody 24680463 Jun 1416:14 mysql-5.5.33.tar.gz

-rwxr--r-- 1 nobody nobody 13724681 May 2117:41 php-5.6.8.tar.bz2

-rwxr--r-- 1 nobody nobody  9955372 May 21 17:58phpMyAdmin-4.4.4-all-languages.zip

-rwxr--r-- 1 nobody nobody   166123 Apr 21 15:37 xcache-3.0.1.tar.gz

[[email protected] ap]#

一、在192.168.1.217主机上安装httpd-2.4.12

从samba共享中下载相应的软件:

[[email protected] ~]# yum -y install samba-client

[[email protected] ~]# smbclient //192.168.1.155/public

smb: \> ls

smb: \> cd ap

smb: \ap\> ls

smb: \ap\> get apr-1.5.2.tar.bz2

getting file \ap\apr-1.5.2.tar.bz2 of size 826885as apr-1.5.2.tar.bz2 (4835.4 KiloBytes/sec) (average 4835.4 KiloBytes/sec)

smb: \ap\> get apr-util-1.5.4.tar.bz2

getting file \ap\apr-util-1.5.4.tar.bz2 ofsize 694427 as apr-util-1.5.4.tar.bz2 (9042.0 KiloBytes/sec) (average 6139.1KiloBytes/sec)

smb: \ap\>

1、在安装httpd之前需要先安装apr、apr-util以及pcre-devel等相关包。在编译安装httpd之前需要Development Tools开发工具集。具体步骤如下:

(1)安装apr

[[email protected] bao]# tar -xf apr-1.5.2.tar.bz2

[[email protected] bao]# cd apr-1.5.2

[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr

[[email protected] apr-1.5.2]# make

[[email protected] apr-1.5.2]# make install

(2)安装apr-util

[[email protected] bao]# tar xf apr-util-1.5.4.tar.bz2

[[email protected] bao]# cd apr-util-1.5.4

[[email protected] apr-util-1.5.4]# ./configure--prefix=/usr/local/apr-util --with-apr=/usr/local/apr/

[[email protected] apr-util-1.5.4]# make

[[email protected] apr-util-1.5.4]# make install

(3)安装pcre-devel

[[email protected] ~]# yum install -y pcre-devel

(4)安装httpd

[[email protected] bao]# tar xf httpd-2.4.12.tar.bz2

[[email protected] bao]# cd httpd-2.4.12

[[email protected] httpd-2.4.12]# ./configure--prefix=/usr/local/apache --sysconfdir=/etc/httpd --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=event --with-included-apr -enable-proxy-enable-proxy-fcgi

说明:

--prefix=/usr/local/apache :安装指定路径。

--sysconfdir=/etc/httpd :指定配置文件安装路径。

--enable-so :支持动态共享模块,如果没有此功能,php无法与apache一起工作,必须安。

--enable-ssl :启用ssl功能,不安装无法启用https。

--enable-rewrite :支持url重写。

--enable-cgi :支持cgi。

在执行configure脚本时,使用–enable-mpms-shared选项即可启用动态构建MPM模块。当给出的参数为all时,所有此平台支持的MPM模块都会被安装。

……………………………………..

configure:

configure: error: Bundled APR requested butnot found at ./srclib/. Download and unpack the corresponding apr and apr-utilpackages to ./srclib/.

[[email protected] httpd-2.4.12]#

错误信息,解决:

[[email protected] bao]# mv apr-1.5.2 apr

[[email protected] bao]# mv apr-util-1.5.4 apr-util

[[email protected] bao]# cp -r apr apr-util httpd-2.4.12/srclib/

[[email protected] bao]#

在编译安装:

[[email protected] httpd-2.4.12]# ./configure--prefix=/usr/local/apache --sysconfdir=/etc/httpd --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=event --with-included-apr -enable-proxy-enable-proxy-fcgi

[[email protected] httpd-2.4.12]# make

[[email protected] httpd-2.4.12]# make install

2、启动服务进行简单测试

[[email protected] ~]# setenforce 0

[[email protected] ~]# service iptables stop

iptables: Setting chains to policy ACCEPT:filter          [  OK  ]

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Unloading modules:                               [  OK  ]

[[email protected] ~]# /usr/local/apache/bin/apachectl start

失败,日志:

[[email protected] logs]# cat error_log

[Wed Jul 08 22:38:15.155125 2015][proxy_balancer:emerg] [pid 45344:tid 139946921051904] AH01177: Failed tolookup provider ‘shm‘ for ‘slotmem‘: is mod_slotmem_shm loaded??

[Wed Jul 08 22:38:15.155262 2015] [:emerg][pid 45344:tid 139946921051904] AH00020: Configuration Failed, exiting

[Wed Jul 08 22:39:07.108730 2015][proxy_balancer:emerg] [pid 45348:tid 139707455522560] AH01177: Failed tolookup provider ‘shm‘ for ‘slotmem‘: is mod_slotmem_shm loaded??

[Wed Jul 08 22:39:07.108852 2015] [:emerg][pid 45348:tid 139707455522560] AH00020: Configuration Failed, exiting

[[email protected] logs]#

原因:

配置文件conf/httpd.conf没有开启 mod_slotmem_shm模块,编辑该文件,放开

LoadModule slotmem_shm_modulemodules/mod_slotmem_shm.so

[[email protected] logs]# vim /etc/httpd/httpd.conf

128 LoadModule slotmem_shm_modulemodules/mod_slotmem_shm.so

[[email protected] ~]# /usr/local/apache/bin/apachectl start

[[email protected] ~]# netstat -lntp

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      1673/sshd

tcp       0      0 127.0.0.1:25     0.0.0.0:*    LISTEN     1026/master

tcp       0      0 :::80       :::*            LISTEN      45379/httpd

tcp       0      0 :::22        :::*           LISTEN      1673/sshd

tcp       0      0 ::1:25      :::*   LISTEN      1026/master

[[email protected] ~]#

浏览器访问:

192.168.1.217

It works!

3、为了更好的管理和使用httpd服务,可为其提供PATH环境变量和SysV风格的脚本。

(1) 提供PATH环境变量:

[[email protected] ~]# vim /etc/profile.d/httpd.sh

export PATH=$PATH:/usr/local/apache/bin

"/etc/profile.d/httpd.sh" [New]1L, 40C written

[[email protected] ~]# . /etc/profile.d/httpd.sh

[[email protected] ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/apache/bin

[[email protected] ~]#

(2) 提供SysV风格的启动脚本:

[[email protected] ~]# vim /etc/init.d/httpd

#!/bin/bash

#

# chkconfig: - 85 15

# description: Apache is a World Wide Webserver. It is used to serve \

. /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 swallowingup a pass-phrase prompt if

# mod_ssl needs a pass-phrase from theuser.

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 mays not

# work correctly with a thread-based MPM;notably PHP will refuse to start.

# Path to the apachectl script, serverbinary, 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 sysntax 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|htlp|configtest|fullstatus)

$apachectl [email protected]

RETVAL=$?

;;

*)

echo "Usage: $prog {start|stop|restart|reload|status|help}"

exit 1

;;

esac

exit $RETVAL

"/etc/rc.d/init.d/httpd" [New]85L, 2084C written

[[email protected] ~]# chmod +x /etc/init.d/httpd

[[email protected] ~]# service httpd status

httpd is stopped

[[email protected] ~]# service httpd start

Starting httpd: httpd (pid 45379) alreadyrunning

[  OK  ]

[[email protected] ~]#

[[email protected] ~]# chkconfig --add httpd

[[email protected] ~]# chkconfig | grep httpd

httpd           0:off   1:off  2:off   3:off   4:off  5:off   6:off

[[email protected] ~]# chkconfig httpd on

[[email protected] ~]# chkconfig | grep httpd

httpd           0:off   1:off  2:on    3:on    4:on   5:on    6:off

[[email protected] ~]#

4、更换pid进程文件存放目录:

每个进程启动后都会有个pid文件,编译安装httpd的pid文件在logs目录里面:

[[email protected] logs]# pwd

/usr/local/apache/logs

[[email protected] logs]# ll

total 12

-rw-r--r--. 1 root root 3527 Jul  8 22:53 access_log

-rw-r--r--. 1 root root  999 Jul 8 22:48 error_log

-rw-r--r--. 1 root root    6 Jul 8 22:48 httpd.pid

[[email protected] logs]#

系统进程一般pid文件都放在/var/run目录下,如果想更换pid进程文件存放目录,需要在主配置文件中加入PidFile  "/var/run/httpd.pid"项,注意:编译安装默认没有该项,需要手工加入:

[[email protected] logs]# vim /etc/httpd/httpd.conf

34 pidfile "/var/run/httpd.pid"

[[email protected] logs]# netstat -lntp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address     Foreign Address    State   PID/Program name

tcp       0      0 :::80            :::*      LISTEN      45379/httpd

[[email protected] logs]# kill 45379

[[email protected] logs]# service httpd start

Starting httpd:                                           [  OK  ]

[[email protected] logs]# cd /var/run/

[[email protected] run]# ll

-rw-r--r--. 1 root      root         6 Jul 8 23:04 httpd.pid

[[email protected] run]#

5、为httpd添加man帮助及输出头文件:

(1) 为httpd添加man帮助:

[[email protected] ~]# yum install -y man pages   (最小化安装系统如果没有man手册需要安装)

[[email protected] ~]# vim /etc/man.config

48 MANPATH /usr/local/apache/man

[[email protected] ~]# man httpd

(2) 输出头文件:

[[email protected] ~]# ln -sv /usr/local/apache/include//usr/include/httpd

`/usr/include/httpd‘ ->`/usr/local/apache/include/‘

[[email protected] ~]#

至此,httpd服务安装成功。

二、编译安装MySQL

1、创建mysql用户和mysql

要想初始化mysql,需要有mysql用户和组。

[[email protected] ~]# groupadd -r -g 306 mysql

[[email protected] ~]# useradd -g 306 -r -u 306 mysql

[[email protected] ~]# id mysql

uid=306(mysql) gid=306(mysql)groups=306(mysql)

[[email protected] ~]#

2、创建mysql数据存放目录

这里练习就在根目录下创建了。

[[email protected] ~]# mkdir /mydata/data -pv

mkdir: created directory `/mydata‘

mkdir: created directory `/mydata/data‘

[[email protected] ~]# ll -d /mydata/ /mydata/data/

drwxr-xr-x. 3 root root 4096 Jul  9 00:45 /mydata/

drwxr-xr-x. 2 root root 4096 Jul  9 00:45 /mydata/data/

[[email protected] ~]#

3、mysql数据目录需要把属主属组更改为mysql,权限更改为0-rwx

[[email protected] mydata]# pwd

/mydata

[[email protected] mydata]# ll

total 4

drwxr-xr-x. 2 root root 4096 Jul  9 00:45 data

[[email protected] mydata]# chown -R mysql:mysql data/

[[email protected] mydata]# chmod o-rwx data/

[[email protected] mydata]# ll

total 4

drwxr-x---. 2 mysql mysql 4096 Jul  9 00:45 data

[[email protected] mydata]#

4、安装cmake编译工具

cmake的重要特性之一是其独立于源码(out-of-source)的编译功能,即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译的影响,因此在同一个源码树上可以进行多次不同的编译,如针对于不同平台编译。

[[email protected] bao]# ll

total 49548

-rw-r--r--. 1 root root  5691656 Jul 9 00:55 cmake-2.8.8.tar.gz

[[email protected] bao]#

[[email protected] bao]# tar xf cmake-2.8.8.tar.gz

[[email protected] bao]# cd cmake-2.8.8

[[email protected] cmake-2.8.8]# ./configure

[[email protected] cmake-2.8.8]# make

[[email protected] cmake-2.8.8]# make install

5、使用cmake编译mysql-5.5

cmake指定编译选项的方式不同于make,其实现方式对比如下:

./configure等于cmake .

./configure –help等同于cmake .-LH or ccmake .

[[email protected] bao]# tar xf mysql-5.5.33.tar.gz

[[email protected] bao]# cd mysql-5.5.33

[[email protected] mysql-5.5.33]# cmake .-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data-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-DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci

[[email protected] mysql-5.5.33]# make

[[email protected] mysql-5.5.33]# make install

说明:

[[email protected] mysql-5.5.28]#

cmake .

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql       (安装路径)

-DMYSQL_DATADIR=/mydata/data     (数据目录存放位置)

-DSYSCONFDIR=/etc                 (配置文件目录)

-DWITH_INNOBASE_STORAGE_ENGINE=1     (是否包含INNOBASE存储引擎)

-DWITH_ARCHIVE_STORAGE_ENGINE=1      (是否包含ARCHIVE存储引擎)

-DWITH_BLACKHOLE_STORAGE_ENGINE=1   (是否包含BLACKHOLE存储引擎,黑洞)

-DWITH_READLINE=1         (使用捆绑的readline,批量导入数据)

-DWITH_SSL=system       (启用ssl功能)

-DWITH_ZLIB=system      (启用zlib压缩功能)

-DWITH_LIBWRAP=0      (不支持libwrap(TCP包装))

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock     (套接字路径)

-DDEFAULT_CHARSET=utf8           (字符集为utf8)

-DDEFAULT_COLLATION=utf8_general_ci   (字符集排序为utf8_general_ci)

编译选项说明:

指定安装文件的安装路径时常用的选项:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql      (安装路径)

-DMYSQL_DATADIR=/data/mysql    (数据文件路径,不指定默认为安装路径下data目录下)

-DSYSCONFDIR=/etc       (配置文件路径)

默认编译的存储引擎包括:csv、myisam、myisammrg和heap。若要安装其它存储引擎,可以使用类似如下编译选项:

-DWITH_INNOBASE_STORAGE_ENGINE=1    (安装INNOBASE存储引擎,就是InnoDB)

-DWITH_ARCHIVE_STORAGE_ENGINE=1     (安装archive存储引擎)

-DWITH_BLACKHOLE_STORAGE_ENGINE=1   (黑洞存储引擎,类似/dev/null)

-DWITH_FEDERATED_STORAGE_ENGINE=1   (5.5不支持,联合存储引擎)

若要明确指定不编译某存储引擎,可以使用类似如下的选项:

-DWITHOUT_<ENGINE>_STORAGE_ENGINE=1

比如:

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1    (不编译EXAMPLE引擎)

-DWITHOUT_FEDERATED_STORAGE_ENGINE=1

-DWITHOUT_PARTITION_STORAGE_ENGINE=1

如若要编译进其它功能,如SSL等,则可使用类似如下选项来实现编译时使用某库或不使用某库:

-DWITH_READLINE=1     (使用捆绑的readline,批量导入数据)

-DWITH_SSL=system      (是否支持SSL)

-DWITH_ZLIB=system     (是否支持Zlib,压缩库)

-DWITH_LIBWRAP=0     (是否包括支持libwrap(TCP包装),不使用)

其它常用的选项:

-DMYSQL_TCP_PORT=3306               (TCP/IP 端口号)

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock   (Unix Socket 套接字文件)

-DENABLED_LOCAL_INFILE=1          (是否启用本地录入文件)

-DEXTRA_CHARSETS=all          (额外的字符集,各种字符)

-DDEFAULT_CHARSET=utf8        (指定MYSQL默认字符集)

-DDEFAULT_COLLATION=utf8_general_ci    (默认排序字符集规则)

-DWITH_DEBUG=0              (是否包括调试支持)

-DENABLE_PROFILING=1    (是否启用代码查询分析,性能分析)

什么是字符集:

字符(Character)是各种文字和符号的总称,包括各国家文字、标点符号、图形符号、数字等。字符集(Character set)是多个字符的集合,字符集种类较多,每个字符集包含的字符个数不同,常见字符集名称:ASCII字符集、GB2312字符集、BIG5字符集、 GB18030字符集、Unicode字符集等。计算机要准确的处理各种字符集文字,需要进行字符编码,以便计算机能够识别和存储各种文字。

汉字字符集:GBK,GB2312,GB18030,UTF8。

如果想清理此前的编译所生成的文件,则需要使用如下命令:

make clean

rm CMakeCache.txt

6、安装完后会在指定安装路径/usr/local目录下有个mysql目录,接下来步骤就和二进制安装方法相同,更改mysql目录下文件的属组为mysql

[[email protected] mysql]# chown -R :mysql /usr/local/mysql/

[[email protected] mysql]# ll

total 200

drwxr-xr-x. 2 root mysql   4096 Jul  9 01:12 bin

-rw-r--r--. 1 root mysql  17987 Jul 15  2013 COPYING

drwxr-xr-x. 3 root mysql   4096 Jul  9 01:11 data

drwxr-xr-x. 2 root mysql   4096 Jul  9 01:11 docs

drwxr-xr-x. 3 root mysql   4096 Jul  9 01:11 include

-rw-r--r--. 1 root mysql 134493 Jul 15  2013INSTALL-BINARY

drwxr-xr-x. 3 root mysql   4096 Jul  9 01:11 lib

drwxr-xr-x. 4 root mysql   4096 Jul  9 01:12 man

drwxr-xr-x. 10 root mysql   4096 Jul 9 01:11 mysql-test

-rw-r--r--. 1 root mysql   2496 Jul 15  2013 README

drwxr-xr-x. 2 root mysql   4096 Jul  9 01:12 scripts

drwxr-xr-x. 27 root mysql   4096 Jul 9 01:12 share

drwxr-xr-x. 4 root mysql   4096 Jul  9 01:12 sql-bench

drwxr-xr-x. 3 root mysql   4096 Jul  9 01:12 support-files

[[email protected] mysql]#

7、手动完成mysql数据库初始化:

[[email protected] mysql]# pwd

/usr/local/mysql

[[email protected] mysql]#scripts/mysql_install_db --user=mysql --datadir=/mydata/data/

8、提供mysql主配置文件,把实例文件复制替换到/etc目录下为my.cnf文件:

[[email protected] mysql]# cp support-files/my-large.cnf /etc/my.cnf

cp: overwrite `/etc/my.cnf‘? y

[[email protected] mysql]# ll /etc/my.cnf

-rw-r--r--. 1 root root 4647 Jul  9 01:18 /etc/my.cnf

[[email protected] mysql]#

9、在配置文件中/etc/my.cnf指定数据文件位置:

[[email protected] mysql]# vim /etc/my.cnf

38 datadir=/mydata/data

"/etc/my.cnf" 147L, 4668Cwritten

[[email protected] mysql]#

10、复制mysql服务脚本到init.d目录下:

[[email protected] mysql]# cp support-files/mysql.server/etc/init.d/mysqld

[[email protected] mysql]# ll -d /etc/init.d/mysqld

-rwxr-xr-x. 1 root root 10871 Jul  9 01:21 /etc/init.d/mysqld

[[email protected] mysql]# chkconfig --add mysqld

[[email protected] mysql]# chkconfig mysqld on

[[email protected] mysql]#

11、启动mysql服务:

[[email protected] ~]# service mysqld start

Starting MySQL.. SUCCESS!

[[email protected] ~]# netstat -lntp

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:3306        0.0.0.0:*      LISTEN      21145/mysqld

[[email protected] ~]#

12、把mysql的bin下命令添加到PATH路径中去,让系统可以直接使用mysql的相关命令:

[[email protected] ~]# vim /etc/profile.d/mysql.sh

export PATH=$PATH:/usr/local/mysql/bin

"/etc/profile.d/mysql.sh" [New]1L, 39C written

[[email protected] ~]# . /etc/profile.d/mysql.sh

[[email protected] ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

[[email protected] ~]#

13、登陆mysql测试连接:

[[email protected] ~]# mysql

……………………………

mysql>

14、修改MySQL的root用户的密码以及打开远程连接:

mysql> use mysql;

Database changed

mysql> desc user;

mysql> GRANT ALL PRIVILEGES ON *.* [email protected]"%" IDENTIFIED BY "123456";

Query OK, 0 rows affected (0.00 sec)

mysql> update user set Password = password(‘123456‘)where User=‘root‘;

Query OK, 4 rows affected (0.00 sec)

Rows matched: 5  Changed: 4 Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql>

15、为mysql添加man帮助及输出头文件和库文件

[[email protected] ~]# yum install -y man pages

[[email protected] ~]# vim /etc/man.config

48 MANPATH /usr/local/mysql/man

[[email protected] ~]# ln -sv /usr/local/mysql/include//usr/include/mysql

`/usr/include/mysql‘ ->`/usr/local/mysql/include/‘

[[email protected] ~]# vim /etc/ld.so.conf.d/mysql.conf

/usr/local/mysql/lib

"/etc/ld.so.conf.d/mysql.conf"[New] 1L, 21C written

[[email protected] ~]#

至此,mysql安装完毕

三、安装PHP

php以php-fpm服务的形式运行,单独调度。如果分开部署可以大大减轻httpd服务器的压力。缺点网络通信不畅的情况下,带宽有可能成为瓶颈。

1、解压并编译安装php-5.6.8

[[email protected] bao]# ll

total 14024

-rw-r--r--. 1 root root   634589 Jul 9 01:40 libmcrypt-2.5.6.tar.gz

-rw-r--r--. 1 root root 13724681 Jul  9 01:39 php-5.6.8.tar.bz2

[[email protected] bao]#

[[email protected] bao]# tar xf php-5.6.8.tar.bz2

[[email protected] bao]# cd php-5.6.8

[[email protected] php-5.6.8]# ./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  --with-mcrypt  --with-config-file-path=/etc--with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts-enable-fpm -with-pdo-mysql=mysqlnd -with-freetype-dir

错误:

checking for xml2-config path...

configure: error: xml2-config not found.Please check your libxml2 installation.

[[email protected] php-5.6.8]#

[[email protected] php-5.6.8]# yum install libxml2-devel –y

在编译:

错误:

checking for BZip2 support... yes

checking for BZip2 in default path... notfound

configure: error: Please reinstall theBZip2 distribution

[[email protected] php-5.6.8]#

[[email protected] php-5.6.8]# yum install bzip2-devel -y

在编译:

错误:

………………

checking for mcrypt support... yes

configure: error: mcrypt.h not found.Please reinstall libmcrypt.

[[email protected] php-5.6.8]#

[[email protected] bao]# tar xf libmcrypt-2.5.6.tar.gz

[[email protected] bao]# cd libmcrypt-2.5.6

[[email protected] libmcrypt-2.5.6]# ./configure

[[email protected] libmcrypt-2.5.6]# make

[[email protected] libmcrypt-2.5.6]# make install

在编译:

[[email protected] php-5.6.8]# ./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-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d--with-bz2 --enable-maintainer-zts -enable-fpm -with-pdo-mysql=mysqlnd-with-freetype-dir

[[email protected] php-5.6.8]# make

[[email protected] php-5.6.8]# make install

安装选项说明:

--prefix=/usr/local/php          (安装目录)

--with-openssl                 (支持openssl功能)

--with-mysql           几个选项都要为mysqlnd;因为mysql服务器单独为另一台主机

--enable-mbstring

--with-freetype-dir        (支持freetype功能,字体库,引用特定字体)

--with-jpeg-dir          (支持jpeg)

--with-png-dir          (支持png)

--with-zlib           (支持通用压缩库)

--with-libxml-dir=/usr      (扩展标记语言,xml库路径位置)

--enable-xml             (支持扩展标记语言)

--enable-sockets          (套接字)

--with-apxs2=/usr/local/httpd24/bin/apxs  替换为 --enable-fpm

--with-mcrypt      (加密库)

--with-config-file-path=/etc    (配置文件位置)

--with-config-file-scan-dir=/etc/php.d (文件php.d目录下也是配置文件一部分)

--with-bz2  (压缩)

--enable-maintainer-zts   (apahce是prwork模式不需要用,其他需要用)

2、给php提供配置文件:

在php安装程序中,有两个文件叫php.ini-development和php.ini-production:

php.ini-development :开发用的配置文件。

php.ini-production :生产环境用的配置文件。

[[email protected] ~]# cp /root/bao/php-5.6.8/php.ini-production/etc/php.ini

[[email protected] ~]# ll -d /etc/php.ini

-rw-r--r--. 1 root root 72369 Jul  9 21:38 /etc/php.ini

[[email protected] ~]#

3、为php-fpm提供Sysv init脚本:

[[email protected] ~]# cp /root/bao/php-5.6.8/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm

[[email protected] ~]# chmod +x /etc/init.d/php-fpm

[[email protected] ~]# chkconfig --add php-fpm

[[email protected] ~]# chkconfig php-fpm on

[[email protected] ~]#

4、为php-fpm提供配置文件:

[[email protected] ~]# cp /usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf

[[email protected] ~]#

[[email protected] ~]# vim /usr/local/php/etc/php-fpm.conf

235 pm.max_children = 50

240 pm.start_servers = 5

245 pm.min_spare_servers = 2

250 pm.max_spare_servers = 8

26 pid = /usr/local/php/var/run/php-fpm.pid

listen = 192.168.1.219:9000

"/usr/local/php/etc/php-fpm.conf"538L, 22836C written

[[email protected] ~]#

5、启动php-fpm服务:

[[email protected] ~]# service php-fpm start

Starting php-fpm  done

[[email protected] ~]# netstat -lntp

tcp       0      0 127.0.0.1:9000        0.0.0.0:*     LISTEN     43631/php-fpm

[[email protected] ~]#

6、到web服务器192.168.1.217上配置httpd,使其能够支持php

[[email protected] ~]# vim /etc/httpd/httpd.conf

250 <IfModule dir_module>

251    DirectoryIndex index.php index.html

252 </IfModule>

让apache能够处理php结尾的页面文件,添加php类型::

380    AddType application/x-httpd-php.php

381    AddType application/x-httpd-php-source .phps

查看是否启用proxy_module proxy-fcgi_module等模块:

116 LoadModule proxy_modulemodules/mod_proxy.so

117 LoadModule proxy_connect_modulemodules/mod_proxy_connect.so

118 LoadModule proxy_ftp_modulemodules/mod_proxy_ftp.so

119 LoadModule proxy_http_modulemodules/mod_proxy_http.so

120 LoadModule proxy_fcgi_modulemodules/mod_proxy_fcgi.so

121 LoadModule proxy_scgi_modulemodules/mod_proxy_scgi.so

7、配置虚拟主机,创建虚拟主机目录:

[[email protected] ~]# vim /etc/httpd/httpd.conf

217 #DocumentRoot"/usr/local/apache/htdocs"

468 # Virtual hosts

469 Include/etc/httpd/extra/httpd-vhosts.conf

"/etc/httpd/httpd.conf" 507L,18451C written

[[email protected] ~]#

[[email protected] extra]# pwd

/etc/httpd/extra

[[email protected] extra]# vim httpd-vhosts.conf

<VirtualHost *:80>

DocumentRoot "/www/da.ok/

ServerName www.da.ok

ProxyRequests Off

ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.1.219:9000/www/da.ok/$1

<Directory "/www/da.ok">

Options none

AllowOverride none

Require all granted

</Directory>

ErrorLog "/usr/local/apache/logs/da.ok-error_log"

CustomLog "/usr/local/apache/logs/da.ok-access_log" common

</VirtualHost>

"httpd-vhosts.conf" 56L, 1904Cwritten

[[email protected] extra]#

说明:

ProxyRequests Off:关闭正向代理。

注意:需要分别在wen服务器和PHP主机上创建相关目录:

[[email protected] ~]# mkdir -pv /www/da.ok

mkdir: created directory `/www‘

mkdir: created directory `/www/da.ok‘

[[email protected] ~]#

[[email protected] ~]# mkdir -pv /www/da.ok

mkdir: created directory `/www‘

mkdir: created directory `/www/da.ok‘

[[email protected] da.ok]# pwd

/www/da.ok

[[email protected] da.ok]# vim index.php

<h1>www.da.ok</h1>

<?php

phpinfo();

?>

[[email protected] da.ok]#

浏览器访问:192.168.1.217测试。

我们把网页放在 192.168.1.219主机上,/www/da/ok下面就可以了,现在当访问192.168.1.217/index.php时,将会通过fcgi协议反向代理到192.168.1.219主机的相应目录下面。

四、配置MySQL整合PHP

授权PHP主机可以访问MySQL(192.168.1.218数据库服务器)

mysql> use mysql;

Database changed

mysql> grant all privileges on *.* to‘root‘@‘192.168.1.219‘ identified by ‘123456‘;

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql>

测试在php主机上是否可以连接mysql(192.168.1.219PHP服务器上)

[[email protected] da.ok]# pwd

/www/da.ok

[[email protected] da.ok]# vim index.php

<h1>www.da.ok</h1>

<?php

$link = mysql_connect(‘192.168.1.218‘,‘root‘,‘123456‘);

if($link)

echo"HaHa..OK!.....";

else

echo "..NO OK!....";

mysql_close;

phpinfo();

?>

"index.php" 18L, 247Cwritten

[[email protected] da.ok]#

浏览器访问:192.168.1.217,如果显示HaHa..OK!.....,表示成功。

五、为PHP安装xcache加速器以提高性能

[[email protected] bao]# ll

-rw-r--r--. 1 root root   173368 Jul 10 22:04xcache-3.2.0.tar.gz

[[email protected] bao]#

用phpize生成configure配置文件:

[[email protected] bao]# tar xf xcache-3.2.0.tar.gz

[[email protected] bao]# cd xcache-3.2.0

[[email protected] xcache-3.2.0]#/usr/local/php/bin/phpize

Configuring for:

PHP Api Version:         20131106

Zend Module Api No:      20131226

Zend Extension Api No:   220131226

[[email protected] xcache-3.2.0]#

[[email protected] xcache-3.2.0]#

./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config

[[email protected] xcache-3.2.0]# make

[[email protected] xcache-3.2.0]# make install

Installing shared extensions:    /usr/local/php/lib/php/extensions/no-debug-zts-20131226/

[[email protected] xcache-3.2.0]#

整合php和xcache,将xcache提供的样例配置导入php.ini,修改extension路径:

[[email protected] ~]# mkdir /etc/php.d

[[email protected] ~]# cp /root/bao/xcache-3.2.0/xcache.ini/etc/php.d/

[[email protected] ~]# vim /etc/php.d/xcache.ini

4 extension =/usr/local/php/lib/php/extensions/no-debug-zts-20131226/xcache.so

"/etc/php.d/xcache.ini" 84L,3168C written

[[email protected] ~]#

重启php-fpm服务:

[[email protected] ~]# service php-fpm restart

Gracefully shutting down php-fpm . done

Starting php-fpm  done

[[email protected] ~]#

浏览器访问:192.168.1.217

六、利用phpMyAdmin工具测试httpd+php+mysql的连接:

把phpMyAdmin-4.4.4-all-languages.zip包分别下载到web192.168.1.217和PHP192.168.1.219主机上网页目录中:

[[email protected] bao]# ll

-rw-r--r--. 1 root root  9955372 Jul 10 22:20phpMyAdmin-4.4.4-all-languages.zip

[[email protected] bao]#

web192.168.1.217上:

[[email protected] bao]# unzip phpMyAdmin-4.4.4-all-languages.zip

[[email protected] bao]# mv phpMyAdmin-4.4.4-all-languages/www/da.ok/pam

[[email protected] bao]# cd /www/da.ok/

[[email protected] da.ok]# ll

drwxr-xr-x. 10 root root 4096 Apr 26 06:45pam

[[email protected] da.ok]#

PHP192.168.1.219上:

[[email protected] bao]# unzip phpMyAdmin-4.4.4-all-languages.zip

[[email protected] bao]# mv phpMyAdmin-4.4.4-all-languages/www/da.ok/pam

[[email protected] bao]# cd /www/da.ok/

[[email protected] da.ok]# ll

-rw-r--r--. 1 root root  247 Jul 10 21:53index.php

drwxr-xr-x. 10 root root 4096 Apr 26 06:45pam

[[email protected] da.ok]#

注意:这是两台不同主机;一个Apache;一个PHP,都要有!

需要连接数据库的操作在PHP主机上192.168.1.219上操作,连接数据库:

[[email protected] pam]# pwd

/www/da.ok/pam

[[email protected] pam]# cp config.sample.inc.php config.inc.php

[[email protected] pam]# vim config.inc.php

29 $cfg[‘Servers‘][$i][‘auth_type‘] = ‘cookie‘;

30/* Server parameters */

31$cfg[‘Servers‘][$i][‘host‘] = ‘192.168.1.218‘;     (修改为数据库主机地址,要有权限)

32$cfg[‘Servers‘][$i][‘connect_type‘] = ‘tcp‘;

33$cfg[‘Servers‘][$i][‘compress‘] = false;

34$cfg[‘Servers‘][$i][‘AllowNoPassword‘] = false;

"config.inc.php" 152L, 4316Cwritten

[[email protected] pam]#

浏览器登陆测试:http://192.168.1.217/pam/

七、discuz安装

把Discuz_X3.2_SC_UTF8.zip包分别下载到web192.168.1.217和PHP192.168.1.219主机上网页目录中:

[[email protected] bao]# ll

-rw-r--r--. 1 root root  12490656 Jul 10 22:34Discuz_X3.2_SC_UTF8.zip

[[email protected] bao]#

web192.168.1.217上:

[[email protected] bao]# unzipDiscuz_X3.2_SC_UTF8.zip

[[email protected] bao]# mv upload/ /www/da.ok/bbs

[[email protected] bao]# cd /www/da.ok/

[[email protected] da.ok]# ll

total 8

drwxr-xr-x. 12 root root 4096 Dec 26  2014 bbs

drwxr-xr-x. 10 root root 4096 Apr 26 06:45pam

[[email protected] da.ok]#

PHP192.168.1.219上:

[[email protected] bao]# unzipDiscuz_X3.2_SC_UTF8.zip

[[email protected] bao]# mv upload/ /www/da.ok/bbs

[[email protected] bao]# cd /www/da.ok/

[[email protected] da.ok]# ll

total 12

drwxr-xr-x. 12 root root 4096 Dec 26  2014 bbs

-rw-r--r--. 1 root root  247 Jul 10 21:53index.php

drwxr-xr-x. 10 root root 4096 Jul 10 22:29pam

[[email protected] da.ok]#

在PHP主机上192.168.1.219给安装权限:

[[email protected] da.ok]# pwd

/www/da.ok

[[email protected] da.ok]# cd bbs/

[[email protected] bbs]# chmod -R 777 *

[[email protected] bbs]#

在数据库主机上192.168.1.218创建数据库:

mysql> create database discudb;

Query OK, 1 row affected (0.02 sec)

mysql>

浏览器安装:

192.168.1.217/bbs

指定数据库服务器:192.168.1.218

数据库名:discudb

时间: 2024-10-16 07:10:47

CentOS 6.5编译安装LAMP分离环境的搭建的相关文章

Centos 6.9 编译安装 LAMP + xcache

Centos 6.9 编译安装 LAMP apache 2.4 + Mysql 5.7 + php5.6.34 + Fast-cgi + xcache 实验环境:VMware Workstation Pro 14(试用版) 系统平台: CentOS release 6.9 (Final) 内核 2.6.32-696.el6.x86_64 Apache/2.4.29 (Unix) PHP 5.6.34 (cli) xcache 3.2.0 1. 编译安装apache 2.4 参考Centos 6.

Centos 7.0 编译安装LAMP(Linxu+apache+mysql+php)之源码安装Mysql (二)

mysql 简介: MySQL是一个关系型数据库管理系统,关系数据库将数据保存在不同的表中,这样就增加了速度并提高了灵活性.目前其属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件.MySQL所使用的 SQL 语言是用于访问数据库的最常用标准化语言. 安装环境: 系统: centos 7.0 最小化安装 软件

Centos 7.0 编译安装LAMP(Linxu+apache+mysql+php)之源码安装php (三)

PHP简介: PHP(外文名:PHP: Hypertext Preprocessor,中文名:"超文本预处理器")是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域.PHP 独特的语法混合了C.Java.Perl以及PHP自创的语法.它可以比CGI或者Perl更快速地执行动态网页.用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成HTML标

Centos 7.0 编译安装LAMP(Linxu+apache+mysql+php)之源码安装Apache (一)

Apache 简介: Apache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一.它快速.可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中. 安装环境: 系统: centos 7.0 最小化安装 软件:httpd-2.4.26 依赖包:apr .apr-util .pcre .gcc .gcc-c++ .perl-dvel.perl.openssl .openssl-

编译安装LAMP平台环境_xcache

基于Linux.Apache.Mysql.Php编译安装LAMP环境平台,并使用xcache加速php 编译安装LAMP平台: 1.下载软件包, 安装依赖包 # yum install -y pcre-devel 2.解包安装apache 2.1 编译安装apr-1.5.0 # tar xvf apr-1.5.0.tar.bz2 # cd apr-1.5.0 && ./configure --prefix=/usr/local/apr # make && make inst

CentOS 6.9编译安装LAMP环境,并部署phpMyAdmin,使用XCache优化性能

一.使用的程序包名称及版本: httpd:2.4.29 mariadb-server:10.2.9 php:5.6.32 备注:httpd-2.4.x依赖于apr-1.4+以及apr-util-1.4+,而CentOS6.9 yum安装的apr和apr-util的版本均为1.3.9,httpd的版本为2.2.15,所以如果要在CentOS 6.9中使用httpd-2.4.x,只能重新源码编译安装 apr:Apache Portable Runtime,Apache运行时环境,可以理解为Apach

centos源码编译安装lamp环境

一.熟悉系统环境 查看系统版本号 cat /etc/issue 查看所有硬件的型号 dmidecode | more 查看memory info cat /proc/meminfo | more 查看CPU info cat /proc/cpuinfo 查看磁盘信息 df -lh 二.准备工作 更新系统时间 ntpdate time.windows.com;/sbin/hwclock -w 备份并替换系统的repo文件 sudo mv /etc/yum.repos.d/CentOS-Base.r

64bit centos 6.5 编译安装 LAMP 环境

MySQL5.5.40 编译安装 请参考 MySQL5.5.40编译安装 Apache 2.4.10 编译安装 请参考 Apache 2.4.10 编译安装 PHP 5.4.33 编译安装 下面我们开始编译安装PHP5.4.33 首先下载源码包到用户目录下, 下载PHP5.4.33 也可以使用命令行下载: [[email protected] ~]# wget http://kr1.php.net/get/php-5.4.33.tar.bz2/from/this/mirror 然后解压源码 [[

Centos 6.7 编译安装LAMP

一.环境和软件包准备 [[email protected] ~]# cat/etc/redhat-release CentOS release 6.7 (Final) [[email protected] ~]# uname -rm 2.6.32-573.el6.x86_64 x86_64 使用163的yum源 cd /etc/yum.repos.d/ wget http://mirrors.163.com/.help/CentOS6-Base-163.repo 关闭防火墙和selinux se