天天看點

Linux 下源碼搭建LAMP環境

Step0:準備工作

①将需要的所有軟體包分類傳到/root/目錄下.

<a href="http://blog.51cto.com/attachment/201308/110202493.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110202670.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110202446.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110203993.png" target="_blank"></a>

②将所有的源碼包進行解壓縮到指定的路徑(/usr/local/src)除了phpmyadmin

tar zxvf apr-1.4.5.tar.gz -C /usr/local/src/

tar zxvf apr-util-1.3.12.tar.gz  -C /usr/local/src/

tar jxvf httpd-2.4.4.tar.bz2  -C /usr/local/src/

tar zxvf cmake-2.8.10.2-Linux-i386.tar.gz  -C /usr/local/src/

tar zxvf mysql-5.6.10.tar.gz  -C /usr/local/src/

tar jxvf php-5.4.14.tar.bz2  -C /usr/local/src/

unzip phpMyAdmin-3.5.8-all-languages.zip 

mv  phpMyAdmin-3.5.8-all-languages  phpmyadmin

cd  /usr/local/src/ 

見下圖

<a href="http://blog.51cto.com/attachment/201308/110203202.png" target="_blank"></a>

Step1:源碼編譯Apache

Apache編譯需要apr和apr-util的支援,是以需要預先編譯這兩個源碼.

說明:APR(Apache portable Run-time libraries)Apache可移植運作庫,主要為上層的應用程式提供可以跨越多作業系統平台使用的底層支援接口庫。APR開發項目實際上包含了三個開發包:apr、apr-util、apr-iconv,給一個開發包分别獨立開發,并分别由自己的版本。

①cd /apr-1.4.5

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

  (指定apr安裝目錄,更多參數參見./configure --help)

   make &amp;&amp; make install 

②cd /apr-util-1.3.12

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

--with-apr=/usr/apr/bin/apr-1-config

(指定apr-util的安裝目錄以及apr的配置檔案的路徑)

  更多參數詳見  ./configure --help 

  make &amp;&amp; make install 

③cd /httpd-2.4.4

./configure  

   --prefix=/usr/local/apache (指定Apache的安裝目錄)

   --sysconfdir=/etc/httpd  (指定Apache服務的配置腳本目錄)  

   --enable-so  (啟用Apache的DSO動态共享對象功能)

   --enable-ssl (啟用Apache的SSL/TLS功能)

   --enable-rewrite (啟用位址重寫功能)

   --with-apr=/usr/local/apr/bin/apr-1-config (apr配置腳本目錄)     

   --with-apr-util=/usr/local/apr/bin/apu-1-config (apu配置目錄)

   --with-pcre (擴充的PCRE庫) 

   注:需要安裝pcre包 (yum install pcre*)

   --with-z (啟用壓縮庫)

   --enable-mpms-shared=all(自動選擇MPM類型)

   make  &amp;&amp; make install  

④編輯/etc/man.config檔案,将Apache源碼的man路徑加入到配置中。 

<a href="http://blog.51cto.com/attachment/201308/110203458.png" target="_blank"></a>

⑤軟連接配接将Apache源碼的include/目錄下的頭檔案加入到系統路徑中。

 ln -s /usr/local/apache/include/   /usr/include/apache 

⑥自編寫bash腳本,來完成Apache服務的start、stop、restart等操作,并且能接受chkconfig的管理。

  vim  httpd  

<a href="http://blog.51cto.com/attachment/201308/110204744.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110205681.png" target="_blank"></a>

mv  httpd  /etc/init.d/ 

  chmod  a+x  /etc/init.d/httpd 

⑦啟動Apache服務,并觀察端口狀态。

  service httpd  start 

  chkconfig httpd on 

  chkconfig --list | grep httpd 

<a href="http://blog.51cto.com/attachment/201308/110205289.png" target="_blank"></a>

netstat -tupln | grep 80 

<a href="http://blog.51cto.com/attachment/201308/110205899.png" target="_blank"></a>

Step2:源碼編譯MySQL

①源碼安裝編譯MySQL需要的cmake工具。

  mv /usr/local/src/cmake-2.8.10.2-Linux-i386  /usr/local/cmake

  編輯/etc/profile檔案,把cmake的bin路徑加入到系統路徑中。

<a href="http://blog.51cto.com/attachment/201308/110205635.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110205841.png" target="_blank"></a>

②編譯MySQL.

  cd  /usr/local/src/mysql-5.6.10/

  cmake . 

  make  &amp;&amp; make install (估計20分鐘左右)

③建立mysql組和mysql賬号(系統服務賬号),修改mysql目錄的權限。

  useradd  -r  -g  mysql  mysql 

  cd /usr/local/mysql 

  chown  -R  mysql  .

  chgrp  -R  mysql  .

<a href="http://blog.51cto.com/attachment/201308/110206552.png" target="_blank"></a>

 以mysql的身份初始化MySQL資料庫。

  scripts/mysql_install_db --user=mysql

  把mysql目錄的所有者權限改回root,除了data/目錄。

  chown -R root .

  chgrp -R mysql data/

<a href="http://blog.51cto.com/attachment/201308/110206536.png" target="_blank"></a>

④拷貝樣例配置檔案,形成MySQL的主配置檔案。

  cp /usr/local/mysql/support-files/my-default.cnf  /etc/my.cnf

  cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld

⑤ 啟動MySQL服務,并觀察端口狀态.

  service mysqld start

  netstat  -tupln | grep 3306

<a href="http://blog.51cto.com/attachment/201308/110206194.png" target="_blank"></a>

⑥編輯/etc/profile檔案,将MySQL源碼的bin路徑加入到環境變量中。

<a href="http://blog.51cto.com/attachment/201308/110207127.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110207757.png" target="_blank"></a>

⑦編輯/etc/ld.so.conf.d/mysql.conf檔案,将MySQL源碼的lib路徑加入系系統庫中。

<a href="http://blog.51cto.com/attachment/201308/110207855.png" target="_blank"></a>

ldconfig重新整理庫lib動态連結庫。

檢視有沒有加載成功。

<a href="http://blog.51cto.com/attachment/201308/110207994.png" target="_blank"></a>

⑧軟連接配接将MySQL源碼的include/目錄下的頭檔案加入到系統路徑中。

  ln -s /usr/local/mysql/include/   /usr/include/mysql

Step3:源碼編譯PHP

①cd /usr/local/src/php-5.4.14/

./configure  --prefix=/usr/local/php(指定安裝目錄)

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

(将php編譯成apache的子產品,允許apache的apxx調用該子產品)

  --with-mysql=/usr/local/mysql (指明mysql的安裝位置) 

  --with-mysqli=/usr/local/mysql/bin/mysql_config(調用myql接口)

  -enable-mbstring=all(指定字元集)

  --with-xml

  --with-png  --with-jpeg  --with-gd  --with-zlib --with-freetype

  xml|png|zlib|jpeg|freetype是apache的一些繪圖功能

  make &amp;&amp; make install  

②編輯/etc/profile檔案,将PHP源碼的bin路徑加入到環境變量中。

<a href="http://blog.51cto.com/attachment/201308/110207245.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110208189.png" target="_blank"></a>

③編輯/etc/ld.so.conf.d/php.conf檔案,将PHP源碼的lib路徑加入到系統庫中。

<a href="http://blog.51cto.com/attachment/201308/110208258.png" target="_blank"></a>

④軟連接配接将PHP源碼的include/目錄下的頭檔案加入到系統路徑中。

  ln -s /usr/local/php/include/   /usr/include/php

⑤編輯Apache的配置檔案,添加支援PHP的一些子產品處理功能。

<a href="http://blog.51cto.com/attachment/201308/110208368.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110208544.png" target="_blank"></a>

⑥service httpd restart

①cp -r /root/PHP/phpmyadmin/   /usr/local/apache/htdocs/

②cd  /usr/local/apache/htdocs/phpmyadmin

③cp -p config.sample.inc.php  config.inc.php

④修改MySQL資料庫的root管理者密碼

  mysqladmin  -u  root  -p  password ‘123456’

  Enter password:(原密碼為空----回車)

【環境測試】

浏覽器輸入基于實體目錄的位址來Web管理MySQL資料庫.

<a href="http://apacheserverip/phpmyadmin">http://ApacheServerIP/phpmyadmin</a>

 (賬号:root;密碼:123456)

<a href="http://blog.51cto.com/attachment/201308/110209500.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110210622.png" target="_blank"></a>

END ! ! ! 

     本文轉自Tar0 51CTO部落格,原文連結:http://blog.51cto.com/tar0cissp/1282655,如需轉載請自行聯系原作者