LAMP的简单配置:
apache的特点:
开放源代码,跨平台使用,支持各种编程语言,模块化设计,运行稳定,良好的安全性。
mysql的特点:
本文编译安装所需软件包:
apache-tomcat-7.0.54.tar.gz
cmake-2.8.6.tar.gz
mysql-5.5.22.tar.gz
libmcrypt-2.5.8.tar.gz
mhash-0.9.9.9.tar.gz
mcrypt-2.6.8.tar.gz
php-5.3.28.tar.gz
部署apache:
卸载系统自带的httpd
rpm -e http --nodeps
编译安装:
tar zxf apache-tomcat-7.0.54.tar.gz -C /usr/src/
cd /usr/src/apache-tomcat-7.0.54
./configure --prefix=/usr/local/httpd #install apache directory \
--enable-so #active mode \
--enable=rewrite #rewrite \
--enable-charset-lite #utf8 \
--enable-cgi #cgi scripts \
make && make install
检查httpd是否安装完成:
ls /usr/local/httpd
命令优化
ln -s /usr/local/httpd/bin/* /usr/local/bin
查看apache的版本:
httpd -v
添加系统文件:
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
vim /etc/init.d/httpd
#!/bin/bash # chkconfig: 35 85 32 # description: my's A apache!
chkconfig --add httpd
chkconfig --list httpd
配置apache并启动:
sed -i '/^#ServerName/a ServerName www.cjl.com' /usr/local/httpd/conf/httpd.conf /usr/local/httpd/bin/apachectl start
查看httpd是否启动:
netstat -utpln |grep 80
添加测试文件:
cat <<END>/usr/local/httpd/htdocs/index.html
hello my in your a king!
访问测试:
mysql的部署:
卸载系统自带mysql
rpm -e mysql --nodeps
安装mysql独特的编译安装软件:
tar zxf /root/cmake-2.8.6.tar.gz -C /root/
cd /root/cmake-2.8.6
./configure && gmake && gmake install
安装mysql依赖包:
yum -y install ncurses-devel
编译安装mysql
tar zxf /root/mysql-5.5.22.tar.gz -C /usr/src
cd /usr/src/mysql-5.5.22
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all
make && make install
授权数据库用户:
useradd -M -s /sbin/nologin mysql -g mysql
chown -R mysql:mysql /usr/local/mysql
初始化数据库:
/usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data/
优化数据库
cp -rf /usr/src/$MY_Q/support-files/my-medium.cnf /etc/my.cnf
cp -rf /usr/src/$MY_Q/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
启动数据库并设置密码:
echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
source /etc/profile
/etc/init.d/mysqld start
mysqladmin -uroot password '123123'
访问测试:
部署PHP实现动态网页加载:
卸载系统自带的php安装包:
rpm -e php --nodeps
rpm -e php-mysql --nodeps
安装依赖包:
yum -y install zlib-devel libxml2-devel
安装加密依赖包:
tar zxf /root/libmcrypt-2.5.8.tar.gz -C /usr/src/
cd /usr/src/libmcrypt-2.5.8
./configure && make && make install
ln -s /usr/local/lib/libmcrypt* /usr/lib/
tar zxf /root/mhash-0.9.9.9.tar.gz -C /usr/src/
cd /usr/src/mhash-0.9.9.9
./configure && make &&maek install
ln -s /usr/local/lib/libmhash* /usr/lib/
tar zxf /root/$M_CR.tar.gz -C /usr/src/
cd /usr/src/$M_CR
./configure && make && make install
如果没成功则执行下面的代码:
export LD_LIBRARY_PATH=/usr/local/lib
./configure && make &&make install
编译安装php:
tar zxf /root/php-5.3.28.tar.gz -C /usr/src/
cd /usr/src/php-5.3.28
./configure --prefix=/usr/local/php5 \
--with-mcrypt \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-config-file-path=/usr/local/php5 \
--enable-mbstring
make && make install
编辑php配置文件,启用动态模块支持.
cp /usr/src/$P_HP/php.ini-development /usr/local/php5/php.ini
sed -i '/^short_open_tag /s/= OFF/= On/g' /usr/local/php5/php.ini
添加优化模块:
tar zxf /root/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/
cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/
cp ZendGuardLoader.so /usr/local/php5/lib/php
cat <<END >>/usr/local/php5/php.ini
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
Zend_loader.enable=1
END
配置apache支持php
sed -i '310a \ AddType application/x-httpd-php .php' /usr/local/httpd/conf/httpd.conf
sed -i '/DirectoryIndex/s/index.html/index.php index.html/g' /usr/local/httpd/conf/httpd.conf
查看httpd的配置文件,php是否安装成功:
LoadModule php5_module modules/libphp5.so
编辑php测试文件:
cat <<END >/usr/local/httpd/htdocs/test1.php
<?php
phpinfo()
?>
END
下面放上本人写的一个简单的LAMP脚本
#!/bin/bash if [ ! -e /etc/yum.repos.d/local.repo ];then cat <<END >/etc/yum.repos.d/local.repo [local] name=cjl baseurl=file:///mnt enabled=1 gpgcheck=0 END fi if [ -e /dev/sr0 ];then mount /dev/cdrom /mnt else echo "CD is not found" fi if [ -e /root/bin/lamp* ];then cp -rf /root/bin/lamp_* /root tar zxf /root/lamp_app.tar.gz -C /root/ else echo "you a app no!!!" fi rpm -qa |grep httpd >/root/apache.txt for A in $(cat /root/apache.txt) do rpm -e $A done rm -rf /root/apache.txt echo "apache install" HT_T=httpd-2.2.17 tar zxf /root/$HT_T.tar.gz -C /usr/src cd /usr/src/$HT_T ./configure --prefix=/usr/local/httpd #install apache directory \ --enable-so #active mode \ --enable=rewrite #rewrite \ --enable-charset-lite #utf8 \ --enable-cgi #cgi scripts \ make && make install if [ -e /usr/local/httpd ];then echo "apache install full,your a httpd version.$(/usr/local/httpd/bin/apachectl -v)" else echo "apache install not full" fi #apache level echo "hello my is your a king!">/usr/local/httpd/htdocs/index.html sed -i '/^#ServerName/a ServerName www.cjl.com' /usr/local/httpd/conf/httpd.conf echo "apache start..." /usr/local/httpd/bin/apachectl restart echo "apache is runing!" #mysql install rpm -qa | grep mysql* >/root/mysql.txt for B in $(cat /root/mysql.txt) do rpm -e $B done rm -rf /root/mysql.txt CM_K=cmake-2.8.6 MY_Q=mysql-5.5.22 tar zxf /root/$CM_K.tar.gz -C /root/ cd /root/$CM_K ./configure && gmake && gmake install rm -rf /root/$CM_K yum -y install ncurses-devel tar zxf /root/$MY_Q.tar.gz -C /usr/src cd /usr/src/$MY_Q cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql #install path \ -DSYSCONFDIR=/etc #initiazation data directory \ -DDEFAULT_CHARSET=utf8 #utf8 \ -DDEFAULT_COLLATION=utf8_general_ci #.. \ -DWITH_EXTRA_CHARSETS=all make && make install if [ -e /usr/local/mysql ];then echo "mysql is full!" else echo "mysql is not full!" fi #mysql config grep mysql /etc/passwd if [ $? -eq 0 ];then echo "your a useradd full!" else echo "new group" groupadd mysql echo "new user" useradd -M -s /sbin/nologin mysql -g mysql fi echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile chown -R mysql:mysql /usr/local/mysql if [ -f /etc/my.cnf ];then rm -rf /etc/my.cnf fi cp -rf /usr/src/$MY_Q/support-files/my-medium.cnf /etc/my.cnf /usr/local/mysql/scripts/mysql_install_db \ --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data/ cp -rf /usr/src/$MY_Q/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig --add mysqld echo "mysql is start..." /etc/init.d/mysqld start echo "mysql is start full" source /etc/profile mysqladmin -uroot password '123123' #php install rpm -qa |grep php >/root/php.txt for C in $(cat /root/php.txt) do rpm -e $C done rm -rf /root/php.txt yum -y install zlib-devel libxml2-devel #install php setting L_IB=libmcrypt-2.5.8 M_HA=mhash-0.9.9.9 M_CR=mcrypt-2.6.8 tar zxf /root/$L_IB.tar.gz -C /usr/src/ cd /usr/src/$L_IB ./configure && make && make install ln -s /usr/local/lib/libmcrypt* /usr/lib/ tar zxf /root/$M_HA.tar.gz -C /usr/src/ cd /usr/src/$M_HA ./configure && make &&maek install ln -s /usr/local/lib/libmhash* /usr/lib/ tar zxf /root/$M_CR.tar.gz -C /usr/src/ cd /usr/src/$M_CR ./configure if [ $? -eq 0 ];then make && make install else export LD_LIBRARY_PATH=/usr/local/lib ./configure && make &&make install fi #php tar install P_HP=php-5.3.28 Z_G=ZendGuardLoader-php-5.3-linux-glibc23-x86_64 tar zxf /root/$P_HP.tar.gz -C /usr/src/ cd /usr/src/$P_HP ./configure --prefix=/usr/local/php5 \ --with-mcrypt \ --with-apxs2=/usr/local/httpd/bin/apxs \ --with-mysql=/usr/local/mysql \ --with-config-file-path=/usr/local/php5 \ --enable-mbstring make && make install if [ -e /usr/local/php5 ];then echo "php install full" fi #php config cp /usr/src/$P_HP/php.ini-development /usr/local/php5/php.ini sed -i '/^short_open_tag /s/= OFF/= On/g' /usr/local/php5/php.ini tar zxf /root/$Z_G.tar.gz -C /usr/src/ cd /usr/src/$Z_G/php-5.3.x/ cp ZendGuardLoader.so /usr/local/php5/lib/php cat <<END >>/usr/local/php5/php.ini zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so Zend_loader.enable=1 END sed -i '310a \ AddType application/x-httpd-php .php' /usr/local/httpd/conf/httpd.conf sed -i '/DirectoryIndex/s/index.html/index.php index.html/g' /usr/local/httpd/conf/httpd.conf cat <<END >/usr/local/httpd/htdocs/test1.php <?php phpinfo() ?> END echo "http://localhost/test1.php"