Apache安裝
到Apache官網(wǎng)下載httpd軟件包。網(wǎng)址:http://httpd.apache.org/
先解壓下載到本地的httpd包
[root@info lamp]# tar -zxvf httpd-2.2.17.tar.gz
[root@info lamp]# cd httpd-2.2.17
完成httpd包解壓后,我們繼續(xù)對(duì)httpd進(jìn)行編譯安裝,--enable-module=so:加載modules動(dòng)態(tài)模塊。
[root@info httpd-2.2.17]# ./configure --prefix=/usr/local/apache --enable-module=so
[root@info httpd-2.2.17]# make
[root@info httpd-2.2.17]# make install
編譯安裝完成后我們可以啟動(dòng)httpd服務(wù)了,現(xiàn)在來(lái)測(cè)試一下。
[root@info httpd-2.0.64]# /usr/local/aparche/bin/apachectl start
It works!
PHP5安裝
到PHP官網(wǎng)下載PHP軟件包。網(wǎng)址:http://www.php.net/
解壓下載到本地的php包
[root@info lamp]# tar -zxvf php-5.2.14.tar.gz
[root@info lamp]# cd php-5.2.14
完成PHP包解壓后,我們繼續(xù)對(duì)PHP進(jìn)行編譯安裝。
[root@info php-5.2.14]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql/
[root@info php-5.2.14]#make
[root@info php-5.2.14]#make test
[root@info php-5.2.14]#make install
編譯安裝完后需對(duì)/usr/local/aparche/conf/httpd.conf進(jìn)行配置。
[root@info php-5.2.14]# cp php.ini-development /usr/local/php/lib/php.ini
[root@info php-5.2.14]# vi /usr/local/aparche/conf/httpd.conf
#加入以下參數(shù)信息:
AddType application/x-httpd-php .php
LoadModule php5_module modules/libphp5.so
找到DirectoryIndex index.html index.html.var,在后面加上index.php 讓它把index.php做為默認(rèn)頁(yè)。
將DocumentRoot "/usr/local/aparche/htdocs"web站點(diǎn)文件存放路徑改成你所在的Web站點(diǎn)路徑。
完成后重啟Apache服務(wù)
[root@info php-5.2.14]# /usr/local/apache/bin/apachectl restart
[root@info php-5.2.14]# netstat -nat|grep 80
tcp 0 0 :::80 :::* LISTEN
然后在你所在的站點(diǎn)下創(chuàng)建一個(gè)php文件,來(lái)測(cè)試PHP是否安裝成功。
我這邊創(chuàng)建了一個(gè)簡(jiǎn)單的php文件,用于顯示PHP配置信息,內(nèi)容
#cat /usr/loca/apach/htdocs/info.php
<?
phpinfo ();
?>
#
MySQL安裝
到mysql官網(wǎng)下載mysql軟件包。網(wǎng)址:http://www.mysql.com/
解壓下載到本地的php包
[root@info lamp]# tar -zxvf mysql-5.1.52.tar.gz
[root@info lamp]# cd mysql-5.1.52
對(duì)mysql進(jìn)行編譯安裝
[root@info mysql-5.1.52]# mkdir /usr/local/mysql
[root@info mysql-5.1.52]# ./configure --prefix=/usr/local/mysql
[root@info mysql-5.1.52]# make
[root@info mysql-5.1.52]# make install
[root@info mysql-5.1.52]# cp support-files/my-medium.cnf /etc/my.cfg
編譯安裝完成后對(duì)mysql目錄進(jìn)行權(quán)限分配,讓其它用戶無(wú)法訪問(wèn)mysql目錄
[root@info mysql-5.1.52]# cd /usr/local/
[root@info local]# chgrp -R mysql mysql
[root@info local]# chown -R mysql mysql
[root@info local]# chown -R 711 mysql
[root@info local]# ls -l mysql
總用量 32
drwxr--x--x 2 mysql mysql 4096 11月 13 13:09 bin
drwxr--x--x 2 mysql mysql 4096 11月 13 13:09 docs
drwxr--x--x 3 mysql mysql 4096 11月 13 13:09 include
drwxr--x--x 3 mysql mysql 4096 11月 13 13:09 lib
drwxr--x--x 2 mysql mysql 4096 11月 13 13:10 libexec
drwxr--x--x 10 mysql mysql 4096 11月 13 13:10 mysql-test
drwxr--x--x 5 mysql mysql 4096 11月 13 13:10 share
drwxr--x--x 5 mysql mysql 4096 11月 13 13:10 sql-bench
初始化mysql授權(quán)表
[root@info local]# su - mysql
[mysql@info ~]$ /usr/local/mysql/bin/mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password new-password
/usr/local/mysql/bin/mysqladmin -u root -h info password new-password
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/mysql/bin/mysqlbug script!
后臺(tái)啟動(dòng)mysql服務(wù)
[mysql@info ~]$ /usr/local/mysql/bin/mysqld_safe &
[1] 29209
[mysql@info ~]$ 101113 13:22:05 mysqld_safe Logging to /usr/local/mysql/var/info.err.
101113 13:22:05 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
[mysql@info ~]$ ps -ef|grep mysql
root 29157 28951 0 13:21 pts/1 00:00:00 su - mysql
mysql 29158 29157 0 13:21 pts/1 00:00:00 -bash
mysql 29209 29158 0 13:22 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe
mysql 29255 29209 0 13:22 pts/1 00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --log-error=/usr/local/mysql/var/info.err --pid-file=/usr/local/mysql/var/info.pid
mysql 29258 29158 0 13:22 pts/1 00:00:00 ps -ef
mysql 29259 29158 0 13:22 pts/1 00:00:00 grep mysql
[mysql@info ~]$ /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.52 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type help; or \h for help. Type \c to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)
現(xiàn)在我們?cè)跒g覽器中重新加載http://192.168.1.90/info.php頁(yè)面,查看模塊部分,發(fā)現(xiàn)MySQL模塊已經(jīng)被加載,這表明我們已成功安裝了MySQL。
到此php整個(gè)環(huán)境基本搭建好了,希望對(duì)正在了解和學(xué)習(xí)有關(guān)這方面技術(shù)的朋友有所幫助。