1.yum安装
yum install php php-fpm php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash php-mysql php-xml
启动php服务命令: /etc/init.d/php-fpm start
2.下载编译安装php 5.3.6:
yum install libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel libtool-ltdl-devel tar -jxvf php-5.3.6.tar.bz2 cd php-5.3.6 ./configure --prefix=/opt/php -with-apxs2=/opt/httpd/bin/apxs --with-curl --with-mcrypt --enable-mbstring --with-iconv --with-gd -with-jpeg-dir=/usr/local/lib --enable-pdo --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd make make install cp php.ini-development /opt/php/lib/php.ini ln -s /opt/php/bin/php /usr/bin/php vi /opt/php/lib/php.ini 把include_path前面的分号删除,改成include_path = "/opt/php/lib/php" sudo vi /opt/httpd/conf/httpd.conf 在最下面加入一行AddHandler application/x-httpd-php .php sudo /opt/httpd/bin/httpd -k restart sudo vi /opt/httpd/htdocs/phpinfo.php
phpinfo.php的内容如下:
<?php phpinfo(); ?>
安装完php,重启apache,用浏览器访问http://localhost/phpinfo.php,能正常显示说明php装好了。
查看php版本: php -v
参考:http://www.jb51.net/article/24775.htm
方法二:
安装apache:
yum install httpd httpd-devel
启动apache:
/etc/init.d/httpd start
此时输入服务器的IP地址,应该看到apache的服务页面,端口不用输,apache默认就是使用80端口
安装mysql:
yum install mysql mysql-server
启动mysql:
/etc/init.d/mysqld start
安装php
yum install php php-devel php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash php-mysql php-xml
重启apache使php生效
/etc/init.d/httpd restart
此时可以在目录:/var/www/html/下建立一个PHP文件
代码:
<?php phpinfo(); ?>
然后访问这个文件,就能看到PHP的一些信息,php.ini配置文件的路径可以在这个页面上看到
安装php的扩展
yum
install
php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
安装完扩展之后需要再次重启apache
/etc/init.d/httpd restart
测试mysql是否链接成功的php代码
<?php
$con = mysql_connect("10.0.@.@@","@@","@@");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydb", $con);
$result = mysql_query("SELECT * FROM sys_user");
while($row = mysql_fetch_array($result))
{
echo $row['UserName'] . " " . $row['PassWord'] . " " . $row['id'];
echo "<br />";
}
mysql_close($con);
?>
可以把上面的代码传入目录/var/www/html/
就可以看到执行情况
参考: http://www.cnblogs.com/liulun/p/3535346.html