编译安装php(包括链接mysql测试)

#1 安装相关包

#2 下载php

wget http://cn2.php.net/distributions/php-5.4.38.tar.gz
tar zxf php-5.4.38.tar.gz
cd php-5.4.38

#3 编译安装
./configure --prefix=/application/php-5.4.38  --enable-fpm --with-mcrypt --enable-mbstring --disable-pdo --with-curl --disable-debug  --disable-rpath --enable-inline-optimization --with-bz2  --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli --with-gd --with-jpeg-dir

make && make install
#4
ln -s /application/php-5.4.38/ /application/php
cp php.ini-production  /application/php/lib/php.ini
cd /application/php/etc/
cp php-fpm.conf.default  php-fpm.conf

mkdir /app/logs �Cp
/application/php/sbin/php-fpm �Ct
/application/php/sbin/php-fpm
lsof -i :9000

#5 查看扩展
/application/php/bin/php -m

#6 创建web目录
mkdir /data/www -p

#7 测试
/application/php/bin/php test.php


### 在本地装nginx

### 在另一台装mysql并授权
grant all on *.* to 'root'@'192.168.189.%' identified by '123456';
grant all on *.* to 'yeqing'@'192.168.189.%' identified by '123456';
grant all on test.* to 'yeqing'@'192.168.189.%' identified by '123456';
flush privileges;

### 在本地装mysql 去链接mysql服务器
yum install mysql


### 链接mysql
mysql -u root -p -h 192.168.189.131


### 测试链接mysql
<?php
mysql_connect('192.168.189.131', 'yeqing', '123456') or die('11111111111');
mysql_select_db('test') or die('2222222222');
mysql_query("set names utf8");
$sql = "select user,host from mysql.user";
$res = mysql_query($sql);
$data = mysql_fetch_array($res);
echo '<pre />';
print_r($data);
?>

#### 测试链接mysqli
<?php
$link = mysqli_connect('192.168.189.131', 'yeqing', '123456','mysql') or die('11111111111');
$res  = mysqli_query($link,'select user,host from mysql.user');
$data = mysqli_fetch_array($res);
while($row = mysqli_fetch_array($res)){
  echo $row['user'],'-->',$row['host'],"\r\n";
}
?>

#### 测试
/application/php/bin/php test.php

本文出自 “技术�潘�” 博客,转载请与作者联系!

你可能感兴趣的:(PHP,mysql)