以紅冒企業版RHEL5爲例,構建LAMP平臺。測試主機192.168.1.1,並準備好相關軟件編譯安裝:httpd-2.2.17.tar.gz、 mysql-5.1.55.tar.gz、libmcrypt-2.5.8.tar.gz、mhash-0.9.9.9.tar.gz、mcrypt-2.6.8.tar.gz、php-5.3.6.tar.gz、phpMyAdmin-3.3.10-all-languages.tar.gz等。
一、搭建httpd。
1編輯IP地址
vim /etc/sysconfig/network-scripts/ifcfg-eth0
2刪除之前rpm包裝的軟件。
rpm -e httpd httpd-manual webalizer subversion mod_python mod_ssl mod_perl system-config-httpd php php-cli php-ldap php-common mysql dovecot --nodeps
3解包httpd到/usr/src/
tar zxf httpd-2.2.17.tar.gz -C /usr/src/
cd /usr/src/httpd-2.2.17/
編譯安裝,
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
make && make install
開啓服務
/usr/local/httpd/bin/apachectl start
二、搭建mysql
解壓mysql到/usr/src/,如果之前用rpm包裝過,一定要清除
tar zxf mysql-5.1.55.tar.gz -C /usr/src/
cd /usr/src/mysql-5.1.55/
編譯安裝mysql
./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312 && make && make install
建立配置文件
cp support-files/my-medium.cnf /etc/my.cnf
初始化數據庫
cd /usr/local/mysql/bin/
./mysql_install_db --user=mysql
chown -R root.mysql /usr/local/mysql/
chown -R mysql /usr/local/mysql/var/
優化執行路徑、程序路徑
ln -s /usr/local/mysql/bin/* /usr/local/bin/
ln -s /usr/local/mysql/lib/mysql/* /usr/bin/
ln -s /usr/local/mysql/include/mysql/* /usr/include/
添加系統服務
cd /usr/src/mysql-5.1.55/
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod a+x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
開啓mysql服務並添加用戶密碼
/etc/init.d/mysqld start
mysqladmin -u root password '123456'
三、搭建PHP
1刪除之前rpm包裝的php
rpm –e php php-cli php-ldap php-common php-mysql –nodeps
2 安裝擴展工具庫
Libmcrypt:
tar zxf libmcrypt-2.5.8.tar.gz -C /usr/src/
cd /usr/src/libmcrypt-2.5.8/
./configure && make && make install
ln -s /usr/local/lib/libmcrypt.* /usr/lib/
mhash:
tar zxf mhash-0.9.9.9.tar.gz -C /usr/src/
cd /usr/src/mhash-0.9.9.9/
./configure && make && make install
ln -s /usr/local/lib/libmhash.* /usr/lib/
mcrypt:
tar zxf mcrypt-2.6.8.tar.gz -C /usr/src/
cd /usr/src/mcrypt-2.6.8/
./configure && make && make install
3安裝php
tar zxf php-5.3.6.tar.gz -C /usr/src/
cd /usr/src/php-5.3.6/
./configure --prefix=/usr/local/php5 --with-mcrypt --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql/ --with-config-file-path=/usr/local/php5 --enable-mbstring && make && make install
4php.ini配置調整,一般複製即可,不用修改
cp /usr/src/php-5.3.6/php.ini-development /usr/local/php5/php.ini
5配置http.conf
vim /usr/local/httpd/conf/httpd.conf
(在LoadModule php5_module modules/libphp5.so添加AddType application/x-httpd-php .php
)
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
(還要在DirectoryIndex添加index.php)
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
重啓httpd服務
/usr/local/httpd/bin/apachectl restart
6測試PHP頁面
vim /usr/local/httpd/htdocs/test.php
<?php
$link=mysql_connect('localhost','root','123456');
if($link) echo " success!!!!";
mysql_close();
phpinfo();
?>
7部署phpMyAdmin系統
tar zxf phpMyAdmin-3.3.10-all-languages.tar.gz
mv phpMyAdmin-3.3.10-all-languages phpmyadmin
(更改名字,否則在瀏覽器上打名字挺煩的)
mv phpmyadmin /usr/local/httpd/htdocs/phpmyadmin
(複製到存放網頁的目錄)
若在頁面中測試,見如下圖,則說明鏈接數據庫成功以及phpadmin部署成功!!