歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

centos 6.0下安裝LAMP

說明:在本帖中,#代表shell的提示符,所有操作均在root環境變量下面執行

一,系統的安裝

系統安裝的是centos6.0版本,磁盤大小300G

/boot         300M

/swap         2G

/             30G

/usr/local    80G

/var          80G   //lvm分區

/home         20G

/tmp          10G

安裝好之後,配置ip地址,ssh,iptables等服務,安裝系統的原則:最小化安裝,盡量不安裝圖形界面和不必要的軟件包。

二,軟件包的准備

mysql-5.6.2-m5,php-5.3.6,httpd-2.2.21

下載地址

   #cd /usr/local/src
   #wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.2-m5.tar.gz
   #wget http://mirrors.sohu.com/php/php-5.3.6.tar.gz
   #wget http://mirrors.sohu.com/apache/httpd-2.2.21.tar.gz

三,本機yum源的配置

   #vim /etc/yum.repos.d/myyum.repo
   [Packages]
   name=CentOS-$releasever - Plus
   baseurl=file:///mnt/cd/  #本地文件路徑,如果是網絡源,請更改
   gpgcheck=1  #gpg校驗
   enabled=1  #yum的開關
   gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
   #yum clean all
   #yum list

四,安裝系統編譯環境所需要的軟件包

for base in gcc gcc-c++ make cmake apr apr-util postgresql-libs zlib* openssl openssl-devel autoconf automake ncurses* libtool* libxslt libxslt-devel libxml* curl* bzip2* gd gd-devel freetype freetype-devel libpng* cairo-devel libxml2-devel pango pango-devel libmcrypt libpng jpeg bison mysql-devel
do rpm -qa |grep $base;retval=$?
[ "$retval" != 0 ] && yum install $base done

注意,以上步驟需要把yum源等配置好,然後復制紫色字體到腳本運行 (主要是安裝gcc make以及GD及庫相關 curl  libpng  zlib freetype libxslt jpegsrc gd libxml )

五,apache的編譯安裝

#service httpd stop //為了防止系統安裝的時候默認安裝過apache            
#rpm -e --nodeps httpd      
#tar xvf httpd-2.2.21.tar.gz         
#cd httpd-2.2.21         
#groupdel Apache        
#groupdel apache       
#userdel apache     
#groupadd --gid=48 apache      
#useradd -s /sbin/nologin -d /usr/local/apache2 -g apache --uid=48  apache      
        
#./configure --prefix=/usr/local/apache2  --enable-deflate --enable-headers --enable-so  --with-mpm=worker  --enable-rewrite     --enable-cgi  --enable-file-cache --enable-cache --enable-disk-cache --enable-mem-cache --enable-static-ab --enable-static-htpasswd --enable-expires --enable-authn-dbm --with-ssl --enable-ssl  --disable-userdir --disable-cgid   --enable-expires --enable-speling         
#make && make install      
#ln -s /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd       
#chown -R apache:apache /usr/local/apache2       
#service httpd restart     
------------------------------------------------------    
#echo 'service httpd restart' >> /etc/rc.d/rc.local 如果前面有ln -s 此處去掉    
------------------------------------------------------       
#sed -i 's/User\ daemon/User\ apache/g' /usr/local/apache2/conf/httpd.conf       
#sed -i 's/Group\ daemon/Group\ apache/g' /usr/local/apache2/conf/httpd.conf     
#cd ..

六,mysql的安裝過程

#tar xvf mysql-5.6.2-m5.tar.gz       
#cd mysql-5.6.2-m5       
#mkdir /usr/local/mysql        
#groupdel mysql        
#userdel mysql        
#groupadd mysql       
#useradd -d /var/lib/mysql -s /bin/bash -g mysql mysql   
-----------------------------------------------------------------   
#wget http://googletest.googlecode.com/files/gtest-1.5.0.tar.gz       
#cp gtest-1.5.0.tar.gz mysql-5.6.2-m5/source_downloads    
------------------------------------------------------------------   
**********此處需要注意的是如果沒有下載gtest,安裝的過程會自動去下載gtest,需要將以下的參數改變成這樣-DENABLE_DOWNLOADS=1      
#  cmake . -DINSTALL_LIBDIR=/usr/local/mysql -DMYSQL_DATADIR=/var/mysql/data -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_ COLLATION=utf8_general_ci -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLE_DOWNLOADS=0 -DENABLED_LOCAL_INFILE=1 -DWITH_MY ISAM_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DWITH_LIBWRA P=1 -DWITH_DEBUG=0   
#chown -R mysql /usr/local/mysql        
#chgrp -R mysql /usr/local/mysql          
#make && make install         
#cp support-files/my-medium.cnf /etc/my.cnf          
#cp support-files/mysql.server /etc/init.d/mysqld          
#chmod  755  /etc/init.d/mysqld           
#chown -R root:mysql /usr/local/mysql/           
#chown -R mysql:mysql /usr/local/mysql/data          
#sed  -i '/^\[mysqld\]$/a set-variable=max_connections=2000' /usr/local/mysql/etc/my.cnf         
#cp extra/my_print_defaults /usr/local/mysql/bin/       
#mkdir -p /var/lib/mysql/data          
#mkdir /var/run/mysqld          
#chown -R mysql:mysql /var/run/mysqld       
#chmod 755 -R /var/mysql/data/         
#chkconfig --add  mysqld         
#chkconfig mysqld on        
#/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/var/mysql/data         
#/usr/local/mysql//bin/mysqld_safe &          
#ln -s /usr/local/mysql/bin/mysql /bin/mysql        
#service mysqld restart  &&         
#cd ..       
需要注意的是:本處只是把mysql安裝好了,對系統參數並沒有做設置,大家可以參考其他mysql調優  
資源進行相關的設置

七,php的安裝過程

#tar xvf libmcrypt-2.5.8.tar.gz    
#cd libmcrypt-2.5.8    
#./configure --prefix=/usr/local/    
#make && make install    
#cd ..    
        
       
#tar xvf  mhash-0.9.9.9.tar.gz    
#cd mhash-0.9.9.9    
#./configure --prefix=/usr/local/    
#make && make install    
#cd ..    
        
#tar xvf mcrypt-2.6.8.tar.gz   
#cd mcrypt-2.6.8   
#LD_LIBRARY_PATH=/usr/local/lib ./configure --prefix=/usr/local/   
#make && make install   
#cd ..   
        
#wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz   
#tar xvf libiconv-1.14.tar.gz   
#cd libiconv-1.14   
# ./configure --prefix=/usr/local   
#make && make install   
#cd ..   
        
#tar xvf freetype-2.4.0.tar.gz    
#cd freetype-2.4.0    
#./configure    
#make && make install    
#cd ..    
        
#  wget http://downloads.sourceforge.net/project/libpng/libpng14/older-releases/1.4.2/libpng-1.4.2.tar.gz    
#tar xvf libpng-1.4.2.tar.gz    
#cd libpng-1.4.2    
#./configure    
#make && make install    
#wget http://www.netpurgatory.com/web_stuff/zeusmp_releases/jpegsrc.v6b.tar.gz    
#./configure --enable-static --enable-shared    
#mkdir /usr/local/man/man1    
        
#----If your system was install libxml2, you do not need to install it.----    
#wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz    
#tar xvf libxml2-2.7.6.tar.gz    
#cd libxml2-2.7.6    
#./configure    
#make && make install    
        
*******************************install php*********************************   
#tar xvf php-5.3.6.tar.gz    
#cd php-5.3.6    
       
****************注意此處進行2處鏈接,同時將--with-mysql=/usr/local/mysql改為--with-mysql=/usr,防止提示configure: error: Cannot find libmysq    
lclient under /usr/local/mysql的錯誤*******************   
#ln -s /usr/local/mysql/libmysqlclient_r.a  /usr/lib/libmysqlclient_r.a    
#ln -s /usr/local/mysql/libmysqlclient.a  /usr/lib/libmysqlclien.a    
        
#./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/ --with-mysql=/usr --with-mysql-sock=/tmp/mysql.    
sock --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql  --with-bz2 --with-jpeg-dir --with-png-dir --with-freetype-dir --w    
ith-libxml-dir=/usr/local --with-zlib-dir --with-gd  --enable-gd-native-ttf  --with-xsl --with-openssl-dir  --with-mcrypt --e    
nable-zip --enable-sqlite-utf8  --enable-sockets --enable-soap  --enable-ucd-snmp-hack --enable-ftp --enable-safe-mode --enab    
le-bcmath  --enable-sysvsem &&    
        
***********加此參數防止make的時候報make: *** [sapi/cli/php] Error 1的錯誤********   
用sed命令替換如下   
#sed -i 's/\-lm\ \-lxslt\ \-lxml2\ \-lz\ \-lm\ \-lcrypt/\-lm\ \-lxslt\ \-lxml2\ \-lz\ \-lm\ \-lcrypt\ \-liconv/g' Makefile    
#make && make install    
#cp php.ini-development /usr/local/php5/php.ini    
        
******php測試頁面的自動生成,如果各位自行定義了apche的路徑,下面的語句也需要改變*****   
         
#echo -e "<?php\nphpinfo();\n?>" >/usr/local/apache2/htdocs/test.php    
********讓apache對php進行支持,需要更改3個地方******   
#sed  -i '/AddType\ application\/x-gzip .gz \.tgz$/a \    AddType\ application\/x-httpd-php\ \.php\ \.phtml'
/usr/local/apache 2/conf/httpd.conf #sed -i '/AddType\ application\/x-httpd-php\ \.php\ \.phtml$/a \ AddType\ application\/x-httpd-php-source\ \.phps' /usr/local/apache2/conf/httpd.conf #sed -i '/Group\ apache$/a LoadModule php5_module libexec/libphp5.so' /usr/local/apache2/conf/httpd.conf
sed -i '/\\ LoadModul foo_modules\ modules\/mod_foo.so$/a \ LoadModule php5_module libexec/libphp5.so' /usr/local/apache2/conf/httpd.conf
#service httpd restart

八,測試調優:通過以上步驟的安裝,系統框架已經可以搭建好了,接下來需要各位自己對各參數進行相關的優化設置

請大家自己設置,本文不再詳述,如有不足之處,請大家指教。

itnihao 2011年9月整理,10發表,於成都

本文出自 “itnihao的運維技術博客” 博客,請務必保留此出處http://itnihao.blog.51cto.com/1741976/680772

Copyright © Linux教程網 All Rights Reserved