CentOS 6.2下以源代码方式安装LAMP

2022-07-04 09:17:59 浏览数 (2)

目的

以源代码方式安装LAMP。

主要软件版本信息

Linux: CentOS 6.2 32

Apache: 2.2.29

MySQL: 5.6.22

PHP: 5.2.17

使用说明

所有的源代码包和一键自动化安装脚本我已经打包好并上传到我的云盘。

所有的源代码包都是从官网或者官方建议的网站下载的。

相关附件 百度云盘下载:http://pan.baidu.com/s/12JCku

或者

------------------------------------------分割线------------------------------------------

FTP地址:ftp://ftp1.linuxidc.com

用户名:ftp1.linuxidc.com

密码:www.linuxidc.com

在 2015年LinuxIDC.com1月CentOS 6.2下以源代码方式安装LAMP

下载方法见 http://www.linuxidc.com/Linux/2013-10/91140.htm

------------------------------------------分割线------------------------------------------

下载好后将其上传至Linux系统的/tmp目录下并解压。

执行下面的命令,安装的过程比较久。

sh /tmp/lamp/lamp.sh

安装完之后最好执行一下source /etc/profile,将mysql的bin目录添加到环境变量。

默认的htdocs目录位于/usr/local/apache目录。

默认的httpd.conf文件位于/usr/local/apache/conf目录。

默认的php.ini文件位于/usr/local/php/lib目录。

默认的my.cnf文件位于/etc目录。

安装完毕后可以用netstat -nltp来检查httpd和mysqld是否启动。

你可以在/usr/local/apache/htdocs目录下创建一个phpinfo.php文件来检查PHP是否正常工作,phpinfo.php的内容如下:

<?php

phpinfo();

?>

如果你在你的phpinfo.php页面中见到如下截图的信息,说明ZendOptimizer已经正常工作了。

你可以通过http://服务器IP/phpMyAdmin来访问数据库。

为了验证PHP是否正常运作,你可以去下一个实际的项目来运行,比如ECSHOP。

下载好后将整个站点上传到/usr/local/apache/htdocs目录下,并执行下面的命令。

chown -R apache:apache /usr/local/apache/htdocs/*

脚本

#!/bin/bash

# Script Name: One-key Automatic InstallLAMPServer

# Author: yestreenstars

# Create Time: 2015-01-08

# Update Time: 2015-01-08

DOMAIN_NAME='www.example.com' # You can change this.

MYSQL_ROOT_PASSWORD='mypassword' # You can change this.

MYSQL_BASEDIR='/usr/local/mysql' # You can change this.

MYSQL_DATADIR='/data' # You can change this.

echo -n '--Stopping iptables and SELinux...'

(

service iptables stop

chkconfig iptables off

setenforce 0

[ -f /etc/selinux/config ] && sed -i '/^SELINUX=/s/=.*/=disabled/' /etc/selinux/config

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing related software...'

(

yum -y install gcc gcc-c make cmake openssl-devel bison ncurses-devel perl Python-devel freetype-devel wget patch libtool-ltdl-devel

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing apr...'

(

tar xjf /tmp/lamp/apr-1.5.1.tar.bz2 -C /usr/local/src/

cd /usr/local/src/apr-1.5.1/

./configure

make && make install

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing apr-util...'

(

tar xjf /tmp/lamp/apr-util-1.5.4.tar.bz2 -C /usr/local/src/

cd /usr/local/src/apr-util-1.5.4/

./configure --with-apr=/usr/local/apr/ --with-crypto

make && make install

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing pcre...'

(

tar xjf /tmp/lamp/pcre-8.36.tar.bz2 -C /usr/local/src/

cd /usr/local/src/pcre-8.36/

./configure --prefix=/usr/local/pcre

make && make install

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing zlib...'

(

tar xzf /tmp/lamp/zlib-1.2.8.tar.gz -C /usr/local/src/

cd /usr/local/src/zlib-1.2.8/

./configure --prefix=/usr/local/zlib

make && make install

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing apache...'

(

useradd -M -s /sbin/nologin apache

tar xjf /tmp/lamp/httpd-2.2.29.tar.bz2 -C /usr/local/src/

cd /usr/local/src/httpd-2.2.29/

./configure

--prefix=/usr/local/apache

--with-z=/usr/local/zlib

--enable-so --enable-static-support

--enable-deflate=shared

--enable-expires=shared

--enable-rewrite=shared

make && make install

sed -i '69,70s/daemon/apache/;101s/.*/ServerName '$DOMAIN_NAME':80/;170s/$/ index.php/;312a    AddType application/x-httpd-php .php' /usr/local/apache/conf/httpd.conf

/bin/cp -f /tmp/lamp/httpd /etc/init.d/

chmod 755 /etc/init.d/httpd

chkconfig --add httpd

chkconfig httpd on

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing mysql...'

(

useradd -M -s /sbin/nologin mysql

mkdir -p $MYSQL_DATADIR

chown -R mysql:mysql $MYSQL_DATADIR

tar xzf /tmp/lamp/mysql-5.6.22.tar.gz -C /usr/local/src/

cd /usr/local/src/mysql-5.6.22/

cmake

-DMYSQL_BASEDIR=$MYSQL_BASEDIR

-DMYSQL_DATADIR=$MYSQL_DATADIR

-DDEFAULT_CHARSET='utf8'

-DDEFAULT_COLLATION='utf8_general_ci'

make && make install

cd /usr/local/mysql/

./scripts/mysql_install_db --user=mysql --basedir=$MYSQL_BASEDIR --datadir=$MYSQL_DATADIR

/bin/cp -f $PWD/support-files/mysql.server /etc/init.d/mysqld

/bin/cp -f $PWD/support-files/my-default.cnf /etc/my.cnf

echo "PATH=$MYSQL_BASEDIR/bin/:$PATH" >> /etc/profile

chkconfig --add mysqld

chkconfig mysqld on

service mysqld start

$MYSQL_BASEDIR/bin/mysqladmin -uroot password $MYSQL_ROOT_PASSWORD

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing re2c...'

(

tar xzf /tmp/lamp/re2c-0.13.7.5.tar.gz -C /usr/local/src/

cd /usr/local/src/re2c-0.13.7.5/

./configure

make && make install

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing libxml2...'

(

tar xzf /tmp/lamp/libxml2-2.9.2.tar.gz -C /usr/local/src/

cd /usr/local/src/libxml2-2.9.2/

./configure --prefix=/usr/local/libxml2

make && make install

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing libpng...'

(

tar xzf /tmp/lamp/libpng-1.6.16.tar.gz -C /usr/local/src/

cd /usr/local/src/libpng-1.6.16/

./configure --prefix=/usr/local/libpng

make && make install

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing jpeg...'

(

mkdir /usr/local/jpeg

mkdir /usr/local/jpeg/bin

mkdir /usr/local/jpeg/lib

mkdir /usr/local/jpeg/include

mkdir -p /usr/local/jpeg/man/man1

tar xzf /tmp/lamp/jpegsrc.v9a.tar.gz -C /usr/local/src/

cd /usr/local/src/jpeg-9a/

./configure --prefix=/usr/local/jpeg --enable-shared --enable-static

make && make install

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing freetype...'

(

tar xjf /tmp/lamp/freetype-2.5.5.tar.bz2 -C /usr/local/src/

cd /usr/local/src/freetype-2.5.5/

./configure --prefix=/usr/local/freetype

make && make install

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing libmcrypt...'

(

tar xzf /tmp/lamp/libmcrypt-2.5.7.tar.gz -C /usr/local/src/

cd /usr/local/src/libmcrypt-2.5.7/

./configure --prefix=/usr/local/libmcrypt

make && make install

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing libgd...'

(

tar xzf /tmp/lamp/libgd-2.1.0.tar.gz -C /usr/local/src/

cd /usr/local/src/libgd-2.1.0/

./configure --prefix=/usr/local/libgd --with-zlib=/usr/local/zlib/ --with-jpeg=/usr/local/jpeg/ --with-png=/usr/local/libpng/ --with-freetype=/usr/local/freetype/

make && make install

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing libiconv...'

(

tar xzf /tmp/lamp/libiconv-1.14.tar.gz -C /usr/local/src/

cd /usr/local/src/libiconv-1.14/

./configure --prefix=/usr/local/

make && make install

ln -s /usr/local/lib/libiconv.so.2 /usr/lib/

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing bzip2...'

(

tar xzf /tmp/lamp/bzip2-1.0.6.tar.gz -C /usr/local/src/

cd /usr/local/src/bzip2-1.0.6/

make install PREFIX=/usr/local/bzip2

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing php...'

(

tar xzf /tmp/lamp/php-5.2.17.tar.gz -C /usr/local/src/

cd /usr/local/src/php-5.2.17/

wget https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt

patch -p0 -b < txtbgxGXAvz4N.txt

./configure

--prefix=/usr/local/php

--with-apxs2=/usr/local/apache/bin/apxs

--with-libxml-dir=/usr/local/libxml2

--with-gd

--with-jpeg-dir=/usr/local/jpeg

--with-png-dir=/usr/local/libpng

--with-zlib-dir=/usr/local/zlib

--with-freetype-dir=/usr/local/freetype

--with-mcrypt=/usr/local/libmcrypt

--with-mysql=/usr/local/mysql

--with-mysqli=/usr/local/mysql/bin/mysql_config

--enable-soap

--enable-mbstring

--enable-sockets

make ZEND_EXTRA_LIBS='-liconv'

make install

cp /usr/local/src/php-5.2.17/php.ini-dist /usr/local/php/lib/php.ini

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing ZendOptimizer...'

(

tar xzf /tmp/lamp/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz -C /usr/local/src/

mv /usr/local/src/ZendOptimizer-3.3.9-linux-glibc23-i386 /usr/local/ZendOptimizer

echo -e 'n[ZendOptimizer]nzend_extension = /usr/local/ZendOptimizer/data/5_2_x_comp/ZendOptimizer.so' >> /usr/local/php/lib/php.ini

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Installing phpMyAdmin...'

(

tar xjf /tmp/lamp/phpMyAdmin-4.0.10.7-all-languages.tar.bz2 -C /usr/local/src/

mv /usr/local/src/phpMyAdmin-4.0.10.7-all-languages /usr/local/apache/htdocs/phpMyAdmin

cd /usr/local/apache/htdocs/phpMyAdmin

/usr/local/mysql/bin/mysql -uroot -p$MYSQL_ROOT_PASSWORD < examples/create_tables.sql

cp config.sample.inc.php config.inc.php

sed -i '48,60s#// ##' config.inc.php

) &> /dev/null && echo 'Completed!' || exit

echo -n '--Starting apache...'

(

service httpd start

) &> /dev/null && echo 'Completed!' || exit

echo 'Completed!'

0 人点赞