centos6.3編譯安裝Apache2.4.3+PHP5.4.8+Mysql5.5.8
作者:星之宇 ┊ 時間:2012-10-22 14:12 ┊ 分類: 網站技術 ┊ 閱讀:1712 ┊ 評論:5
以虛擬機VirtualBox 版本是4.1.20(內存設置爲512M,centos安裝是文本模式下安裝),全新以最小化包安裝了32位的CentOS6.3系統,作爲本地web環境,上次講了在windows下安裝Apache2.4.3+PHP5.4.8+Mysql5.5.8,這次就說說linux(centos)下編譯安裝的過程(全命令模式下完成)。
以下分爲幾部分來說:
第一部分:準備工作。
1.全新centos6.3(以下簡稱centos)最基本的設置略過(比如用戶、網絡設置等等)。
2.這裏可以聯網了。這裏用到的我不寫到一起了。
安裝wget工具。
[root@localhost ~]# yum -y install wget
安裝GCC軟件套件
[root@localhost ~]# yum -y install gcc
[root@localhost ~]# yum -y install gcc-c++
安裝make
[root@localhost ~]# yum -y install make
安裝vim
[root@localhost ~]# yum -y install vim
3.下載各個安裝包:基本上多是官網提供的源。
[root@localhost ~]# wget http://apache.etoak.com/httpd/httpd-2.4.3.tar.gz
[root@localhost ~]# wget http://apache.etoak.com/apr/apr-1.4.6.tar.gz
[root@localhost ~]# wget http://apache.etoak.com/apr/apr-util-1.5.1.tar.gz
[root@localhost ~]# wget http://hk1.php.net/distributions/php-5.4.8.tar.gz
[root@localhost ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz
[root@localhost ~]# wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
(注意大小寫,不然會報404錯誤的。)
[root@localhost ~]#ls
查看下有沒有全部下好,如圖片中紅色的就是剛剛下載的。
4.以上源碼包全部用tar zxvf xxx.tar.gz解壓縮
[root@localhost ~]# tar zxvf httpd-2.4.3.tar.gz
[root@localhost ~]# tar zxvf apr-1.4.6.tar.gz
[root@localhost ~]# tar zxvf apr-util-1.5.1.tar.gz
[root@localhost ~]# tar zxvf php-5.4.8.tar.gz
[root@localhost ~]# tar zxvf pcre-8.31.tar.gz
[root@localhost ~]# tar zxvf libmcrypt-2.5.8.tar.gz
[root@localhost ~]#ls
查看如圖中藍色的就是解壓好文件夾。
第二部分:安裝Apache。
1.安裝apache依賴包pcre
[root@localhost ~]# cd ./pcre-8.31
[root@localhost ~]# ./configure --prefix=/usr/local/pcre
[root@localhost ~]# make && make install
2.安裝openssl
[root@localhost ~]# yum -y install openssl-devel
3.移動apr和apr-util到httpd-2.4.3文件夾下srclib內並且重命名
[root@localhost ~]# mv apr-1.4.6 /httpd-2.4.3/srclib/apr
[root@localhost ~]# mv apr-util-1.5.1 /httpd-2.4.3/srclib/apr-util
4.安裝Apache 2.4.3主程序
[root@localhost ~]# cd ./httpd-2.4.3
[root@localhost ~]# ./configure --prefix=/usr/local/apache --enable-so --enable-deflate=shared --enable-ssl=shared --enable-expires=shared --enable-headers=shared --enable-rewrite=shared --enable-static-support --with-included-apr --with-mpm=prefork --enable-cache --enable-file-cache --with-pcre=/usr/local/pcre
[root@localhost ~]# make && make install
5.基本配置讓apache自啓動。
修改httpd.conf,wq保存退出
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
找到“#ServerName www.example.com:80”,在下面加上這一行
ServerName localhost:80
注意:沒有沒有修改直接執行自啓動修改,會出現錯誤提示:“AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using centos.huoba. Set the 'ServerName' directive globally to suppress this message”
加入配置文件實現自啓動
[root@localhost ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
[root@localhost ~]# vim /etc/init.d/httpd
在#!/bin/sh 下面加上這兩行,wq保存退出
# chkconfig: 345 90 90
# description: Apache
[root@localhost ~]# chkconfig --add /etc/init.d/httpd
[root@localhost ~]# service httpd start
暫時關閉防火牆測試。
[root@localhost ~]# /etc/init.d/iptables status ##查看防火牆狀態
[root@localhost ~]# /etc/init.d/iptable stop ##本次關閉防火牆
[root@localhost ~]# /etc/init.d/iptable restart ##重啓防火牆
[root@localhost ~]#chkconfig --level 35 iptables off ##永久關閉防火牆
由於我用的是虛擬機,關閉防火牆後訪問測試。瀏覽輸入ip地址,出現“It works”就說明Apache已經正常安裝。
防火牆設置:
如果是虛擬機的話,用來作爲本地環境的,還是永久關閉防火牆比較簡單。
當然你也可以對防火牆進行設置。
添加端口80,443以及ssh端口22,你也可以添加ftp端口21等等
[root@localhost ~]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@localhost ~]# /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
[root@localhost ~]# /sbin/iptables -I INPUT -p tcp --dport 443 -j ACCEPT
[root@localhost ~]# /etc/init.d/iptables save ##保存配置
[root@localhost ~]# /etc/init.d/iptable restart ##重啓防火牆
到此。Apache的設置基本完成。
第三部分:安裝MySQL
1.下載mysql,上面的時候忘記下了
[root@localhost ~]# wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.28.tar.gz
解壓mysql-5.5.28.tar.gz
[root@localhost ~]# tar zxvf mysql-5.5.28.tar.gz
2.安裝cmake
[root@localhost ~]# yum -y install cmake make
安裝一些其他
[root@localhost ~]# yum -y install autoconf bison automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*
3.安裝mysql 5.5.28主程序
[root@localhost ~]# cd mysql-5.5.28
[root@localhost ~]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFIGDIR=/usr/local/mysql/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql
[root@localhost ~]# make && make install
官方說明:
The MyISAM, MERGE, MEMORY, and CSV engines are mandatory (always compiled into the server) and need not be installed explicitly.(說明:mysql默認支持的數據庫引擎有MyISAM, MERGE, MEMORY, CSV,無需在編譯時再聲明)
所以上面的編譯條件省掉了如下兩行
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
但INNODB一定要聲明式安裝,所以多了這一行
-DWITH_INNOBASE_STORAGE_ENGINE=1
4.配置mysql 5.5.28
[root@localhost ~]# cp /usr/loacl/mysql/support-files/my-huge.cnf etc/my.cnf
[root@localhost ~]# vi /etc/my.cnf
修改my.cnf配置,把innodb相關選項前面的#去掉,大概在115-130行之間。
以下命令爲mysql 啓動及自啓動配置
[root@localhost ~]# cp /usr/loacl/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &
chkconfig --add mysqld
chkconfig --level 345 mysqld on
[root@localhost ~]# service mysqld start
一般只要把my.cnf設置好這裏就不會報錯。如果有錯請留言評論,我會試着幫你解決
剩下就是mysql的設置了。
[root@localhost ~]# /usr/local/server/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
彈出輸入password的提示,直接回車。
設置密碼:
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
mysql> quit
刪除root密碼爲空的記錄
mysql> use mysql;
mysql> delete from user where password='';
mysql> flush privileges;
配置mysql允許root遠程登錄
mysql> grant all privileges on *.* to root@'%' identified by "123456";
mysql> flush privileges;
mysql> quit
主機可以通過軟件來遠程訪問centos的mysql數據庫了。
到此mysql安裝和設置基本完成。
第四部分:安裝PHP 5.4.8
1.查看apache版本
[root@localhost ~]# /usr/local/apache/bin/httpd -v
查看apache已編譯安裝的模塊
[root@localhost ~]# /usr/local/apache/bin/httpd -M
2.安裝相關資源及依賴包
[root@localhost ~]# yum -y install bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel
3.安裝php 5.4.8程序
[root@localhost ~]# vim /usr/local/apache/bin/apxs
編輯apxs,把#!/replace/with/path/to/perl/interpreter -w 這一行(一般是第一行)更改爲"#!/usr/bin/perl -w"。
注意:如果沒有改,編譯的時候會出現了“Sorry, I cannot run apxs”的錯誤提示。因爲沒有指明正確的perl執行程序的位置。
[root@localhost ~]# cd php-5.4.8
[root@localhost ~]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/include/libxml2 --with-config-file-path=/usr/local/apache/conf --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd --enable-gd-native-ttf --with-zlib --with-mcrypt --with-pdo-mysql=/usr/local/mysql --enable-shmop --enable-soap --enable-sockets --enable-wddx --enable-zip --with-xmlrpc --enable-fpm --enable-mbstring --with-zlib-dir --with-bz2 --with-curl --enable-exif --enable-ftp --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-freetype-dir=/usr/lib/
[root@localhost ~]# make && make install
php配置,編譯安裝時我的php.ini文件目錄指向/usr/local/apache/conf
[root@localhost ~]# cd php-5.4.8
[root@localhost ~]# cp php.ini-production /usr/local/apache/conf/php.ini
4.apache配置文件httpd.conf相關修改以支持PHP
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
1. 添加php支持。
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
2. 添加默認索引頁面index.php,再找到“DirectoryIndex”,在index.html後面加上“ index.php”
DirectoryIndex index.html index.php
3. 不顯示目錄結構,找到“Options Indexes FollowSymLinks”,修改爲
Options FollowSymLinks
4. 開啓Apache支持僞靜態,找到“AllowOverride None”,修改爲
AllowOverride All
保存httpd.conf配置,然後再執行以下兩行命令
[root@localhost ~]# chown -R nobody. /usr/local/apache/htdocs/
[root@localhost ~]# chmod -R 777 /usr/local/apache/htdocs/
[root@localhost ~]# service httpd restart
注意:重啓有可能libphp5.so報錯,這個有多種情況,這裏就不一一說明了。你可以把錯誤提示貼出來求解決方法。
我在htdocs新建了一個index.php,
<?php phpinfo();?>
運行了下,部分截圖如下:
到了這裏php的基本安裝已經完成了。
總之,在編譯安裝的時候,等的時間最久。安裝這3個軟件中報錯n多,大部分是由於沒有相關資源或者沒有依賴包出現的報錯。
這裏碰到的錯誤就不一一說明了。本來我還想全部用離線資源包來本地編譯安裝,發現要安裝的東西太多了,所以也就一部分相關資源和依賴包用了在線源更新安裝。
最後不得不說一句:不用源更新安裝,不用一鍵安裝包就是找罪受。
最後再附上emlog5.0安裝好之後的展示圖,忙了這麼久裝個程序試試: