linux下手动编译安装LAMP平台

编译安装LAMP平台

软件版本都是最新稳定版本:apache 2.2.19  mysql 5.5.14  php 5.3.6
源码包编译安装位置(prefix)        /usr/local/webserver


1、移除系统自带的rpm包的http mysql php
# yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd  -y

 
2 安装必备的开发包
# yum -y install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel \
ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel \
gettext-devel  pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel \
libxml2-devel curl-devel  libicu libicu-devel libmcrypt libmcrypt-devel libmhash libmhash-devel
 
 
3.同步系统时间:
# vim /etc/ntp.conf  //添加下面三行内容(19行下面添加) 
server 3.cn.pool.ntp.org
server 3.asia.pool.ntp.org
server 0.asia.pool.ntp.org
 
# /sbin/service ntpd stop
# /usr/sbin/ntpdate  cn.pool.ntp.org  //更新时间
# /sbin/service ntpd start
# /sbin/chkconfig ntpd on
 


4.编译安装MySQL

##编译环境前提(mysql 5.5.x 不再用 configure,而用cmake)
##下载安装cmake
# cd /usr/src
# wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
# tar xvf  cmake-2.8.4.tar.gz
# cd cmake-2.8.4
# ./configure
# make
# make install
 

##下载最新版的mysql 源码安装包
# cd /usr/src
# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.14.tar.gz/from/ht...
# tar zxvf mysql-5.5.14.tar.gz
# cd mysql-5.5.14
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql \
         -DMYSQL_DATADIR=/data/mysql/data \
         -DWITH_MYISAM_STORAGE_ENGINE=1 \
         -DWITH_INNOBASE_STORAGE_ENGINE=1 \
         -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
         -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
         -DENABLED_LOCAL_INFILE=1 \
         -DDEFAULT_CHARSET=utf8 \
         -DDEFAULT_COLLATION=utf8_general_ci \
         -DEXTRA_CHARSETS=all \
         -DMYSQL_TCP_PORT=3306
        
# make
# make install
 
##安装配置MySQL
 # userdel -r mysql
 # groupadd -g 3306 mysql
 # useradd -u 3306 -g mysql -M -s /sbin/nologin mysql
 # mkdir -p /data/mysql/data
 # mkdir -p /data/mysql/log
 # chown -R mysql:mysql /data/mysql
 # chmod -R 755 /data/mysql
 # cp support-files/my-medium.cnf /etc/my.cnf
 # /usr/local/webserver/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/webserver/mysql --datadir=/data/mysql/data &   //初始化数据库
 # cp support-files/mysql.server /etc/init.d/mysqld
 # chmod +x /etc/init.d/mysqld
 # /sbin/chkconfig --add mysqld
 # /sbin/chkconfig mysqld on
 # /sbin/service  mysqld start
 # netstat -tnlp |grep 3306
 
# cd /usr/local/bin //进入用户的默认搜索路径下建立mysql命令的软连接,可以直接执行mysql命令
# ln -s /usr/local/webserver/mysql/bin/mysql mysql
# ln -s /usr/local/webserver/mysql/bin/mysqldump mysqldump
# ln -s /usr/local/webserver/mysql/bin/mysqladmin  mysqladmin
 
# mysqladmin -u root  password '123456'  //设置数据库密码
# mysql -u root -p
mysql> flush privileges;
 
 
5、apache安装
# cd /usr/src
# wget http://labs.renren.com/apache-mirror//httpd/httpd-2.2.19.tar.gz
# tar xvf httpd-2.2.19.tar.gz
#cd httpd-2.2.19
# ./configure --prefix=/usr/local/webserver/apache \
--enable-so --enable-rewrite \
 --enable-mods-shared=most --sysconfdir=/etc/httpd
# make
# make install
 
# /usr/local/webserver/apache/bin/apachectl start
# netstat -tnlp |grep httpd
# cp /usr/local/webserver/apache/bin/apachectl /etc/init.d/httpd
# /sbin/service  httpd start
# netstat -tnlp |grep 80
# vim /etc/init.d/httpd (第二行添加注释信息,添加为系统服务)
   # chkconfig: 35 61 61
   # description: Apache
 

# /sbin/chkconfig --add httpd
# /sbin/chkconfig httpd on

 

6、PHP安装
# cd /usr/src
# wget http://cn.php.net/get/php-5.3.6.tar.gz/from/this/mirror
# tar xvf php-5.3.6.tar.gz
# cd php-5.3.6
# ./configure --prefix=/usr/local/webserver/php \
--mandir=/usr/local/share/man \
--infodir=/usr/local/share/info \
--with-apxs2=/usr/local/webserver/apache/bin/apxs \
--enable-cgi --with-mysql=/usr/local/webserver/mysql/ \
--with-config-file-path=/usr/local/webserver/php/etc \
--with-pdo-mysql=/usr/local/webserver/mysql \
--with-mysqli=/usr/local/webserver/mysql/bin/mysql_config \
--enable-zip --enable-sqlite-utf8 -enable-sockets \
--enable-soap --enable-pcntl --enable-mbstring \
--enable-intl --enable-calendar --enable-bcmath \
--enable-exif --with-mcrypt --with-mhash --with-gd \
--with-png-dir --with-jpeg-dir --with-freetype-dir \
--with-libxml-dir --with-curl --with-curlwrappers \
--with-zlib   --with-openssl --with-kerberos=shared \
--with-gettext=shared --with-xmlrpc=shared
 
# make
# make install
 
# cp php.ini-recommended /usr/local/webserver/php/etc/php.ini   //拷贝配置文件

7、整合Apache与PHP及系统初始化配置
# vim /usr/local/apache/conf/httpd.conf
查找AddType application/x-gzip .gz .tgz,在该行下面添加
AddType application/x-httpd-php .php
查找DirectoryIndex index.html 把该行修改成
DirectoryIndex index.html index.htm index.php 
:wq 保存退出

测试apache和php是否整合成功,下面我们测试apache和php是否整合成功,在apache文档跟目录下新建一个小小的php程序
# cd /usr/local/webserver/apache/htdocs
# sudo vi index.php  //在index.php文件中写入下面三行
<?php
phpinfo();
?>
 
重启apache服务
# /sbin/service  httpd restart
访问,在浏览器中输入http://localhost/index.php 出现php信息界面则说明整合成功。

你可能感兴趣的:(linux下手动编译安装LAMP平台)