apache 数据库 php,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 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

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 [email protected] identified by ‘123‘; ##240为php的IP

#连接mysql的测试页

cd /usr/local/httpd/htdocs

vim mysql.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模块

测试页面

//连接本地的 Redis 服务

$redis = new Redis();

$redis->connect(‘127.0.0.1‘, 6379);

$redis->auth(‘123456‘);

echo "Connection to server sucessfully.";

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值