centos6.5安裝 LAMP環境搭建

mysql用的二進制包安裝。 Apache php 用的源碼包

mysql版本5.5.46    Apache版本2.4.7  PHP版本:5.5

安裝mysql

mysql下載地址:http://mirrors.sohu.com/mysql/MySQL-5.5/

初始化

[root@localhost lamp]# tar zxvf mysql-5.5.46-linux2.6-x86_64.tar.gz   #解壓   

[root@localhost lamp]# mv mysql-5.5.46-linux2.6-x86_64  /usr/local/mysql   #移動位置,並去掉版本好

[root@localhost lamp]# useradd -s /sbin/nologin -M mysql    #增加mysql用戶。 不能登錄 不創建家目錄

[root@localhost lamp]# mkdir -p /data/mysql    #創建datadir  數據庫文件會放在這裏

[root@localhost lamp]# chown -R mysql:mysql /data/mysql/    #更改屬組 屬主

[root@localhost lamp]# cd /usr/local/mysql/                #進入目錄

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql     --user定義數據庫的所屬主,--datadir 定義安裝目錄

                                   

接下來會看到有兩個OK.說明執行正確。


[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

#複製啓動腳本文件

[root@localhost mysql]# chmod 755 /etc/init.d/mysqld

# 修改啓動腳本權限

[root@localhost mysql]# vim /etc/init.d/mysqld

#修改啓動腳本。 找到bashedir 增加下面的路徑

basedir=/usr/local/mysql    # 安裝位置

datadir=/data/mysql          #  數據庫位置

然後把啓動腳本加入系統服務項,設定開機啓動

chkconfig --add mysqld

chkconfig mysqld on

service mysqld start

如果啓動不了。請到/data/mysql 目錄下查看錯誤日誌。這個日誌通常是主機名.err。

檢查MYSQL石否啓動的命令爲:

ps aux |grep mysqld

netstat -an |grep 3306



安裝Apache2.4.7版本。

下載地址爲:http://mirrors.sohu.com/apache/

tar zxvf httpd-2.4.7.tar.gz     #解壓文件

cd httpd-2.4.7               #進入目錄

./configure --prefix=/usr/local/apache2/ --sysconfdir=/usr/local/apache2/etc --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared   #編譯參數

錯誤

configure: error:Bundled APR requested but not found at./srclib/.

  tar zxvf apr-1.4.6.tar.gz     #解壓apr包

  tar -zxvf apr-util-1.4.1.tar.gz   #解壓apr-util包

  cp -r /lamp/apr-1.4.6 /lamp/httpd-2.4.7/srclib/apr

  cp -r /lamp/apr-util-1.4.1 /lamp/httpd-2.4.7/srclib/apr-util    # 然後把兩個包複製到httpd-2.4.7/srclib/ 裏面並且取消版本號。


錯誤:

configure: error: in `/lamp/httpd-2.4.7/srclib/apr':

configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details

configure failed for srclib/apr


yum -y install gcc-c++   #安裝 gcc

錯誤:

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

tar zxvf pcre-8.34.tar.gz

[root@localhost lamp]# cd pcre-8.34

[root@localhost pcre-8.34]# ./configure  && make &&  make install


錯誤

checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures


yum -y install openssl-devel   #yum安裝


把上面4個錯誤解決後。重新 ./configure 參數編譯 無問題就執行

make 

make install


/usr/local/apache2/bin/apachectl start         # 啓動apache

啓動完後用以下命令檢查apache是否正常啓動,

ps aux |grep httpd

netstat -an |grep :80


如果不能啓動 請清空防火牆規格。關閉selinux

防火牆清空命令如下,關閉selinux 請修改selinux配置文件。

iptables -F

service iptables save


通過瀏覽器輸入地址訪問:http://192.168.137.30 (我服務器的地址)  。若能顯示“It works”表明apache正常工作。

設置Apache系統開機是自動開啓。

vim /etc/rc.d/rc.local

增加一行 把下面增加進去。

/usr/local/apache2/bin/apachectl start    


安裝php5.5版本

tar zxvf php-5.5.9.tar.gz  #解壓php安裝包

cd php-5.5.9  #進入php文件

./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  --with-mcrypt=/usr/local/libmcrypt/    #編譯參數


以下***爲解決方法。
錯誤
configure: error: xml2-config not found. Please check your libxml2 installation.
yum install -y libxml2-devel
錯誤

configure: error: Please reinstall the BZip2 distribution

yum install -y bzip2 bzip2-devel

錯誤

configure: error: jpeglib.h not found.

 yum install libjpeg-devel -y


錯誤

configure: error: png.h not found.

 yum install libpng-devel -y


錯誤

configure: error: freetype-config not found.

yum install -y freetype freetype-devel

錯誤

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

tar zxvf mcrypt-2.6.8.tar.gz    #提示mcrypt包沒有安裝。安裝mcrypt包 又依賴依賴 libmcrypt,  mhash 這兩個包。

1.首先編譯安裝  libmcrypt,  mhash,  mcrypt  二進制源碼包。

下載libmcrypt-2.5.8.tar.gz


tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

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

make  

make install


安裝 libltdl,也在libmcrypt源碼包裏面

cd libmcrypt-2.5.8 /libltdl

./configure --enable-ltdl-install

make

make install

 

下載mhash-0.9.9.9.tar.gz

tar zxvf mhash-0.9.9.9 

cd mhash-0.9.9.9 

./configrue --prefix

make 

make install


這兩個包安裝完。然後在安裝mcrypt包。


安裝mcrypt

tar zxvf mcrypt-2.6.8.tar.gz

LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/lib ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt   #編譯參數

make 

make install

#mcrypt 沒有安裝完成。這是php模塊。需要等php安裝完成之後。在繼續安裝。




把以上的依賴關係解決完了之後在繼續安裝PHP

./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  --with-mcrypt=/usr/local/libmcrypt/

make

make install


生成php.ini

cp /lamp/php-5.5.9/php.ini-production  /usr/local/php/etc/php.ini


apache結合php

Apache的主配置文件爲 :/usr/local/apache2/etc/httpd.conf   #參數編譯的時候指定到/usr/local/apache2/etc/ 這個目錄下。


vim /usr/local/apache2/etc/httpd.conf

找到AddType application/x-gzip .gz .tgz 這一行在下面增加

AddType application/x-httpd-php .php


找到:<IfModule dir_module>

    DirectoryIndex index.html

</IfModule>

將中間一樣的內容改爲:DirectoryIndex index.html index.htm index.php

修改完成後保存退出。

啓動前檢測apache的配置文件是否正常。

/usr/local/apache2/bin/apachectl -t  

如果顯示“Syntax OK” 表示正常。


啓動apache

/usr/local/apache2/bin/apachectl start


檢測是否啓動成功。

netstart -lnp |grep httpd





LAMP相關小知識。

/usr/local/apache2/bin/apachectl  graceful   加載apache配置文件   不用重啓


/usr/local/apache2/bin/apachectl  -t  查看php配置文件是否正常


/usr/local/php/bin/php -i |more  能查看php安裝信息。。./configure 內容 等等


cat /usr/local/apache2/build/config.nice   查看apache 安裝的編譯代碼


cat /usr/local/mysql/bin/mysqlbug |grep -i confi     參看musql安裝的編譯參數


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章