1. #!/bin/bash
    2. menu(){
    3. clear
    4. echo " ##############‐‐‐‐Menu‐‐‐‐##############"
    5. echo "# 1. Install Nginx"
    6. echo "# 2. Install MySQL"
    7. echo "# 3. Install PHP"
    8. echo "# 4. Exit Program"
    9. echo " ########################################"
    10. }
    11. choice(){
    12. read p "Please choice a menu[1‐9]:" select
    13. }
    14. install_nginx(){
    15. id nginx &>/dev/null
    16. if [ $? ne 0 ];then
    17. useradd s /sbin/nologin nginx
    18. fi
    19. if [ f nginx1.8.0.tar.gz ];then
    20. tar xf nginx1.8.0.tar.gz
    21. cd nginx1.8.0
    22. yum y install gcc pcredevel openssldevel zlibdevel make
    23. ./configure ‐‐prefix=/usr/local/nginx ‐‐withhttp_ssl_module
    24. make
    25. make install
    26. ln s /usr/local/nginx/sbin/nginx /usr/sbin/
    27. cd ..
    28. else
    29. echo "没有 Nginx 源码包"
    30. fi
    31. }
    32. install_mysql(){
    33. yum y install gcc gccc++ cmake ncursesdevel perl
    34. id mysql &>/dev/null
    35. if [ $? ne 0 ];then
    36. useradd s /sbin/nologin mysql
    37. fi
    38. if [ f mysql5.6.25.tar.gz ];then
    39. tar xf mysql5.6.25.tar.gz
    40. cd mysql5.6.25
    41. cmake .
    42. make
    43. make install
    44. /usr/local/mysql/scripts/mysql_install_db ‐‐user=mysql ‐‐datadir=/usr/local/mysql/data/
    45. ‐‐basedir=/usr/local/mysql/
    46. chown R root.mysql /usr/local/mysql
    47. chown R mysql /usr/local/mysql/data
    48. /bin/cp f /usr/local/mysql/supportfiles/mysql.server /etc/init.d/mysqld
    49. chmod +x /etc/init.d/mysqld
    50. /bin/cp f /usr/local/mysql/supportfiles/mydefault.cnf /etc/my.cnf
    51. echo "/usr/local/mysql/lib/" >> /etc/ld.so.conf
    52. ldconfig
    53. echo 'PATH=\$PATH:/usr/local/mysql/bin/' >> /etc/profile
    54. export PATH
    55. else
    56. echo "没有 mysql 源码包"
    57. exit
    58. fi
    59. }
    60. install_php(){
    61. #安装 php 时没有指定启动哪些模块功能,如果的用户可以根据实际情况自行添加额外功能如‐‐with‐gd 等
    62. yum y install gcc libxml2devel
    63. if [ f mhash0.9.9.9.tar.gz ];then
    64. tar xf mhash0.9.9.9.tar.gz
    65. cd mhash0.9.9.9
    66. ./configure
    67. make
    68. make install
    69. cd ..
    70. if [ ! f /usr/lib/libmhash.so ];then
    71. ln s /usr/local/lib/libmhash.so /usr/lib/
    72. fi
    73. ldconfig
    74. else
    75. echo "没有 mhash 源码包文件"
    76. exit
    77. fi
    78. if [ f libmcrypt2.5.8.tar.gz ];then
    79. tar xf libmcrypt2.5.8.tar.gz
    80. cd libmcrypt2.5.8
    81. ./configure
    82. make
    83. make install
    84. cd ..
    85. if [ ! f /usr/lib/libmcrypt.so ];then
    86. ln s /usr/local/lib/libmcrypt.so /usr/lib/
    87. fi
    88. ldconfig
    89. else
    90. echo "没有 libmcrypt 源码包文件"
    91. exit
    92. fi
    93. if [ f php5.4.24.tar.gz ];then
    94. tar xf php5.4.24.tar.gz
    95. cd php5.4.24
    96. ./configure ‐‐prefix=/usr/local/php5 ‐‐withmysql=/usr/local/mysql ‐‐enablefpm ‐‐
    97. enablembstring ‐‐withmcrypt ‐‐withmhash ‐‐withconfigfilepath=/usr/local/php5/etc ‐‐with
    98. mysqli=/usr/local/mysql/bin/mysql_config
    99. make && make install
    100. /bin/cp f php.iniproduction /usr/local/php5/etc/php.ini
    101. /bin/cp f /usr/local/php5/etc/phpfpm.conf.default /usr/local/php5/etc/phpfpm.conf
    102. cd ..
    103. else
    104. echo "没有 php 源码包文件"
    105. exit
    106. fi
    107. }
    108. while :
    109. do
    110. menu
    111. choice
    112. case $select in
    113. 1)
    114. install_nginx
    115. ;;
    116. 2)
    117. install_mysql
    118. ;;
    119. 3)
    120. install_php
    121. ;;
    122. 4)
    123. exit
    124. ;;
    125. *)
    126. echo Sorry!
    127. esac
    128. done