安裝環境:php
系統:CentOS release 6.2 (Final)html
Mysql: mysql-5.1.62.tar.gz mysql
http:httpd-2.2.25.tar.gzc++
php: php-5.4.19.tar.gzsql
前期準備:先將須要的軟件包拖到虛擬服務器root上,以下圖數據庫
[root@localhost ~]# unzip LAMP.zipapache
[root@localhost ~]# yum -y install openssl-devel ncurses-devel libtermcap-devel libxml2-devel gcc gcc-c++vim
[root@localhost ~]# yum -y remove httpd mysql-server mysql php-mysql瀏覽器
1. 安裝 httpd源碼包bash
[root@localhost ~]# tar -zxvf httpd-2.2.25.tar.gz
[root@localhost ~]# cd httpd-2.2.25
[root@localhost httpd-2.2.25]#./configure --prefix=/usr/local/httpd \
--enable-so --enable-rewrite --enable-cgi \
--enable-charset-lite --enable-ssl \
--enable-suexec --with-suexec-caller=daemon \
--with-suexec-docroot=/usr/local/httpd/htdocs
[root@localhost httpd-2.2.25]# make && make intsall
創建 httpd 控制腳本,添加啓動參數
[root@localhost httpd-2.2.25]# cp -f /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[root@localhost httpd-2.2.25]# vim /etc/init.d/httpd
#!/bin/bash
# chkconfig: 35 85 15
# description: Apache is a World Wide Web Server
......
[root@localhost httpd-2.2.25]# chmod +x /etc/init.d/httpd
[root@localhost httpd-2.2.25]# chkconfig --add httpd
2. 安裝 mysql源碼包
準備mysql運行帳戶(不建立家目錄 uid爲49 不能登陸),安裝
[root@localhost httpd-2.2.25]# useradd -M -u 49 -s /sbin/nologin mysql
[root@localhost httpd-2.2.25]# cd /root
[root@localhost]# tar -zxvf mysql-5.1.62.tar.gz
[root@localhost]# cd /mysql-5.1.62/
[root@localhost mysql-5.1.62]# ./configure --prefix=/usr/local/mysql \
--with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charset=gbk,gb2312
[root@localhost mysql-5.1.62]# make && make install
調整目錄權限,創建mysql配置文件
[root@localhost mysql-5.1.62]#chown -R root:mysql /usr/local/mysql/
[root@localhost mysql-5.1.62]#chown -R mysql /usr/local/mysql/var/#若無此目錄需自行建立mkdir
[root@localhost mysql-5.1.62]#cp -f /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
[root@localhost mysql-5.1.62]# vim /etc/my.cnf
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer_size = 16M
......
添加庫連接,創建 mysqld控制腳本,添加啓動參數
[root@localhost mysql-5.1.62]# ln -sf /usr/local/mysql/bin/* /usr/local/bin/
[root@localhost mysql-5.1.62]# cat /etc/ld.so.conf.d/mysql-64.conf
/usr/local/mysql/lib/mysql
[root@localhost mysql-5.1.62]# ldconfig
[root@localhost mysql-5.1.62]#cp -f /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.1.62]#chmod +x /etc/init.d/mysqld
[root@localhost mysql-5.1.62]#chkconfig --add mysqld
[root@localhost mysql-5.1.62]# /usr/local/mysql/bin/mysql_install_db --user=mysql
3. 編譯安裝 php
[root@localhost mysql-5.1.62]# cd /root/
[root@localhost ~]# tar -zxvf php-5.4.19.tar.gz
[root@localhost ~]#cd php-5.4.19
[root@localhost php-5.4.19]# ./configure --prefix=/usr/local/php \
--enable-mbstring --enable-sockets \
--with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql \
--with-config-file-path=/usr/local/php
[root@localhost php-5.4.19]# make && make install
啓用httpd的PHP網頁支持
[root@localhost php-5.4.19]# vim /usr/local/httpd/conf/httpd.conf
......
54 LoadModule php5_module modules/libphp5.so
......
99 ServerName localhost:80
......
167 <IfModule dir_module>
168 DirectoryIndex index.html index.php
169 </IfModule>
......
309 AddType application/x-compress .Z
310 AddType application/x-gzip .gz .tgz
311 AddType application/x-httpd-php .php
......
啓動mysql 和httpd
[root@localhost php-5.4.19]# service mysqld restart
[root@localhost php-5.4.19]# service httpd restart
修改mysql密碼,建立mysql數據庫
[root@localhost php-5.4.19]# mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost'=PASSWORD('123456');
mysql> CREATE DATABASE bbsdb;
mysql> GRANT all ON bbsdb.* TO runbbs@localhost IDENTIFIED BY 'admin123';
mysql> quit;
4. 建立測試網頁,測試訪問結果
1. 確保能正確解析 PHP 網頁
[root@localhost php-5.4.19]# vim /usr/local/httpd/htdocs/test1.php
<?php
phpinfo();
?>
—— 從瀏覽器訪問 http://服務器地址/test1.php
2. 確保PHP網頁可訪問 MySQL 數據庫
[root@localhost php-5.4.19]# vim /usr/local/httpd/htdocs/test2.php
<?php
$link=mysql_connect('localhost','root','123456');
if($link) echo "Success !!"; //成功則顯示Success !!
else echo "Failure !!"; //失敗則顯示Failure !!
mysql_close(); //關閉數據庫鏈接
?>
—— 從瀏覽器訪問 http://服務器地址/test2.php