apache+php鏈接數據庫

######## 安裝APACHE #############
#安裝apr
/usr/src/apache+php/
tar xf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr
make && make installphp

#安裝apr-util
cd ..
tar xf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
make && make installhtml

 

#安裝httpd
cd ..
yum install pcre-devel zlib-devel openssl-devel -y
tar xf httpd-2.4.25.tar.gz
cd httpd-2.4.25
./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-so --enable-deflate --enable-expires --enable-headers --enable-ssl --enable-rewrite --enable-mpms-shared=all --with-mpm=prefork --enable-mods-shared=most
make && make install
#可經過./configure --help或結合http://httpd.apache.org/docs/2.4/progms/configure.html來了解各參數含義mysql


# vim /etc/profile 或者 vim ~/.bash_profile
echo 'export PATH=/usr/local/httpd/bin:$PATH' >> /etc/profile
. /etc/profileredis

yum remove httpd* -ysql

# vi /usr/local/httpd/conf/httpd.conf
sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/g' /usr/local/httpd/conf/httpd.conf
apachectl start
netstat -antp | grep httpdapache

#啓動文件
ln -s /usr/local/httpd/bin/apachectl /etc/init.d/httpd
echo -e "
# chkconfig: - 85 15\n# description: The Apache HTTP Server" >> /etc/init.d/httpd
chkconfig --add httpd
systemctl enable httpd
/etc/init.d/httpd restartvim


#查看全部模塊
ls /usr/local/httpd/modules/bash

#查看加載模塊
apachectl -t -D DUMP_MODULESapp

######### 安裝PHP ############
#安裝php:
yum install libxml2 libxml2-devel -y
tar xf php-5.6.30.tar.gz
cd php-5.6.30
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/bin/apxs
make && make installide

vi /usr/local/httpd/conf/httpd.conf
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

/etc/init.d/httpd restart

#測試:
vim /usr/local/httpd/htdocs/index.php
<?php
phpinfo();
?>

 

#php安裝mysql模塊:
yum -y install mysql-devel autoconf
ln -s /usr/lib64/mysql /usr/lib/mysql ----64位系統
cd /usr/src/apache+php/php-5.6.30/ext/mysql
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-mysql=/usr
make && make install

讓php加載安裝好的外部模塊:
cp php解壓縮路徑/php.ini-production /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226"
extension = "mysql.so"
/etc/init.d/httpd restart


#安裝配置mysql(此處安裝的是rpm):
yum install mysql-server -y
mysql
mysql> grant all on *.* to root@192.168.18.240 identified by '123'; ##240爲php的IP


#鏈接mysql的測試頁
cd /usr/local/httpd/htdocs
vim mysql.php
<?php

$conn = mysql_connect('192.168.18.241','root','123');

if (!$conn)
{

die('Could not connect: ' . mysql_error());
}

else
{
echo "Connect Successfully!";
}

?>

 


#安裝PHP的redis.so:
yum install -y autoconf
cd /tmp/phpredis-3.1.1RC1
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

#安裝驗證
ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/redis.so

#配置PHP 加載redis客戶端
cp php-5.6.30/php.ini-production /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226"
extension = redis.so


# 在redis中設置bind參數-->重啓redis
bind 127.0.0.1 192.168.18.134(本機ip)


#經過網頁phpinfo.php或者 /usr/local/php/bin/php -m 驗證是否正確加載了redis模塊
測試頁面
<?php
//鏈接本地的 Redis 服務
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

$redis->auth('123456');

echo "Connection to server sucessfully.</br>";

//查看服務是否運行echo "Server is running: " . $redis->ping();?>

相關文章
相關標籤/搜索