lamp網站平台(編譯安裝)
什麼是 lamp:
目前最為成熟的一種企業網站應用模式,可提供動态web站點應用及開發環境
構成元件:
linux、apache、mysql、php/perl/python
安裝環境:
需要開發工具和開發庫支援
---------------------------
l apache編譯安裝與啟動
[root@localhost tom]# tar xzvf httpd-2.2.9.tar.gz -c /usr/src/
[root@localhost tom]# cp httpd.configure.sh /usr/src/httpd-2.2.9/
[root@localhost tom]# cd /usr/src/httpd-2.2.9/
[root@localhost httpd-2.2.9]#
[root@localhost httpd-2.2.9]# vim httpd.configure.sh // 配置編譯選項的腳本檔案内容
#!/bin/bash
./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite \
--enable-ssl --with-ssl=/usr/lib --enable-auth-digest --enable-cgi \
--enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/apache2/htdocs
// 配置含義:
--enable-ssl:開啟ssl
--enable-auth-digest:apache有兩種認證:基本和摘要,這裡選擇摘要認證
--enable-cgi:啟用 cgi功能
--enable-suexec:啟用 suexec,postfix要用到
[root@localhost httpd-2.2.9]# chmod a+x httpd.configure.sh // 增加可執行權限
[root@localhost httpd-2.2.9]# ./httpd.configure.sh //使用腳本進行編譯前的配置
[root@localhost httpd-2.2.9]# make
[root@localhost httpd-2.2.9]# make install
[root@localhost httpd-2.2.9]#
[root@localhost ~]# /usr/local/apache2/bin/apachectl start //啟動服務
[root@localhost ~]#
搭建成功後通路 http://192.168.1.2
内容顯示為: it works!
----------------------------
使用service指令啟動、停止服務
[root@localhost ~]# cp /usr/local/apache2/bin/apachectl /etc/init.d/newhttpd
[root@localhost ~]# service newhttpd restart
使用chkconfig工具設定自動啟動
[root@localhost ~]# chkconfig --add newhttpd
newhttpd 服務不支援 chkconfig // 預設不支援chkconfig工具
[root@localhost ~]# vim /etc/init.d/newhttpd //在第2行插chkconfig參數設定
#!/bin/sh
# chkconfig: 35 85 15
# description: new http server daemon
[root@localhost ~]# chkconfig newhttpd on
[root@localhost ~]# chkconfig --list newhttpd
newhttpd 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉
------------------------
mysql編譯安裝與啟動
建立使用者:
[root@localhost ~]# useradd -m -s /sbin/nologin mysql
解壓釋放源代碼包到/usr/src目錄:
[root@localhost tom]# tar xzvf mysql-5.0.56.tar.gz -c /usr/src/
[root@localhost tom]# cd /usr/src/mysql-5.0.56/
[root@localhost mysql-5.0.56]#
配置編譯選項:
[root@localhost mysql-5.0.56]# ./configure --prefix=/usr/local/mysql
[root@localhost mysql-5.0.56]# make
[root@localhost mysql-5.0.56]# make install
建立配置檔案:
[root@localhost mysql-5.0.56]# cp support-files/my-medium.cnf /etc/my.cnf
初始化資料庫:
[root@localhost mysql-5.0.56]# /usr/local/mysql/bin/mysql_install_db --user=mysql
[root@localhost mysql-5.0.56]# chown -r root.mysql /usr/local/mysql/
[root@localhost mysql-5.0.56]# chown -r mysql /usr/local/mysql/var/
調整lib 庫路徑
[root@localhost mysql-5.0.56]# echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf // 這個隻是臨時調整,如果需要請自己寫入配置檔案中
[root@localhost mysql-5.0.56]# ldconfig
将 mysqld添加為系統服務:
[root@localhost mysql-5.0.56]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.0.56]# chmod +x /etc/init.d/mysqld
[root@localhost mysql-5.0.56]# chkconfig --add mysqld
[root@localhost mysql-5.0.56]# chkconfig mysqld on
[root@localhost mysql-5.0.56]# service mysqld restart
設定mysql程式的執行路徑:
[root@localhost mysql-5.0.56]# export path=$path:/usr/local/mysql/bin
[root@localhost mysql-5.0.56]# echo "path=$path:/usr/local/mysql/bin" >> /etc/profile
--------------------------------
php編譯安裝
[root@localhost tom]# tar xjvf php-5.2.6.tar.bz2 -c /usr/src/
[root@localhost tom]# cp php.configure.sh /usr/src/php-5.2.6/
[root@localhost tom]#
[root@localhost tom]# cd /usr/src/php-5.2.6/
[root@localhost php-5.2.6]# vim php.configure.sh // 配置編譯選項的腳本檔案内容
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql --enable-sockets --enable-mbstring
[root@localhost php-5.2.6]# chmod a+x php.configure.sh //增加可執行權限
[root@localhost php-5.2.6]# ./php.configure.sh //使用腳本進行編譯前的配置
[root@localhost php-5.2.6]# make
[root@localhost php-5.2.6]# make install
[root@localhost php-5.2.6]#
複制php.ini配置檔案:
[root@localhost php-5.2.6]# cp php.ini-dist /usr/local/php5/php.ini
修改httpd.conf配置檔案支援php類型的網頁:
[root@localhost php-5.2.6]# vim /usr/local/apache2/conf/httpd.conf
......
53 loadmodule php5_module modules/libphp5.so // 确認有這一行
......
167 directoryindex index.php index.html // 修改這一行,首頁檔案
310 addtype application/x-httpd-php .php // 增加這一行,支援 php檔案識别
測試php運作環境:
[root@localhost ~]# vim /usr/local/apache2/htdocs/index.php // 測試 php網頁
<?php
phpinfo();
?>
[root@localhost ~]# vim /usr/local/apache2/htdocs/testdb.php // 測試 mysql資料庫
$link=mysql_connect('localhost','test','');
if(!$link) echo "fail !!";
else echo "success !!";
mysql_close();
客戶機通路測試
通路http://192.168.1.2 應該能看到php的測試頁面
http://192.168.1.2/testdb.php 如果出現 success! 表示資料庫連接配接ok