编译安装php(包括链接mysql测试)
php安装顺序:先安装apache 再安装php
cd ../php-NN
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
make
make install
参照手册:http://php.net/manual/zh/install.unix.apache2.php
#1 安装相关包
yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel
zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel
krb5 krb5-devel libidn libidn-devel openssl openssl-devel
#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-jpeg-dir –with-png-dir –with-freetype-dir –with-gd
--with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
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 –p
/application/php/sbin/php-fpm –t
/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
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 ‘
’;
print_r($data);
?>
#### 测试链接mysqli
$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
本文转自cloves 51CTO博客,原文链接:http://blog.51cto.com/yeqing/1627798