CentOS LAMP做爲服務器,不安裝不須要的組件,因此在選擇組件的時候,不要選web服務器,由於咱們後面要手動編譯安裝。CentOS LAMP系統約定RPM包和源碼包存放位置:php
- RPM包和源碼包存放位置 /usr/local/src
- 源碼包編譯安裝位置(prefix) /usr/local/XXX
- MySQL 數據庫位置 /usr/local/mysql/var
- 網站根目錄 /usr/local/apache/htdocs
CentOS LAMP環境搭建html
搭建的工做包括APACHE、MYSQL、PHP。能夠按照這個順序來搭建環境。mysql
一、獲取軟件包linux
- Httpd: http://www.apache.org/dist/httpd/httpd-2.2.11.tar.gz
- mysql: http://mirror.provenscaling.com/mysql/enterprise/source/5.0/mysql-5.0.70.tar.gz
- php: http://museum.php.net/php5/php-5.2.2.tar.gz
把它們所有放到 /usr/local/src 下面.>cd /usr/local/src (定位到安裝包目錄)web
二、安裝 mysql sql
- >tar -zxvf mysql-5.0.70.tar.gz
- >cd mysql-5.0.70
- >./configure --prefix=/usr/local/mysql
- >make
- >make install
- >useradd mysql //添加 mysql 用戶
- >cd /usr/local/mysql
- >bin/mysql_install_db --user=mysql
- >chown -R mysql . //設置權限,注意後面有一個點 "."
- >chgrp -R mysql .
- >chown -R mysql var
- >cp share/mysql/my-medium.cnf /etc/my.cnf
- >cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld //開機啓動
- >chmod 755 /etc/rc.d/init.d/mysqld
- >chkconfig --add mysqld
運行了上面第8步後:數據庫
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 centos5 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 mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/mysql/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.comapache
運行如下命令便可啓動 MySQL 服務器:>/etc/rc.d/init.d/mysqld start //啓動 MySQL(mysql安裝完畢)centos
三、安裝Apache瀏覽器
- >tar -zxvf httpd-2.2.11.tar.gz
- >cd httpd-2.2.11
- >./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite --enable-shared=max
- >make
- >make install
運行上面第3步時,出現下面的問題:
[root@centos5 httpd-2.3.8]# ./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite --enable-shared=max
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
Configuring Apache Portable Runtime library ...
checking for APR... no
configure: error: APR not found. Please read the documentation.
到http://apr.apache.org/download.cgi下載 apr-1.4.2.tar.gz。
解壓後進入解壓目錄,進行以下操做:
./configure --prefix=/desired/path/of/apr
make
make test
make install
啓動apache服務 >/usr/local/apache/bin/apachectl -k start用瀏覽器打開 http://127.0.0.1/ 若是能夠訪問則說明apache安裝成功。
四、安裝PHP
>tar -zxvf php-5.2.2.tar.gz
>cd php-5.2.2
>./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs
>make
>make install
>cp php.ini-dist /usr/local/php/lib/php.ini
>vi /usr/local/php/lib/php.ini
五、CentOS LAMP配置httpd
.conf >vi /usr/local/apache/conf/httpd.conf找到"AddType application/x-gzip .tgz"在它的下面添加AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps找到"DirectoryIndex index.html在index.html 前添加 index.php
啓動apache服務>/usr/local/apache/bin/apachectl -k start將apache設置成開機自啓動:在/etc/rc.d/rc.local文件中加入一行並保存: /usr/local/apache /bin/apachectl start (apache+php配置完畢)
六、查看確認 L.A.M.P 環境信息:>vi /usr/local/apache/htdocs/phpinfo.php新增長下面一行,並保存。 <?php phpinfo(); ?>>chmod 755 /usr/local/apache/htdocs/phpinfo.php用瀏覽器打開 http://127.0.0.1/phpinfo.php檢查 phpinfo中的各項信息是否正確。若是能夠訪問則環境搭建成功
測試php與mysql的鏈接
- >vi /usr/local/apache/htdocs/testdb.php增長下面幾行,並保存。
- <?php
- $link=mysql_connect('localhost','root','yourpassword');
- if(!$link) echo "fail";
- else echo "success";
- mysql_close();
- ?>
- >chmod 755 /usr/local/apache/htdocs/testdb.php
- >service mysqld start
用瀏覽器打開 http://127.0.0.1/testdb.php若是輸出success代表php與mysql鏈接成功CentOS LAMP環境搭建完畢