search

How to build a lamp script?

Jun 25, 2017 am 10:06 AM
lampbuildScript

环境:Centos6.6        事先将需要的源码包打包放在lamp.tar.gz中,并解压到/root下

[root@zengqingfu ~]# cat /etc/centos-release 
CentOS release 6.6 (Final)
[root@zengqingfu ~]# uname -a
Linux zengqingfu 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

[root@zengqingfu ~]# ls
anaconda-ks.cfg      lamp.sh                 phpMyAdmin-4.2.5-all-languages.tar.gz                模板
avg_score.awk        lamp.tar.gz             pxe_kickstart.sh                                     视频
cmake-2.8.6.tar.gz   libmcrypt-2.5.8.tar.gz  rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm           图片
history.txt          lines                   sturecord.txt                                        文档
httpd-2.2.17.tar.gz  mcrypt-2.6.8.tar.gz     test                                                 下载
input.txt            mhash-0.9.9.9.tar.gz    var_of_shell.sh                                      音乐
install.log          mysql-5.5.22.tar.gz     ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz  桌面
install.log.syslog   php-5.3.28.tar.gz       公共的

执行步骤:每一步执行之后的输出过程省略了

[root@zengqingfu ~]# ./lamp.sh y   加载光盘搭建本地yum仓库(可选的,已经搭建好yum仓库的可以不执行,直接到下一步)

[root@zengqingfu ~]# ./lamp.sh a    安装Apache web服务

[root@zengqingfu ~]# ./lamp.sh m     安装mysql

[root@zengqingfu ~]# ./lamp.sh p     编译安装PHP


[root@zengqingfu ~]# ./lamp.sh P(大写的)      再次安装PHP,并修改httpd.conf以支持PHP解析
  

[root@zengqingfu ~]# ./lamp.sh o          测试PHP能否成功连接MySQL,http网页能否解析PHP

下面看完整代码:

  1 [root@zengqingfu ~]# cat lamp.sh   2 #!/bin/bash  3 #Filename: lamp.sh  4 #Author: Zeng Qingfu  5 #####  6 if [ $# -ne 1 ];then  7     echo '''  8         Usage:input one option at a time;order to install lamp:first y,second a,third m,fourth p,fifth P,sixth o;  9         Options:y[install yum and stop iptables,selinux];a[install httpd];m[install mysql];p[install php];o[djust httpd.conf,test,install phpMyAdmin]; 10     ''' 11         exit 1 12 elif [ $# -eq 1 ];then 13     if [ $1 != "a" -a $1 != "m" -a $1 != "p" -a $1 != "o" -a $1 != "y" -a $1 != "P" -o $1 == "h" ];then 14          echo ''' 15              Usage:input one option at a time;order to install lamp:first y,second a,third m,fourth p,fifth o; 16              Options:y[install yum and stop iptables,selinux];a[install httpd];m[install mysql];p[install php];o[djust httpd.conf,test,install phpMyAdmin]; 17          ''' 18         exit 1 19     fi 20 fi 21  22 case $1 in 23  24 y) 25 ######stop  iptables and off selinux  and set yum repository################ 26 service iptables stop 27 chkconfig iptables off 28 setenforce 0 29 sed -i '7 s/enforcing/disabled/' /etc/selinux/config 30 umount /dev/cdrom 31 mkdir -p /media/cdrom 32 mount /dev/cdrom /media/cdrom 33 cd /etc/yum.r* 34 mkdir a 35 mv C* a/ 36 /bin/cp a/*M* ./ 37 sed -i '20 s/0/1/' C* 38 rpm --import /media/cdrom/*K* 39 yum -y clean all 40 yum makecache 41 ;; 42 ############################################################################# 43  44 a) 45 echo "installing httpd" 46 ##---------------install httpd------------------ 47     IP=$(hostname -I | awk '{print $1}') 48     echo "$IP www.zengqingfu.com" >> /etc/hosts 49     tar xf httpd-2.2.17.tar.gz -C /usr/src/ 50     rpm -qa make gcc gcc-c++ 51     if  [ $? -eq 0 ];then 
 52         cd /usr/src/httpd-2.2.17/ 53         ./configure --prefix=/usr/local/httpd  --enable-so --enable-rewrite --enable-charset-lite --enable-cgi &&make&&make install  &> /dev/null 54     else 55         yum -y install make gcc gcc-c++   &> /dev/null 56         ./configure --prefix=/usr/local/httpd  --enable-so --enable-rewrite --enable-charset-lite --enable-cgi &&make&&make install  &> /dev/null 57     fi 58     ln -s /usr/local/httpd/bin/*  /usr/local/bin/ 59     /bin/cp /usr/local/httpd/bin/apachectl  /etc/init.d/httpd 60     chmod +x /etc/init.d/httpd 61     sed -i '1a#chkconfig: 35 85 21\n#description: Startup script for the Apache HTTP Server' /etc/init.d/httpd 62     sed -n '1,3p' /etc/init.d/httpd 63     chkconfig --add httpd 64     chkconfig --list httpd 65     cd  /usr/local/httpd/conf/ 66     /bin/cp httpd.conf httpd.conf.origin 67     ROW=$(awk '/#ServerName/{print NR,$0}' httpd.conf | awk '{print $1}') 68     sed -i "$ROW s/#//;s/example/zengqingfu/" httpd.conf 69     apachectl -t 70     [ $? -eq 0 ] && /etc/init.d/httpd start 71     cat /usr/local/httpd/htdocs/index.html 72 ;; 73  74 m) 75 echo "installing mysql" 76 #########-------------------install mysql------------------- 77     cd /root 78     rpm -q mysql-server mysql 79     rpm -e mysql --nodeps 80     rpm -e mysql-server --nodeps 81     rpm -q ncurses-devel 82     [ $? -ne 0 ] && yum -y install ncurses-devel 83     cd /root 84     tar -xf cmake-2.8.6.tar.gz -C /usr/src/  
 85     cd /usr/src/cmake-2.8.6/ 86     ./configure && gmake && gmake install    &> /dev/null 87     groupadd mysql 88     useradd -M -s /sbin/nologin -g mysql mysql 89     cd /root 90     tar xf mysql-5.5.22.tar.gz -C /usr/src/ 91     cd /usr/src/mysql-5.5.22/ 92     cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci  -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc  && make && make install    &> /dev/null 93     chown -R mysql:mysql /usr/local/mysql/ 94     cat support-files/my-medium.cnf > /etc/my.cnf 95     /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/  --datadir=/usr/local/mysql/data/  --user=mysql        &> /dev/null 96     echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile 97     source /etc/profile 98     /bin/cp support-files/mysql.server /etc/init.d/mysqld 99     chmod +x /etc/init.d/mysqld100     chkconfig --add mysqld101     /etc/init.d/mysqld start102     netstat -anpt | grep mysqld103     mysqladmin -uroot password "123456"104     mysqladmin -uroot -p123456 password "zengqingfu";history -c105 ;;106 107 p)108 echo "installing php"109 #####---------------------install php----------------------110     rpm -q php && rpm -e php --nodeps111     rpm -q php-cli && rpm -e php-cli --nodeps112     rpm -q php-ldap && rpm -e php-ldap --nodeps113     rpm -q php-common && rpm -e php-common -nodeps114     rpm -q php-mysql  && rpm -e php-mysql --nodeps115     rpm -q zlib-devel libxml2-devel  
116     if [ $? -ne 0 ];then117         yum -y install zlib-devel libxml2-devel    
118     fi119     cd /root120     rpm -q libmcrypt || tar xf libmcrypt-2.5.8.tar.gz -C /usr/src/121     cd /usr/src/libmcrypt-2.5.8/122     ./configure &&make &&make install &> /dev/null123     ln -s /usr/local/lib/libmcrypt* /usr/lib124     cd /root125     rpm -q mhash ||  tar xf mhash-0.9.9.9.tar.gz -C /usr/src/126     cd /usr/src/mhash-0.9.9.9/127     ./configure &&make&&make install  &> /dev/null128     ln -s /usr/local/lib/libmhash.* /usr/lib/129     cd /root130     rpm -q mcrypt || tar xf mcrypt-2.6.8.tar.gz -C /usr/src/131     cd /usr/src/mcrypt-2.6.8/132     export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH133     ./configure &&make &&make install    &> /dev/null134     cd /root135     tar xf php-5.3.28.tar.gz -C /usr/src/136     cd /usr/src/php-5.3.28/137     ./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    &> /dev/null138     /bin/cp -f php.ini-development /usr/local/php5/php.ini139     cd /root140     ROW=$(awk '/^short_open_tag/{print NR,$0}' /usr/local/php5/php.ini | awk '{print $1}') 
141     sed -i "$ROW s/Off/On/" /usr/local/php5/php.ini142     ROW=$(awk '/default_charset/{print NR,$0}' /usr/local/php5/php.ini | awk '{if(NR==1)print $1}')143     sed -i "$ROW s/;//;s/iso-8859-1/utf-8/" /usr/local/php5/php.ini 
144     cd /root145     tar xf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/146     cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/147     cd php-5.3.x/148     /bin/cp ZendGuardLoader.so /usr/local/php5/lib/php/149     echo -e "zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so\nzend_loader.enable=1" >> /usr/local/php5/php.ini150     tail -2 /usr/local/php5/php.ini151 152 echo "adjust httpd.conf,test,install phpMyAdmin"153 #############--------------------adjust httpd.conf---------------154 ROW=$(awk '/LoadModule php5_module/{print NR,$0}' /usr/local/httpd/conf/httpd.conf | awk '{print $1}')155 sed -i "$ROW a AddType application/x-httpd-php .php" /usr/local/httpd/conf/httpd.conf156 sed -n "$(($ROW+1)) p" /usr/local/httpd/conf/httpd.conf157 ROW=$(awk '/DirectoryIndex/{print NR,$0}' /usr/local/httpd/conf/httpd.conf | awk '{if(NR==2)print $1}')158 sed -i "$ROW s/$/ index.php/" /usr/local/httpd/conf/httpd.conf159 sed -n "$ROW p" /usr/local/httpd/conf/httpd.conf160 httpd -t161 [ $? -eq 0 ] && /etc/init.d/httpd restart162 163 ;;164 165 P)166   cd /usr/src/php-5.3.28/167   make install168   /bin/cp -f php.ini-development /usr/local/php5/php.ini169   cd /root170   ROW=$(awk '/^short_open_tag/{print NR,$0}' /usr/local/php5/php.ini | awk '{print $1}') 
171   sed -i "$ROW s/Off/On/" /usr/local/php5/php.ini172   ROW=$(awk '/default_charset/{print NR,$0}' /usr/local/php5/php.ini | awk '{if(NR==1)print $1}')173   sed -i "$ROW s/;//;s/iso-8859-1/utf-8/" /usr/local/php5/php.ini 
174   cd /root175   tar xf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/176   cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/177   cd php-5.3.x/178   /bin/cp ZendGuardLoader.so /usr/local/php5/lib/php/179   echo -e "zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so\nzend_loader.enable=1" >> /usr/local/php5/php.ini180   tail -2 /usr/local/php5/php.ini181 182 ROW=$(awk '/LoadModule php5_module/{print NR,$0}' /usr/local/httpd/conf/httpd.conf | awk '{print $1}')183 sed -i "$ROW a AddType application/x-httpd-php .php" /usr/local/httpd/conf/httpd.conf184 sed -n "$(($ROW+1)) p" /usr/local/httpd/conf/httpd.conf185 ROW=$(awk '/DirectoryIndex/{print NR,$0}' /usr/local/httpd/conf/httpd.conf | awk '{if(NR==2)print $1}')186 sed -i "$ROW s/$/ index.php/" /usr/local/httpd/conf/httpd.conf187 sed -n "$ROW p" /usr/local/httpd/conf/httpd.conf188 httpd -t189 [ $? -eq 0 ] && /etc/init.d/httpd restart190 service httpd restart191 ;;192 193 o)194 ###########----------------------test---------------195 cd /usr/local/httpd/htdocs/196 echo -e "<?php \nphpinfo();\n?>" > test.php197 echo -e "<?php \n\$link=mysql_connect(&#39;localhost&#39;,&#39;root&#39;,&#39;zengqingfu&#39;);\nif(\$link) echo &#39;Successfully connected mysql&#39;;\nmysql_close();\n?>" > test1.php 
198 ##############------install phpMyAdmin----------------199 cd /root200 tar xf phpMyAdmin-4.2.5-all-languages.tar.gz201 mv phpMyAdmin-4.2.5-all-languages /usr/local/httpd/htdocs/phpMyAdmin202 cd /usr/local/httpd/htdocs/phpMyAdmin/203 /bin/cp config.sample.inc.php config.inc.php204 205 service httpd start206 ;;207 esac

 

The above is the detailed content of How to build a lamp script?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The 5 Essential Elements of Linux: ExplainedThe 5 Essential Elements of Linux: ExplainedMay 07, 2025 am 12:14 AM

The five core elements of Linux are: 1. Kernel, 2. Command line interface, 3. File system, 4. Package management, 5. Community and open source. Together, these elements define the nature and functionality of Linux.

Linux Operations: Security and User ManagementLinux Operations: Security and User ManagementMay 06, 2025 am 12:04 AM

Linux user management and security can be achieved through the following steps: 1. Create users and groups, using commands such as sudouseradd-m-gdevelopers-s/bin/bashjohn. 2. Bulkly create users and set password policies, using the for loop and chpasswd commands. 3. Check and fix common errors, home directory and shell settings. 4. Implement best practices such as strong cryptographic policies, regular audits and the principle of minimum authority. 5. Optimize performance, use sudo and adjust PAM module configuration. Through these methods, users can be effectively managed and system security can be improved.

Linux Operations: File System, Processes, and MoreLinux Operations: File System, Processes, and MoreMay 05, 2025 am 12:16 AM

The core operations of Linux file system and process management include file system management and process control. 1) File system operations include creating, deleting, copying and moving files or directories, using commands such as mkdir, rmdir, cp and mv. 2) Process management involves starting, monitoring and killing processes, using commands such as ./my_script.sh&, top and kill.

Linux Operations: Shell Scripting and AutomationLinux Operations: Shell Scripting and AutomationMay 04, 2025 am 12:15 AM

Shell scripts are powerful tools for automated execution of commands in Linux systems. 1) The shell script executes commands line by line through the interpreter to process variable substitution and conditional judgment. 2) The basic usage includes backup operations, such as using the tar command to back up the directory. 3) Advanced usage involves the use of functions and case statements to manage services. 4) Debugging skills include using set-x to enable debugging mode and set-e to exit when the command fails. 5) Performance optimization is recommended to avoid subshells, use arrays and optimization loops.

Linux Operations: Understanding the Core FunctionalityLinux Operations: Understanding the Core FunctionalityMay 03, 2025 am 12:09 AM

Linux is a Unix-based multi-user, multi-tasking operating system that emphasizes simplicity, modularity and openness. Its core functions include: file system: organized in a tree structure, supports multiple file systems such as ext4, XFS, Btrfs, and use df-T to view file system types. Process management: View the process through the ps command, manage the process using PID, involving priority settings and signal processing. Network configuration: Flexible setting of IP addresses and managing network services, and use sudoipaddradd to configure IP. These features are applied in real-life operations through basic commands and advanced script automation, improving efficiency and reducing errors.

Linux: Entering and Exiting Maintenance ModeLinux: Entering and Exiting Maintenance ModeMay 02, 2025 am 12:01 AM

The methods to enter Linux maintenance mode include: 1. Edit the GRUB configuration file, add "single" or "1" parameters and update the GRUB configuration; 2. Edit the startup parameters in the GRUB menu, add "single" or "1". Exit maintenance mode only requires restarting the system. With these steps, you can quickly enter maintenance mode when needed and exit safely, ensuring system stability and security.

Understanding Linux: The Core Components DefinedUnderstanding Linux: The Core Components DefinedMay 01, 2025 am 12:19 AM

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.

The Building Blocks of Linux: Key Components ExplainedThe Building Blocks of Linux: Key Components ExplainedApr 30, 2025 am 12:26 AM

The core components of the Linux system include the kernel, file system, and user space. 1. The kernel manages hardware resources and provides basic services. 2. The file system is responsible for data storage and organization. 3. Run user programs and services in the user space.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.