云平台快速部署与源码编译lamp应用wordpress

来源:互联网 发布:网络销售聊天技巧话术 编辑:程序博客网 时间:2024/05/17 01:37

前言

这篇博客我决定写的精简一点,不写过多的废话。
所有步骤均在云平台上完成与成功。
lamp指的是
L: linux
A: apache (httpd)
M: mysql, mariadb
M:memcached
P: php, perl, python
我这里用到的是linux+apache+mariadb+php
wordpress是使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。也可以把 WordPress当作一个内容管理系统(CMS)来使用。
首先介绍如何用在CentOS7上快速的部署lamp加wordpress。
后面再介绍关于如何在centos6上面源码编译搭建最新的lamp-wordpress.
最后我会放上在CentOS6上一键部署lamp的脚本。

快速部署lamp应用

安装各种包

[root@localhost ~]# yum install httpd php php-mysql [root@localhost ~]# yum install mariadb-server[root@localhost ~]# systemctl start httpd[root@localhost ~]# systemctl start mariadb

创建数据库及用户

不过首先要做安全措施
运行mysql初始安全脚本

[root@localhost ~]# mysql_secure_installation 

按要求设定密码还有其他的一些选项等。
设定完成可以登录mysql了,我这里不允许匿名账户就用的root登陆的。

[root@localhost ~]# mysql -uroot -pEnter password: 

输入你的root密码,登陆数据库。
(如果是在云平台上面的虚拟机,不是在本地的虚拟机,注意密码一定要复杂,我的IP一天被别人登录失败3W多次…)
首先创建一个数据库

MariaDB [(none)]> create database wpdb;

然后我这里直接创建用户加授权一起做了。
为了安全,一定要锁定你这台服务器的IP,不允许从其他登录。

mysql> grant all  on wpdb.* to wpuser@'123.123.123.123' identified by "wppass";mysql> grant all  on wpdb.* to wpuser@'127.0.0.1' identified by "wppass";mysql> grant all  on wpdb.* to wpuser@'localhost' identified by "wppass";

测试

测试apache是否正常,
测试php和mariadb连接是否正常。
首先在/val/www/html/目录下创建index.php文件
写入代码如下:

[root@localhost /var/www/html]# vim index.php<html><body><h1> LAMP</h1></body></html><?php$mysqli=new mysqli("localhost","root","centos");if(mysqli_connect_errno()){echo "连接数据库失败!";$mysqli=null;exit;}echo "连接数据库成功!";$mysqli->close();phpinfo();?>

然后修改apache的配置文件

[root@localhost /var/www/html]# vim /etc/httpd/conf/httpd.conf DirectoryIndex index.php index.html index.html.var

搜索DirectoryIndex然后在后下面写下index.php,使其优先识别.php后缀文件。
重新加载apache的配置文件

[root@localhost /var/www/html]# systemctl reload httpd

如果一切成功,那么会出现下面这张图片的样子。
这里写图片描述
那么接下来我们就要部署应用wordpress了

部署wordpress

我这里用的是从网上下载的最新的wordpress-4.8.1-zh_CN.tar.gz

[root@localhost ~/src]# tar xvf wordpress-4.8-zh_CN.tar.gz -C /var/www/html/[root@localhost ~/src]# cd /var/www/html[root@localhost /var/www/html]# wordpress/ blog/[root@localhost /var/www/html]#cd blog[root@localhost /var/www/html/blog]# cp wp-config-sample.php  wp-config.php[root@localhost /var/www/html/blog]# vim wp-config.php修改这几样:    // ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //    /** WordPress数据库的名称 */    define('DB_NAME', 'wpdb');    /** MySQL数据库用户名 */    define('DB_USER', 'wpuser');    /** MySQL数据库密码 */    define('DB_PASSWORD', '你之前设置的密码');

登录测试就好了,
在浏览器输出http://IP/blog

这是最简单的,最迅速(十分钟之内即可完成)也是最稳定的部署lamp应用wordpress的方法,缺点是,性能不太好。可以使用xcache,epel源里面就有,直接安装即可。

在CentOS6上源码编译PHP-FPM模式的LAMP

软件版本:apr-1.6.2.tar.gz    httpd-2.4.27.tar.bz2    php-5.6.31.tar.xz             xcache-3.2.0.tar.bz2    apr-util-1.6.0.tar.gz  mariadb-5.5.57-linux-x86_64.tar.gzwordpress-4.8.1-zh_CN.tar.gz(为了使用xcache加速PHP没有使用最新的版本,再更新的版本,xcache不支持)

编译httpd2.4

首先安装开发包组

[root@localhost ~]# yum groupinstall "development tools" -y

我这里把接下来编译过程中缺少的包都放在这里,可以提前安装好,也可以按报错再装。

[root@localhost ~]# yum install openssl-devel pcre-devel expat-devel[root@localhost ~]# tar xvf apr-1.6.2.tar.gz [root@localhost ~]# tar xvf apr-util-1.6.0.tar.gz [root@localhost ~]# tar xvf httpd-2.4.27.tar.bz2 

把apr和apr-util都放在httpd下只用编译一次就好了。

[root@localhost ~]# cp -r apr-1.6.2 httpd-2.4.27/srclib/apr[root@localhost ~]# cp -r apr-util-1.6.0 httpd-2.4.27/srclib/apr-util

准备编译

[root@localhost ~]# cd httpd-2.4.27/[root@localhost ~/src/httpd-2.4.27]# . /configure --prefix=/app/httpd24 \--enable-so --enable-ssl \--enable-rewrite --with-zlib \--with-pcre --with-included-apr \--enable-modules=most \--enable-mpms-shared=all \--with-mpm=prefork

如果没什么问题就可以开始编译安装了

[root@localhost ~/src/httpd-2.4.27]# make -j 4 && make install

加入PATH变量。

[root@localhost ~/src/httpd-2.4.27] # /etc/profile.d/lamp.shPATH=/app/httpd24/bin/:$PATH保存后[root@localhost ~/src/httpd-2.4.27] # . /etc/profile.d/lamp.sh重载lamp.sh文件

编辑服务脚本,也可以复制过来后再修改。我这里就放上这个服务脚本

#!/bin/bash## httpd        Startup script for the Apache HTTP Server## chkconfig: - 85 15# description: The Apache HTTP Server is an efficient and extensible  \#          server implementing the current HTTP standards.# processname: httpd# config: /etc/httpd/conf/httpd.conf# config: /etc/sysconfig/httpd# pidfile: /var/run/httpd/httpd.pid#### BEGIN INIT INFO# Provides: httpd# Required-Start: $local_fs $remote_fs $network $named# Required-Stop: $local_fs $remote_fs $network# Should-Start: distcache# Short-Description: start and stop Apache HTTP Server# Description: The Apache HTTP Server is an extensible server #  implementing the current HTTP standards.### END INIT INFO# Source function library.. /etc/rc.d/init.d/functionsif [ -f /etc/sysconfig/httpd ]; then        . /etc/sysconfig/httpdfi# Start httpd in the C locale by default.HTTPD_LANG=${HTTPD_LANG-"C"}# This will prevent initlog from swallowing up a pass-phrase prompt if# mod_ssl needs a pass-phrase from the user.INITLOG_ARGS=""# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server# with the thread-based "worker" MPM; BE WARNED that some modules may not# work correctly with a thread-based MPM; notably PHP will refuse to start.# Path to the apachectl script, server binary, and short-form for messages.apachectl=/app/httpd24/bin/apachectlhttpd=${HTTPD-/app/httpd24/bin/httpd}prog=httpdpidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}lockfile=${LOCKFILE-/var/lock/subsys/httpd24}RETVAL=0STOP_TIMEOUT=${STOP_TIMEOUT-10}# The semantics of these two functions differ from the way apachectl does# things -- attempting to start while running is a failure, and shutdown# when not running is also a failure.  So we just do it the way init scripts# are expected to behave here.start() {        echo -n $"Starting $prog: "        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS        RETVAL=$?        echo        [ $RETVAL = 0 ] && touch ${lockfile}        return $RETVAL}# When stopping httpd, a delay (of default 10 second) is required# before SIGKILLing the httpd parent; this gives enough time for the# httpd parent to SIGKILL any errant children.stop() {    status -p ${pidfile} $httpd > /dev/null    if [[ $? = 0 ]]; then        echo -n $"Stopping $prog: "        killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd    else        echo -n $"Stopping $prog: "        success    fi    RETVAL=$?    echo    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}}reload() {    echo -n $"Reloading $prog: "    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then        RETVAL=6        echo $"not reloading due to configuration syntax error"        failure $"not reloading $httpd due to configuration syntax error"    else        # Force LSB behaviour from killproc        LSB=1 killproc -p ${pidfile} $httpd -HUP        RETVAL=$?        if [ $RETVAL -eq 7 ]; then            failure $"httpd shutdown"        fi    fi    echo}# See how we were called.case "$1" in  start)    start    ;;  stop)    stop    ;;  status)        status -p ${pidfile} $httpd    RETVAL=$?    ;;  restart)    stop    start    ;;  condrestart|try-restart)    if status -p ${pidfile} $httpd >&/dev/null; then        stop        start    fi    ;;  force-reload|reload)        reload    ;;  graceful|help|configtest|fullstatus)    $apachectl $@    RETVAL=$?    ;;  *)    echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"    RETVAL=2esacexit $RETVAL

可以直接复制上面这个脚本,作为服务较本。

接下来我们要把httpd24加入开价启动,并启动httpd24

[root@localhost ~]# chkconfig --add httpd24[root@localhost ~]# chkconfig --list httpd24[root@localhost ~]# service httpd24 start

二进制安装mariadb

解压缩
并创建软连接
创建mysql用户
运行脚本安装制定路径

[root@localhost ~src/]# tar xvf mariadb-5.5.57-linux-x86_64.tar.gz  -C /usr/local/ [root@localhost ~src/]# cd /usr/local/[root@localhost /usr/local]# ln -s mariadb-5.5.57-linux-x86_64/ mysql[root@localhost /usr/local]# useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql [root@localhost /usr/local]# cd mysql/[root@localhost /usr/local/mysql]# scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql

在/etc/下创建目录mysql
并复制配置文件到/etc/mysql/目录下

[root@localhost /usr/local/mysql]# mkdir /etc/mysql[root@localhost /usr/local/mysql]# cp support-files/my-large.cnf   /etc/mysql/my.cnf

修改配置文件

[root@localhost /usr/local/mysql]#  vim /etc/mysql/my.cnf[mysqld]后面加上三行datadir = /app/mysqldbinnodb_file_per_table = ONskip_name_resolve = ON

复制服务脚本
加入开机启动项
创建日志文件,给与权限。
启动

[root@localhost /usr/local/mysql]#  cp support-files/mysql.server /etc/init.d/mysqld[root@localhost /usr/local/mysql]#  chkconfig --add mysqld[root@localhost /usr/local/mysql]#  chkconfig --list [root@localhost /usr/local/mysql]#  touch /var/log/mysqld.log[root@localhost /usr/local/mysql]#  chown mysql /var/log/mysqld.log[root@localhost /usr/local/mysql]#  service mysqld start

加入PATH路径

[root@localhost /usr/local/mysql]#  vim /etc/profile.d/lamp.sh PATH=/app/httpd24/bin/:$PATHPATH=/usr/local/mysql/bin/:$PATH保存退出重载lamp.sh. /etc/profile.d/lamp.sh

执行mysql安全脚本
root登录数据库
创建数据库和用户

[root@localhost ~]# mysql_secure_installation[root@localhost ~]# mysql -uroot -pcentosMariaDB [(none)]> grant all on wpdb.* to wpuser@'192.168.25.%' identified by 'centos';MariaDB [(none)]> grant all on wpdb.* to wpuser@'127.%' identified by 'centos';MariaDB [(none)]> grant all on wpdb.* to wpuser@'localhost' identified by 'centos';

源码编译PHP

编译时会以来的包我都提前列出来,安装
解压
编译前准备
编译

[root@localhost ~/src]# yum install libxml2-devel bzip2-devel libmcrypt-devel[root@localhost ~/src]# tar xvf php-5.6.31.tar.xz [root@localhost ~/src]# cd php-5.6.31[root@localhost ~/src/php-5.6.31]# . /configure --prefix=/app/php \--with-mysql=/usr/local/mysql \--with-openssl \--with-mysqli=/usr/local/mysql/bin/mysql_config \--enable-mbstring \--with-png-dir \--with-jpeg-dir \--with-freetype-dir \--with-zlib \--with-libxml-dir=/usr \--enable-xml \--enable-sockets \--with-apxs2=/app/httpd24/bin/apxs \--with-mcrypt \--with-config-file-path=/etc \--with-config-file-scan-dir=/etc/php.d \--with-bz2[root@localhost ~/src/php-5.6.31]# make -j 4 && make install

加入PATH路径

[root@localhost ~/src/php-5.6.31]#  vim /etc/profile.d/lamp.sh PATH=/app/php/bin:$PATHPATH=/app/httpd24/bin/:$PATHPATH=/usr/local/mysql/bin/:$PATH保存退出重载PATH路径[root@localhost ~/src/php-5.6.31]#  .  /etc/profile.d/lamp.sh 

复制文件做配置文件

[root@localhost ~/src/php-5.6.31]# cp php.ini-production /etc/php.ini修改httpd24的配置文件[root@localhost ~/src/php-5.6.31]# vim /app/apache24/conf/httpd.conf启动httpd的相关模块去掉下面两行注释LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so 添加如下二行AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps定位至DirectoryIndex index.html修改为:DirectoryIndex index.php index.htm加下面两行ProxyRequests Off 关闭正向代理ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1重启服务[root@localhost ~/src/php-5.6.31]# service httpd24 restart

测试

[root@localhost ~]# vim /app/httpd24/htdocs/index.php<html><body><h1>It works!</h1></body></html><?php$mysqli=new mysqli("localhost","root","centos");if(mysqli_connect_errno()){echo "连接数据库失败!";$mysqli=null;exit;}echo "连接数据库成功!";$mysqli->close();phpinfo();?>

配置wordpress

解压 wordpress

[root@localhost ~src]# tar xvf wordpress-4.8.1-zh_CN.tar.gz  -C /app/httpd24/htdocs[root@localhost ~src]# cd /app/httpd24/htdocs[root@localhost ~/app/httd24/htdocs]# mv wordpress/ blog/[root@localhost ~/app/httd24/htdocs]# cd /app/httpd24/htdocs/blog/[root@localhost ~/app/httd24/htdocs/blog]# cp wp-config-sample.php  wp-config.php[root@localhost ~/app/httd24/htdocs/blog]# vim wp-config.php修改下面的登录信息    /** MySQL数据库用户名 */    define('DB_USER', 'wpuser');    /** MySQL数据库密码 */    define('DB_PASSWORD', 'centos');    /** MySQL主机 */    define('DB_HOST', 'localhost');

登录

在浏览器上登录http://websrv/blog
按顺序填信息

编译xcache实现php加速

[root@localhost ~src]# tar xvf xcache-3.2.0.tar.bz2 [root@localhost ~src]# cd xcache-3.2.0[root@localhost ~src/xcache-3.2.0]# phpize 这里要安装php-devel.x86_64包开始编译[root@localhost ~src/xcache-3.2.0]# ./configure  --enable-xcache --with-php-config=/app/php5/bin/php-config make && make install创建文件夹复制配置文件[root@localhost ~src/xcache-3.2.0]# mkdir /etc/php.d/[root@localhost ~src/xcache-3.2.0]# cp xcache.ini  /etc/php5.d/修改配置文件[root@localhost ~src/xcache-3.2.0]# vim /etc/php5.d/xcache.ini extension = /app/php5/lib/php/extensions/no-debug-non-zts-20131226/xcache.so最后重启php-fpm[root@localhost ~src/xcache-3.2.0]# service php-fpm restart

到这里,编译安装lamp应用wordpress就成功了,剩下的就是自己起自定义自己的博客了。
这里放上我刚刚搭建的博客的地址
http://118.89.166.61
我之前使用了,源码编译安装部署博客,后来,我又换成了yum安装的,虽然版本老旧,
但是稳定。
下面我放上一段朋友写的在CentOS6上一键部署LAMP编译安装的脚本。

一键安装脚本

创建一个文件夹,步入就叫lamp

apr-1.5.2.tar.bz2
apr-util-1.5.4.tar.bz2
httpd-2.4.25.tar.bz2
mariadb-5.5.43-linux-x86_64.tar.gz
php-5.6.31.tar.bz2
这些压缩包都放进去
然后在lamp目录下创建一个服务较本httpd24
代码如下:

[root@localhost ~/lamp]# cat index.php <?php    $conn=mysql_connect('127.0.0.1','root','');    if ($conn)        echo "success";    else        echo "fail";    phpinfo();?>[root@localhost ~/lamp]# cat httpd24 #!/bin/bash## httpd        Startup script for the Apache HTTP Server## chkconfig: - 85 15# description: The Apache HTTP Server is an efficient and extensible  \#          server implementing the current HTTP standards.# processname: httpd# config: /etc/httpd/conf/httpd.conf# config: /etc/sysconfig/httpd# pidfile: /var/run/httpd/httpd.pid#### BEGIN INIT INFO# Provides: httpd# Required-Start: $local_fs $remote_fs $network $named# Required-Stop: $local_fs $remote_fs $network# Should-Start: distcache# Short-Description: start and stop Apache HTTP Server# Description: The Apache HTTP Server is an extensible server #  implementing the current HTTP standards.### END INIT INFO# Source function library.. /etc/rc.d/init.d/functionsif [ -f /etc/sysconfig/httpd ]; then        . /etc/sysconfig/httpdfi# Start httpd in the C locale by default.HTTPD_LANG=${HTTPD_LANG-"C"}# This will prevent initlog from swallowing up a pass-phrase prompt if# mod_ssl needs a pass-phrase from the user.INITLOG_ARGS=""# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server# with the thread-based "worker" MPM; BE WARNED that some modules may not# work correctly with a thread-based MPM; notably PHP will refuse to start.# Path to the apachectl script, server binary, and short-form for messages.apachectl=/usr/local/apache/bin/apachectlhttpd=${HTTPD-/usr/local/apache/bin/httpd}prog=httpdpidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}lockfile=${LOCKFILE-/var/lock/subsys/httpd}RETVAL=0STOP_TIMEOUT=${STOP_TIMEOUT-10}# The semantics of these two functions differ from the way apachectl does# things -- attempting to start while running is a failure, and shutdown# when not running is also a failure.  So we just do it the way init scripts# are expected to behave here.start() {        echo -n $"Starting $prog: "        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS        RETVAL=$?        echo        [ $RETVAL = 0 ] && touch ${lockfile}        return $RETVAL}# When stopping httpd, a delay (of default 10 second) is required# before SIGKILLing the httpd parent; this gives enough time for the# httpd parent to SIGKILL any errant children.stop() {    status -p ${pidfile} $httpd > /dev/null    if [[ $? = 0 ]]; then        echo -n $"Stopping $prog: "        killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd    else        echo -n $"Stopping $prog: "        success    fi    RETVAL=$?    echo    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}}reload() {    echo -n $"Reloading $prog: "    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then        RETVAL=6        echo $"not reloading due to configuration syntax error"        failure $"not reloading $httpd due to configuration syntax error"    else        # Force LSB behaviour from killproc        LSB=1 killproc -p ${pidfile} $httpd -HUP        RETVAL=$?        if [ $RETVAL -eq 7 ]; then            failure $"httpd shutdown"        fi    fi    echo}# See how we were called.case "$1" in  start)    start    ;;  stop)    stop    ;;  status)        status -p ${pidfile} $httpd    RETVAL=$?    ;;  restart)    stop    start    ;;  condrestart|try-restart)    if status -p ${pidfile} $httpd >&/dev/null; then        stop        start    fi    ;;  force-reload|reload)        reload    ;;  graceful|help|configtest|fullstatus)    $apachectl $@    RETVAL=$?    ;;  *)    echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"    RETVAL=2esacexit $RETVAL[root@localhost ~/lamp]# chmod +X httpd24

继续在lamp目录下创建一个index.php文件
[root@localhost ~/lamp]# cat index.php
代码如下:

<?php    $conn=mysql_connect('127.0.0.1','root','');    if ($conn)        echo "success";    else        echo "fail";    phpinfo();?>

重点来了,在lamp目录下创建lamp.sh脚本
代码如下:

[root@localhost ~/lamp]# cat lamp.sh #!/bin/bashsoftware=("apr-1.5.2.tar.bz2" "apr-util-1.5.4.tar.bz2" "httpd-2.4.25.tar.bz2" "php-5.6.31.tar.bz2" "mariadb-5.5.43-linux-x86_64.tar.gz")soft_dir=("apr-1.5.2" "apr-util-1.5.4" "httpd-2.4.25" "php-5.6.31" "mariadb-5.5.43-linux-x86_64")apr=apr-1.5.2apr_util=apr-util-1.5.4httpd=httpd-2.4.25php=php-5.6.31mysql=mariadb-5.5.43-linux-x86_64dir=`pwd`# Pre-installation scriptarr_software=("pcre-devel" "openssl-devel" "bzip2-devel" "libmcrypt-devel" "libxml2-devel" "Development Tools")yum_install_depend_package() {    for i in $(seq 0 $[${#arr_software[*]}-1]); do        if [[ ${arr_software[$i]} == "Development Tools" ]]; then            echo -e "\033[31mInsatll ${arr_software[$i]}, please wait...\033[0m"            yum groupinstall -y ${arr_software[$i]} &> /dev/null         else            echo -e "\033[31mInsatll ${arr_software[$i]}, please wait...\033[0m"            rpm -q ${arr_software[$i]} &> /dev/null || yum install -y ${arr_software[$i]} &> /dev/null        fi    done}#yum install -y wget &> /dev/null#yum install -y pcre-devel &> /dev/null#yum install -y openssl-devel &> /dev/null #yum groupinstall -y "Development Tools" &> /dev/null#yum install -y  bzip2-devel &> /dev/null#yum install -y libmcrypt-devel &> /dev/null#yum install -y libxml2-devel &> /dev/null# installation httpdtar_software() {    for i in $(seq 0 $[${#software[*]}-1]); do        if [ ! -d ${soft_dir[$i]} ]; then            tar xf ${software[$i]} &> /dev/null        fi    done}install_apr() {    echo -e "\033[33mCompile $apr, please wait...\033[0m"    cd $apr     ./configure --prefix=/usr/local/apr/ &> /dev/null || { echo "Compile $apr fail." && exit 1; }    make &> /dev/null    make install &> /dev/null    cd $dir}install_apr_util() {    echo -e "\033[33mCompile $apr_util, please wait...\033[0m"    cd $apr_util     ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr &> /dev/null || { echo "compile $apr_util fail." && exit 1; }    make &> /dev/null     make install &> /dev/null    cd $dir}install_httpd() {    echo -e "\033[33mCompile $httpd, please wait...\033[0m"    id apache &> /dev/null || { groupadd -r apache && useradd -g apache -r apache; }    cd $httpd     ./configure --prefix=/usr/local/apache --sysconf=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork &> /dev/null || { echo -e "\033[32mcompile $httpd fail.\033[0m" && exit 1; }    make &> /dev/null    make install &> /dev/null    cd $dir    cp -f ./httpd24 /etc/init.d/httpd24    chkconfig --add httpd24 &> /dev/null    chkconfig httpd24 on &> /dev/null}# Install mariadbinstall_mysqld() {    echo -e "\033[33mInstall $mysql, please wait...\033[0m"    cd $dir    mv $mysql /usr/local/$mysql    cd /usr/local    ln -sv $mysql mysql &> /dev/null    id mysql &> /dev/null || { groupadd -r mysql && useradd -g mysql -r mysql; }     mkdir -p /data/mydata    chown -R mysql:mysql /data/mydata    cd mysql    ./scripts/mysql_install_db --user=mysql --datadir=/data/mydata/ &> /dev/null    if [ ! -f /etc/my.cnf ]; then        cp ./support-files/my-large.cnf /etc/my.cnf        grep "datadir" /etc/mysql/my.cnf &> /dev/null || sed -i '/\[mysqld\]/a \datadir = /data/mydata\ninnodb_file_per_table = on\nskip_name_resolve = on' /etc/my.cnf    else        [ -d /etc/mysql ] &> /dev/null || mkdir /etc/mysql        cp -f ./support-files/my-large.cnf /etc/mysql/my.cnf        grep "datadir" /etc/mysql/my.cnf &> /dev/null || sed -i '/\[mysqld\]/a \datadir = /data/mydata\ninnodb_file_per_table = on\nskip_name_resolve = on' /etc/mysql/my.cnf    fi    cp -f ./support-files/mysql.server /etc/rc.d/init.d/mysqld    [ -f /var/log/mysqld.log ] &> /dev/null || { touch /var/log/mysqld.log && chown mysql:mysql /var/log/mysqld.log; }    chkconfig --add mysqld    chkconfig mysqld on}# Install phpinstall_php() {    echo -e "\033[33mCompile $php, please wait...\033[0m"    cd $dir/$php    ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts &> /dev/null    echo -e "\033[33mInstall $php, please wait...\033[0m"    make &> /dev/null    make install &> /dev/null    cp -f ./php.ini-production /etc/php.ini     sed -i '/<IfModule mime_module>/a \    AddType application/x-httpd-php .php\n    AddType application/x-httpd-php-source .phps' /etc/httpd24/httpd.conf    sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/g' /etc/httpd24/httpd.conf    cd $dir    [ -f /usr/local/apache/htdocs/index.html ] && rm -f /usr/local/apache/htdocs/index.html && cp -f ./index.php /usr/local/apache/htdocs/index.php    service httpd24 start &> /dev/null    service mysqld start &> /dev/null}main() {    yum_install_depend_package    tar_software    install_apr    install_apr_util    install_httpd    install_mysqld    install_php}main

在给lamp.sh加上执行权限

[root@localhost ~/lamp]# chmod +x lamp.sh 

一键安装的时候使用命令bash lamp.sh,就可以开始自动编译安装,显示效果如下。

[root@localhost ~/lamp]# bash lamp.shInsatll pcre-devel, please wait...Insatll openssl-devel, please wait...Insatll bzip2-devel, please wait...Insatll libmcrypt-devel, please wait...Insatll libxml2-devel, please wait...Insatll Development Tools, please wait...Compile apr-1.5.2, please wait...Compile apr-util-1.5.4, please wait...Compile httpd-2.4.25, please wait...Install mariadb-5.5.43-linux-x86_64, please wait...Compile php-5.6.31, please wait...Install php-5.6.31, please wait...

最后

lamp是一门基础技术,每一个运维到需要掌握,
一定要拥有独立部署环境的能力。
只有部署好了环境,才能在上面跑应用。
写到最后都感觉自己都点精神衰弱了…






顺便推荐一下个人博客地址

www.seeil.life (没备案,域名已挂)
www.seeit.cc(没备案,域名已挂)
http://118.89.166.61(博客地址)
博客会和这边同步跟新的。

ღ ღ ღ 如果觉得文章对您有用,不妨赞一下ღ ღ ღ

原创粉丝点击