码迷,mamicode.com
首页 > 数据库 > 详细

apache+php连接数据库

时间:2019-03-02 23:45:36      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:bsp   参数   grep   mysq   serve   dump   type   路径   rip   

######## 安装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 install

#安装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 install

 

#安装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来了解各参数含义


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

yum remove httpd* -y

# 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 httpd

#启动文件
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 restart


#查看所有模块
ls /usr/local/httpd/modules/

#查看加载模块
apachectl -t -D DUMP_MODULES

######### 安装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 install

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();
?>

 

apache+php连接数据库

标签:bsp   参数   grep   mysq   serve   dump   type   路径   rip   

原文地址:https://www.cnblogs.com/Stephen-blog/p/10463486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!