LAMP安装流程

1、系统环境

[root@testserver src]# cat /etc/issue
CentOS release 6.7 (Final)
Kernel \r on an \m
[root@testserver src]# uname -a
Linux testserver 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

2、软件包准备

mysql 、php、 apache、 nginx 安装包事先要下载到/usr/local/src目录下,如名字不对需要更改脚本里的软件包名称;
httpd-2.4.18.tar.gz 、mysql-5.6.25.tar.gz 、nginx-1.6.2.tar.gz、 php-5.6.10.tar.gz

3、install dependencies packages

yum install wget gcc gcc-c++ make re2c curl curl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel cmake bzip2 bzip2-devel pcre pcre-devel -y

4、安装mysql

cd /usr/local/src
tar -zxf mysql-5.6.25.tar.gz
cd mysql-5.6.25
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

make && make install

useradd -M -s /sbin/nologin mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql/
chown -R mysql:mysql /usr/local/mysql/

cd /usr/local/mysql/scripts/
./mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql

/bin/cp /usr/local/mysql/my.cnf /etc/my.cnf
sed -i '/^\[mysqld\]$/a\user = mysql\ndatadir = /data/mysql\ndefault_storage_engine = InnoDB\n' /etc/my.cnf

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
sed -i 's#^datadir=#datadir=/data/mysql#' /etc/init.d/mysqld
sed -i 's#^basedir=#basedir=/usr/local/mysql#' /etc/init.d/mysqld
service mysqld start
chkconfig --add mysqld
chkconfig mysqld on

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
/etc/init.d/iptables save

echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile

5、安装apache

cd /usr/local/src
wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz
wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
 
tar zxf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr
make && make install
 
cd /usr/local/src
tar zxf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

cd /usr/local/src
tar zxf httpd-2.4.18.tar.gz
/bin/cp -r apr-1.5.2 /usr/local/src/httpd-2.4.18/srclib/apr
/bin/cp -r apr-util-1.5.4 /usr/local/src/httpd-2.4.18/srclib/apr-util
cd httpd-2.4.18
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre --enable-mods-shared=most --enable-so --with-included-apr
make && make install

echo "export PATH=$PATH:/usr/local/apache2/bin" >> /etc/profile
source /etc/profile

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables save
/usr/local/apache2/bin/apachectl

6、安装php

cd /usr/local/src
tar zxf php-5.6.10.tar.gz
cd php-5.6.10
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6

make && make install

cp /usr/local/src/php-5.6.10/php.ini-production /usr/local/php/etc/php.ini
sed -i 's#^;date.timezone =#date.timezone=Asia/Shanghai#' /usr/local/php/etc/php.ini

./configure出现的问题及解决方案:

报错内容:configure: error: mcrypt.h not found. Please reinstall libmcrypt
网上搜索了很多,包括自带的 yum install libmcrypt libmcrypt-devel,这个是没有效果的。

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz   
tar -zxf libmcrypt-2.5.7.tar.gz         
cd libmcrypt-2.5.7        
./configure        
make && make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make && make install
cd ../../
然后再重新编译php

7、设置

sed -i '/AddType application\/x-gzip .gz .tgz/a\ AddType application/x-httpd-php .php\n' /usr/local/apache2/conf/httpd.conf
sed -i 's#index.html#index.html index.php#' /usr/local/apache2/conf/httpd.conf
sed -i '/#ServerName www.example.com:80/a\ServerName localhost:80\n' /usr/local/apache2/conf/httpd.conf

cat >> /usr/local/apache2/htdocs/test.php <<EOF
<?php
echo "PHP is OK\n";
?>
EOF
 
/usr/local/apache2/bin/apachectl graceful
curl localhost/test.php
posted @ 2016-01-14 14:27  幻月0412  阅读(172)  评论(0编辑  收藏  举报