说明:本实验在单主机搭建。下面的步骤只需要你复制粘贴,即可完成实验。
1、安装httpd
mkdir /tools cd /tools #获取软件包 wget -c http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.16.tar.gz wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.bz2 wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.bz2 tar -xf httpd-2.4.16.tar.gz tar -xf apr-1.5.2.tar.bz2 tar -xf apr-util-1.5.4.tar.bz2 #编译安装各软件 cd apr-1.5.2 ./configure --prefix=/usr/local/apr make && make install cd ../apr-util-1.5.4 ./configure --prefix=/usr/local/apr-utils --with-apr=/usr/local/apr/ make && make install cd ../httpd-2.4.16 yum install pcre-devel zlib-devel -y ./configure --prefix=/usr/local/apache --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-utils/ make && make install
2、安装MySQL。
#安装依赖包
yum install -y autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool* openssl* yum install cmake -y #添加用户和组 groupadd mysql useradd -g mysql -M -s /sbin/nologin mysql mkdir -p /data/3306/data #获取包和安装 cd /tools wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.45.tar.gz tar -xf mysql-5.5.45.tar.gz cd mysql-5.5.45 chown mysql.mysql -R . cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/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 gmake make install chown mysql.mysql -R /data cd /usr/local/mysql scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data cp support-files/my-medium.cnf /data/3306/my.cnf vim /data/3306/my.cnf [root@node6 mysql]# diff /data/3306/my.cnf support-files/my-medium.cnf 39d38 < datadir=/data/3306/data 51c50 < log-error = /data/3306/data/mysql-err --- >
3、安装php
cd /tools yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel openssl-devel libxslt-devel -y #这些东西因为php需要画图,不安装容易出现问题 wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz tar zxf libiconv-1.14.tar.gz cd libiconv-1.14 ./configure --prefix=/usr/local/libiconv make make install cd ../ #提前下载好php53 tar -xf php-5.3.27.tar.bz2 cd php-5.3.27 ./configure \ --prefix=/usr/local/php53 \ --with-apxs2=/usr/local/apache/bin/apxs \ --with-mysql=/usr/local/mysql \ --with-xmlrpc \ --with-openssl \ --with-zlib \ --with-freetype-dir \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-iconv=/usr/local/libiconv \ --enable-short-tags \ --enable-sockets \ --enable-zend-multibyte \ --enable-soap \ --enable-mbstring \ --enable-static \ --enable-gd-native-ttf \ --with-curl \ --with-xsl \ --enable-ftp \ --with-libxml-dir make make install cp php.ini-production /usr/local/php53/lib/php.ini [root@node6 php-5.3.27]# grep php /usr/local/apache/conf/httpd.conf LoadModule php5_module modules/libphp5.so
4、整合apache,php,mysql
useradd -M -s /sbin/nologin www vim /usr/local/apache/conf/httpd.conf [root@node6 apache]# diff conf/httpd.conf conf/httpd.conf.bak 149d148 < LoadModule php5_module modules/libphp5.so 160c159 < User www --- > User daemon 249c248 < DirectoryIndex index.php index.html --- > DirectoryIndex index.html 378,379d376 < AddType application/x-httpd-php .php < AddType application/x-httpd-php-source .php .phps vim /usr/local/apache/htdocs/index.php <?php phpinfo(); ?> /usr/local/apache/bin/apachectl -t /usr/local/apache/bin/apachectl start iptables -I INPUT -d 192.168.198.160 -p tcp --dport 80 -j ACCEPT
4.2整合php和mysql
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf & /usr/local/mysql/bin/mysql -e "delete from mysql.user where user='';" vim /usr/local/apache/htdocs/index.php <?php $link_id=mysql_connect('localhost','root','') or mysql_error(); if($link_id){ echo "mysql successful by yunzhonghe !"; }else{ echo mysql_error(); } ?>
总结:到此一个简单的lamp平台搭建完成。用时大约1小时。
原创文章,作者:艾贺,如若转载,请注明出处:http://www.178linux.com/8673
评论列表(1条)
最后出现这个输入地址直接出现