写在前面:如果此文有幸被某位朋友看见并发现有错的地方,希望批评指正。如有不明白的地方,愿可一起探讨。
LAMP平台规划拓扑图
配置主机1
编译安装apr-1.5.0
# tar xf apr-1.5.0.tar.bz2 # cd apr-1.5.0 # ./configure --prefix=/usr/local/apr # make && make install
编译安装apr-util-1.5.3
# tar xf apr-util-1.5.3.tar.bz2 # cd apr-util-1.5.3 # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ # make && make install
编译安装httpd-2.4.9
# tar xf httpd-2.4.9.tar.bz2 # cd httpd-2.4.9 # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --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 # make && make install
修改httpd主配置文件,设置Pid文件的路径
# vim /etc/httpd24/httpd.conf
在ServerRoot "/usr/local/apache"行下面添加一行:
PidFile "/var/run/httpd.pid"
提供SysV服务脚本/etc/rc.d/init.d/httpd24,这个文件需要新建
# vim /etc/rc.d/init.d/httpd24
#!/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
# chmod +x /etc/rc.d/init.d/httpd24 # chkconfig --add httpd24 # chkconfig httpd24 on
启动http24服务并测试
# service httpd24 start
在浏览器中键入10.170.2.80,可以得到如下结果:
编译安装php-5.4.26
# tar xf php-5.4.26.tar.bz2 # cd php-5.4.26 # ./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 # make && make install
为php提供配置文件
# cp php.ini-production /etc/php.ini
编辑httpd配置文件,以支持php
# vim /etc/httpd24/httpd.conf
在AddType application/x-gzip .gz .tgz行下面添加下面两行: AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 将DirectoryIndex index.html这一行改为: DirectoryIndex index.php index.html
在/usr/local/apache/htdocs目录下添加测试页
# vim /usr/local/apache/htdocs/index.php <?php phpinfo(); ?>
重启httpd24和php服务,测试httpd和php结合
# service httpd24 restart
在浏览器键入10.170.2.80/index.php,在出现的页面的查看页面中是否包含如下内容
配置主机2
编译安装mariadb-5.5.36
# tar xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local # cd /usr/local/ # ln -sv mariadb-5.5.36-linux-x86_64/ mysql # mkdir -pv /mysql/data # groupadd -r mysql # useradd -g mysql -s /sbin/nologin -M -d /mysql/data -r mysql # chown -R mysql:mysql /mysql # chown -R mysql:mysql /mysql/data
为数据库提供配置文件:
# cd mysql # mkdir /etc/mysql # chown -R root.mysql ./* # cp support-files/my-large.cnf /etc/mysql/my.cnf 修改文件/etc/mysql/my.cnf文件内容,在thread_concurrency = 8行下添加一行: datadir = /mysql/data
为数据库提供SysV启动脚本,并设置为开机启动:
# cp support-files/mysql.server /etc/init.d/mysqld # chkconfig --add mysqld # chkconfig mysqld on
初始化数据库并启动数据库:
# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh # source /etc/profile.d/mysql.sh # echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf # ldconfig # ln -sv /usr/local/mysql/include/ /usr/include/mysql # scripts/mysql_install_db --user=mysql --datadir=/mysql/data/ # /etc/init.d/mysqld start
创建数据库并授权:
MariaDB [(none)]> CREATE DATABASE pma; MariaDB [(none)]> GRANT ALL ON pma.* TO pmauser@'10.170.2.%' IDENTIFIED BY 'pmapass'; MariaDB [(none)]> FLUSH PRIVILEGES;
搭建测试环境并进行测试
在主机1中解压文件phpMyAdmin-3.5.1-all-languages.tar.bz2到/usr/local/apache/htdocs目录,然后进行一些设定:
# tar xf phpMyAdmin-3.5.1-all-languages.tar.bz2 -C /usr/local/apache/htdocs # cd /usr/local/apache/htdocs # mv phpMyAdmin-3.5.1-all-languages pma # cd pma # cp config.sample.inc.php config.inc.php # vim config.inc.php $cfg['blowfish_secret'] = 'a8b7c6dabkekif7449'; $cfg['Servers'][$i]['host'] = '10.170.2.36';
重启httpd24和php服务:
# service httpd24 restart
在浏览器下输入:10.170.2.80/pma可以得到结果,然后输入账号和密码进行登录:
键入用户名和密码后,点击执行可得到如下结果