当前位置: > Linux服务器 > 服务器设置 >

LAMP编译安装

时间:2014-11-30 16:06来源:linux.it.net.cn 作者:IT

Lamp(linux+apache+mysql+php)源码包最新版编译安装步骤

本次基于CentOS Minimal系统搭建

  1. #!/bin/sh
  2. ########################## Written By Qitan ####################################
  3. ################## BLOG: http://blog.catjia.com #################################
  4. #################### EMAIL: qqing_lai@hotmail.com ##############################
  5. ########################## DATE: 2011-11-09 ####################################
  6.  
  7. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  8. export PATH
  9.  
  10. dir="/usr/local"
  11. hostname="www.7tan.info"
  12. mycnf="my-innodb-heavy-4G.cnf"
  13.  
  14. # Check if user is root
  15. if [ $(id -u) != "0" ]; then
  16.     echo "Error: You must be root to run this script, please use root to setup operation system"
  17.     exit 1
  18. fi
  19.  
  20. #################################### Install LAMP… ###########################
  21.  
  22. # Download Files…
  23.  
  24. function func() {
  25. if [ -s $file ]; then
  26.     printf "n"
  27.     echo "$file Found."
  28. else
  29.     printf "n"
  30.     echo "$file not found, download now…"
  31.     wget -c $url
  32.     if [ -s $file ]; then
  33.     echo "$file already download."
  34.     printf "n"
  35.     else
  36.     echo -e "33[7m"
  37.     echo "$file cannot download, please download manually and rerun this script." >> /root/qq_lamp.log
  38.     echo -e "33[0m"
  39.     exit 0
  40.     fi
  41. fi
  42. }
  43.  
  44. function file_down() {
  45.     local file=httpd-2.2.21.tar.bz2 url=http://labs.renren.com/apache-mirror//httpd/httpd-2.2.21.tar.bz2
  46.     func
  47.     local file=cmake-2.8.6.tar.gz url=http://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gz
  48.     func
  49.     local file=mysql-5.5.16.tar.gz url=http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.16.tar.gz/from/http://mirror.services.wisc.edu/mysql/
  50.     func
  51.     local file=php-5.3.8.tar.bz2 url=http://cn2.php.net/get/php-5.3.8.tar.bz2/from/this/mirror
  52.     func
  53.     local file=phpMyAdmin-3.4.7-all-languages.tar.bz2 url=http://nchc.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.4.7/phpMyAdmin-3.4.7-all-languages.tar.bz2
  54.     func
  55.     local file=xcache-1.3.2.tar.gz url=http://xcache.lighttpd.net/pub/Releases/1.3.2/xcache-1.3.2.tar.gz
  56.     func
  57.     local file=ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz url='http://blog.catjia.com/wp-content/uploads/2011/12/ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
    '
  58.     func
  59.     local file=rpmforge-release-0.5.2-2.el6.rf.i686.rpm url=http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
  60.     func
  61. }
  62.  
  63. # function file_down()
  64. file_down
  65.  
  66.     # Add additional resource/rpm
  67. rpm –import http://apt.sw.be/RPM-GPG-KEY.dag.txt
  68. rpm -K rpmforge-release-0.5.2-2.el6.rf.i686.rpm
  69. rpm -i rpmforge-release-0.5.2-2.el6.rf.i686.rpm
  70.  
  71. sleep 1
  72.  
  73. yum -y install wget ftp ntp kernel kernel-devel make gcc gcc-c++ autoconf automake vim ntsysv crontab* man ImageMagick-devel rar unrar unzip ncurses-devel zlib* flex* libxml* libmcrypt* mhash* libcurl-devel libtool libtool-ltdl-devel* bison bison-devel libjpeg* gd gd-devel openssl* cronolog bzip2-devel libpng-devel libtiff-devel freetype-devel libXpm-devel gettext-devel pam-devel >> ntpdate time.nist.gov >> yum -y update
  74.  
  75. sleep 3
  76.  
  77. # Install AMP…
  78.  
  79. # Install phpMyAdmin
  80.     alias cp='cp' >> tar -jxvf phpMyAdmin-3.4.7-all-languages.tar.bz2 >> cp -r phpMyAdmin-3.4.7-all-languages /data/www/wwwroot/eyo/phpMyAdmin >> source /root/.bashrc
  81. cat > /data/www/wwwroot/eyo/phpMyAdmin/config.inc.php <<EOF
  82. <?php
  83.  /* This is needed for cookie based authentication to encrypt password in
  84.  * cookie
  85.  */
  86. $cfg['blowfish_secret'] = 'qitan99'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
  87.  
  88. /*
  89.  * Servers configuration
  90.  */
  91.  
  92. $i = 0;
  93.  
  94. /*
  95.  * First server
  96.  */
  97. $i++;
  98. /* Authentication type */
  99. $cfg['Servers'][$i]['auth_type'] = 'cookie';
  100. /* Server parameters */
  101. $cfg['Servers'][$i]['host'] = 'localhost';
  102. $cfg['Servers'][$i]['connect_type'] = 'tcp';
  103. $cfg['Servers'][$i]['compress'] = false;
  104. /* Select mysqli if your server has it */
  105. $cfg['Servers'][$i]['extension'] = 'mysql';
  106. $cfg['Servers'][$i]['AllowNoPassword'] = false;
  107.  
  108. $cfg['UploadDir'] = '';
  109. $cfg['SaveDir'] = '';
  110.  
  111. ?>
  112. EOF
  113.  
  114. # Install Cmake and MySQL
  115.  
  116. printf "Start install cmake…n"
  117.     tar -zxvf cmake-2.8.6.tar.gz >> cd cmake-2.8.6 >> ./configure >> gmake >> make install >> make clean
  118.  
  119. # 创建数据库安装目录
  120.     groupadd mysql >> useradd mysql -g mysql -s /sbin/nologin -d /data/mysql/data/ >> chown mysql.mysql -R /data/mysql
  121.     cd .. >> tar -zxvf mysql-5.5.16.tar.gz >> cd mysql-5.5.16 >> cmake -DCMAKE_INSTALL_PREFIX=$dir/mysql -DMYSQL_DATADIR=/data/mysql/data -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DWITH_DEBUG=0 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1  -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 >> make >> make install >> make clean
  122.     cp -r support-files/$mycnf /etc/my.cnf >> sed -i '47 askip-grant-tables' /etc/my.cnf >> chmod +x scripts/mysql_install_db >> ./scripts/mysql_install_db –user=mysql –basedir=$dir/mysql –datadir=/data/mysql/data
  123.     cp -r support-files/mysql.server /etc/rc.d/init.d/mysqld >> sed -i '46,47s/^/#/' /etc/rc.d/init.d/mysqld >> sed -i '46 abasedir='$dir'/mysql/' /etc/rc.d/init.d/mysqld >> sed -i '48 adatadir=/data/mysql/data/' /etc/rc.d/init.d/mysqld >> chmod +x /etc/rc.d/init.d/mysqld >> chkconfig –levels 345 mysqld on >> ln -sf $dir/mysql/bin/* /usr/local/bin/ >> ln -sf $dir/mysql/bin/* /usr/bin/
  124.     /etc/init.d/mysqld start
  125.     mysql -n <<EOF
  126. drop database test;
  127. use mysql;
  128. delete from user where user='';
  129. update user set password=password('$rpass') where user='root';
  130. grant all privileges on *.* to root@"%" identified by '$rpass';
  131. create database eyo;
  132. grant all privileges on eyo.* to eyoadmin@localhost identified by '$passwd';
  133. grant all privileges on eyo.* to eyoadmin@"%" identified by '$passwd';
  134. flush privileges;
  135. quit
  136. EOF
  137.     sed -i '/skip-grant-tables/d' /etc/my.cnf
  138.     /etc/init.d/mysqld restart    
  139.  
  140. sleep 3
  141.  
  142. # Install Apache
  143.  
  144. # 创建网页文件目录
  145.     groupadd www >> useradd www -g www -s /sbin/nologin -d /data/www >> chown www.www /data/www/wwwroot >> chmod 777 /data/www/wwwroot
  146.     cd ../ >> tar -jxvf httpd-2.2.21.tar.bz2 >> cd httpd-2.2.21 >> ./configure –prefix=$dir/apache2 –with-ssl=/usr/ –enable-ssl –enable-so –enable-mime-magic –enable-cache –enable-mem-cache –with-included-apr –enable-deflate=shared –enable-expires=shared –enable-rewrite=shared –enable-static-support >> make >> make install >> make clean >> echo "$dir/apache2/bin/apachectl start" >> /etc/rc.d/rc.local
  147.  
  148. # Install PHP
  149. printf "Start install PHP…n"
  150.     cd ../ >> tar -jxvf php-5.3.8.tar.bz2 >> cd php-5.3.8 >> ./configure –prefix=$dir/php –with-apxs2=$dir/apache2/bin/apxs –with-config-file-path=$dir/php/etc –with-mysql=$dir/mysql –with-libxml-dir –with-jpeg-dir=/usr/lib/ –with-gd –enable-gd-native-ttf –with-png-dir –with-bz2 –with-freetype-dir –with-iconv –with-zlib-dir –with-openssl=/usr/ –with-mcrypt –enable-soap –enable-magic-quotes –enable-ftp –enable-mbstring –enable-exif –disable-cgi –with-pear –enable-zip –with-mhash –with-openssl –enable-inline-optimization –disable-ipv6 –disable-cli –with-mysqli=$dir/mysql/bin/mysql_config –enable-bcmath  –with-curl >> make >> make install >> make clean
  151.     mkdir $dir/php/etc >> cp -r php.ini-production $dir/php/etc/php.ini >> sed -i 's/^;date.timezone =.*/>ndate.timezone = Asia/Chongqing/' $dir/php/etc/php.ini >> ln -sf $dir/php/bin/* /usr/local/bin/ >> ln -sf $dir/php/bin/* /usr/bin/
  152.     
  153. # Install Xcache
  154.     cd .. >> tar -zxvf xcache-1.3.2.tar.gz >> cd xcache-1.3.2 >> $dir/php/bin/phpize >> ./configure –with-php-config=$dir/php/bin/php-config –enable-xcache –enable-xcache-optimizer –enable-xcache-coverager >> make >> make install >> make clean
  155.     cat >> $dir/php/etc/php.ini <<EOF
  156. ;add the following code at the end of file php.ini
  157. [xcache-common]
  158. zend_extension      = $dir/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so
  159.  
  160. [xcache.admin]
  161. xcache.admin.user   = "admin"
  162. ;生成密码: echo -n "passwd"| md5sum
  163. xcache.admin.pass   = "f50dff779a142c7e0987755a247109f7"
  164.  
  165. [xcache]
  166. ; Change xcache.size to tune the size of the opcode cache
  167. xcache.size         = 24M
  168. xcache.shm_scheme   = "mmap"
  169. xcache.count        = 4
  170. xcache.slots        = 8K
  171. xcache.ttl          = 0
  172. xcache.gc_interval  = 0
  173.  
  174. ; Change xcache.var_size to adjust the size of variable cache
  175. xcache.var_size     = 8M
  176. xcache.var_count    = 1
  177. xcache.var_slots    = 8K
  178. xcache.var_ttl      = 0
  179. xcache.var_maxttl   = 0
  180. xcache.var_gc_interval =     300
  181. xcache.test         = Off
  182. xcache.readonly_protection = On
  183. xcache.mmap_path    = "/tmp/xcache"
  184. xcache.coredump_directory =   ""
  185. xcache.cacher       = On
  186. xcache.stat         = On
  187. xcache.optimizer    = Off
  188.  
  189. [xcache.coverager]
  190. xcache.coverager    = On
  191. xcache.coveragedump_directory = ""
  192. EOF
  193.  
  194. # If ZendGuardLoader have download manually, install zend optimizer    
  195. # Install Zend Optimizer
  196. if [ -s ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz ]; then
  197.     cd ../ >> tar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz >> cp -r ZendGuardLoader-php-5.3-linux-glibc23-i386 $dir/php/lib/php/extensions/
  198.     cat >> $dir/php/etc/php.ini <<EOF
  199. zend_extension    = $dir/php/lib/php/extensions/ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so
  200. zend_loader.enable=1
  201. zend_loader.disable_licensing=0
  202. EOF
  203.  
  204. fi
  205.  
  206. # Combined Apche and PHP
  207.  
  208.     # Modify file httpd.conf    
  209.     sed -i 's/#ServerName www.example.com:80/ServerName localhost/' $dir/apache2/conf/httpd.conf
  210.     sed -i 's/ServerAdmin you@example.com/ServerAdmin qitan@goego.net/g' $dir/apache2/conf/httpd.conf
  211.     sed -i 's/AddType application/x-gzip .gz .tgz.*/>n    AddType application/x-httpd-php .php/' $dir/apache2/conf/httpd.conf
  212.     sed -i 's/DirectoryIndex index.html/DirectoryIndex index.html index.htm index.php/' $dir/apache2/conf/httpd.conf
  213.     sed -i '122 a    Allow from all' $dir/apache2/conf/httpd.conf
  214.     cat >> $dir/apache2/conf/httpd.conf <<EOF
  215. Include conf/extra/httpd-mpm.conf
  216. Include conf/extra/httpd-info.conf
  217. Include conf/extra/httpd-vhosts.conf
  218. Include conf/extra/httpd-default.conf
  219.  
  220. <IfModule mod_expires>
  221. ExpiresActive On
  222. ExpiresDefault A60
  223. ExpiresByType image/x-icon A2592000
  224. ExpiresByType application/x-javascript A2592000
  225. ExpiresByType text/css A2592000
  226. ExpiresByType image/gif A604800
  227. ExpiresByType image/png A604800
  228. ExpiresByType image/jpeg A604800
  229. ExpiresByType text/plain A604800
  230. ExpiresByType application/x-shockwave-flash A604800
  231. ExpiresByType video/x-flv A604800
  232. ExpiresByType application/pdf A604800
  233. ExpiresByType text/html A60
  234. </IfModule>
  235.  
  236. <IfModule mod_deflate.c>
  237. SetOutputFilter DEFLATE
  238. AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript
  239. </IfModule>
  240. EOF
  241.     # Setup vhost
  242.     cd $dir/apache2/conf/extra >> mv httpd-vhosts.conf httpd-vhosts.conf.bak
  243.     cat > httpd-vhosts.conf <<EOF
  244. NameVirtualHost *:80
  245.  
  246. <VirtualHost *:80>
  247.     DocumentRoot "/data/www/wwwroot/eyo"
  248.     ServerName $hostname
  249.     ErrorLog "/data/www/logs/$hostname.error.log"
  250. #    CustomLog "|/usr/sbin/cronolog /data/www/logs/$hostname.access.log.%Y%m%d" combined
  251.     CustomLog "/data/www/logs/$hostname-access_log" combined
  252. <Directory "/data/www/wwwroot/eyo">
  253. #    Options None
  254. #    AllowOverride None
  255.     Options FollowSymLinks
  256.     AllowOverride All
  257.     Order allow,deny
  258.     Allow from all
  259. </Directory>
  260. <location /server-status>
  261.     SetHandler server-status
  262.     Order Deny,Allow
  263.     Deny from all
  264.     Allow from 127.0.0.1
  265. </location>
  266. </VirtualHost>
  267. EOF
  268.  
  269.     mv httpd-default.conf httpd-default.conf.bak
  270.     cat > httpd-default.conf <<EOF
  271. Timeout 60
  272. KeepAlive On
  273. MaxKeepAliveRequests 500
  274. KeepAliveTimeout 15
  275. UseCanonicalName Off
  276. AccessFileName .htaccess
  277. ServerTokens Prod
  278. ServerSignature Off
  279. HostnameLookups Off
  280. EOF
  281.  
  282.     mv httpd-info.conf httpd-info.conf.bak
  283.     cat > httpd-info.conf <<EOF
  284. <Location /server-status>
  285.     SetHandler server-status
  286.     Order deny,allow
  287.     Deny from all
  288.     Allow from 127.0.0.1
  289. </Location>
  290. <Location /server-info>
  291.     SetHandler server-info
  292.     Order deny,allow
  293.     Deny from all
  294.     Allow from .example.com
  295. </Location>
  296.  
  297. ExtendedStatus On
  298. EOF
  299.  
  300.     mv httpd-mpm.conf httpd-mpm.conf.bak 
  301.     cat > httpd-mpm.conf <<EOF
  302. <IfModule !mpm_netware_module>
  303.     PidFile "logs/httpd.pid"
  304. </IfModule>
  305. <IfModule !mpm_winnt_module>
  306. <IfModule !mpm_netware_module>
  307. LockFile "logs/accept.lock"
  308. </IfModule>
  309. </IfModule>
  310. <IfModule mpm_prefork_module>
  311.     ServerLimit           1000
  312.     StartServers          10
  313.     MinSpareServers       10
  314.     MaxSpareServers      20
  315.     MaxClients          1000
  316.     MaxRequestsPerChild   5000
  317. </IfModule>
  318. <IfModule mpm_worker_module>
  319.     StartServers          4
  320.     MaxClients          300
  321.     MinSpareThreads      25
  322.     MaxSpareThreads      75
  323.     ThreadsPerChild      25
  324.     MaxRequestsPerChild   0
  325. </IfModule>
  326. <IfModule mpm_beos_module>
  327.     StartThreads            10
  328.     MaxClients              50
  329.     MaxRequestsPerThread 10000
  330. </IfModule>
  331. <IfModule mpm_netware_module>
  332.     ThreadStackSize      65536
  333.     StartThreads           250
  334.     MinSpareThreads         25
  335.     MaxSpareThreads        250
  336.     MaxThreads            1000
  337.     MaxRequestsPerChild      0
  338.     MaxMemFree             100
  339. </IfModule>
  340. <IfModule mpm_mpmt_os2_module>
  341.     StartServers           2
  342.     MinSpareThreads        5
  343.     MaxSpareThreads       10
  344.     MaxRequestsPerChild    0
  345. </IfModule>
  346. <IfModule mpm_winnt_module>
  347.     ThreadsPerChild      150
  348.     MaxRequestsPerChild    0
  349. </IfModule>
  350. EOF
  351.     # Vhost Directory and basic setup
  352.     mkdir /data/www/wwwroot/eyo >> chmod 777 /data/www/wwwroot/eyo
  353.     cat > /data/www/wwwroot/eyo/index.html <<EOF
  354. <html>
  355. <head>
  356. <title>LAMP Install Success.</title>
  357. </head>
  358. <body>
  359. <p>########################## Written By Qitan ####################################</p>
  360. <p>####################### BLOG: http://blog.catjia.com ################################</p>
  361. <p>####################### EMAIL: qqing_lai@hotmail.com ##############################</p>
  362. <p>########################## DATE: 2011-11-09 ###################################</p>
  363. <p>################# LAMP Have Successfully Installed., enjoy it! ############################</p>
  364. </body>
  365. </html>
  366. EOF
  367.     cat > /data/www/wwwroot/eyo/phpinfo.php <<EOF
  368. <html>
  369. <head>
  370. <title>LAMP Install Success.</title>
  371. </head>
  372. <body>
  373. <p>########################## Written By Qitan ####################################</p>
  374. <p>####################### BLOG: http://blog.catjia.com ################################</p>
  375. <p>####################### EMAIL: qqing_lai@hotmail.com ##############################</p>
  376. <p>########################## DATE: 2011-11-09 ###################################</p>
  377. <p>################# LAMP Have Successfully Installed., enjoy it! ############################</p>
  378. </body>
  379. </html>
  380.  
  381. <?php
  382.     phpinfo();
  383. ?>
  384. EOF
  385.     $dir/apache2/bin/apachectl start

(责任编辑:IT)
------分隔线----------------------------