‘壹’ linux下安装php环境必须的组件 libxml2 一直安装不成功,求大神解答!
直接用 yum 安装 php好了。yum 可以自己解依赖关系
‘贰’ 在linux系统中怎么搭建php环境
Linux下配置安装PHP环境
参考别人的做法,遇到问题上网查,下面就是安装步骤.
一、安装Apache2.2.22
1、到官网下载 http://httpd.apache.org/download.cgi
2、解压
tar -zxvf httpd-2.2.22.tar.gz
3、建立目标文件夹(注意以下所有操作都时在root用户下执行的)
mkdir /usr/local/apache2
也就是说等下安装的apache2要安装到这个文件夹里面
4、配置
回到原来解压之后产生的文件夹
./configure --prefix=/usr/local/apache2 --enable-mole=shared
要加上后面的参数,否则无法使用php,-enable-mole=shared表示Apache可以动态的加载模块
这一步,出现了很多问题:
第一个错误为:
checking for APR... no
configure: error: APR not found. Please read the documentation.
解决方法:
download the latest versions of both APR and APR-Util from Apache APR, unpack them into ./srclib/apr and ./srclib/apr-util (be sure the domain names do not have version numbers; for example, the APR distribution must be under ./srclib/apr/)
then do
./configure --with-included-apr
原文章地址:http://stackoverflow.com/questions/9436860/apache-httpd-setup-and-installatio
另外一种解决方法为:
分别安装APR和APR-util,安装方法为:首先下载这两个文件,然后解压,进入解压后目录,然后把APR和APR-util分别安装到/usr/local/文件夹的apr和apr-util文件夹下。APR的具体安装方法为:
[root@localhost 52lamp]# tar -zxvf apr-1.4.2.tar.gz //unzip -o apr-1.4.2.zip
[root@localhost 52lamp]# cd apr-1.4.2
[root@localhost apr-1.4.2]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.4.2]# make
[root@localhost apr-1.4.2]# make install
安装Apr-util 在./confiure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
其他步骤类似。
第二个错误为:no acceptable C compiler found in $Path
直接运行 yum install gcc,安装Gcc即可
第三个问题为:pcre-config for libpcre not found
解决方法就是 下载prce安装包,和APR类似,安装到/usr/local/pcre文件夹下面即可。PS:fedora下安装c++编译器g++的命令为:yum install gcc-c++ 。
5、编译
make
6、安装
make install
7、启动,重启和停止 ,先切换到安装完成后的目录/usr/local/apache2/bin
./apachectl -k start
./apachectl -k restart
./apachectl -k stop
8、配置文件(满足最基本的配置)
编辑 /usr/local/apache2/conf/httpd.conf 文件
找到:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在后面添加:
AddType application/x-httpd-php .php(使Apcche支持PHP)
AddType application/x-httpd-php-source .php5
找到:
<IfMole dir_mole>
DirectoryIndex index.html
</IfMole>
添加:
<IfMole dir_mole>
DirectoryIndex index.html index.php
</IfMole>
找到:
#ServerName www.example.com:80
修改为:
ServerName 127.0.0.1:80或者ServerName localhost:80
记得要去掉前面的“#”
9、测试
在浏览器里输入http://127.0.0.1
如果出现It Works!说明成功。这是我的测试结果:O(∩_∩)O哈哈~
10、修改默认的Web站点目录
默认的目录为 "/usr/local/apache2/htdocs",修改apache的配置文件httpd.conf,比如在新建一个 /home/gyw/WebSite的目录作为apache的站点目录
找到DocumentRoot这一行修改为:DocumentRoot "/home/gyw/WebSite"
找到 <Directory> 这一行修改为:<Directory "/home/gyw/WebSite">
测试:修改到文件夹出现错误:
“You don't have permission to access /index.html on this server.”
解决方法:
更改文件权限;chmod 755 index.html
打开apache配置文件httpd.conf,找到这么一段:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
deny from all
Satisfy all
</Directory>
测试结果如下:
二、安装PHP
1、 下载
http://www.php.net/downloads.php
2、解压
tar -zxvf php-5.3.16.tar.gz
3、建立目标文件夹
mkdir /usr/local/php
也就是说等下安装的php要安装到这个文件夹里面
4、配置
回到原来解压后的文件夹
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs
注意这里有一个-with-apxs2=/usr/local/apache/bin/apxs选项,其中apxs是在安装Apache时产生的,apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具,使之可以用由mod_so提供的LoadMole指令在运行时加载到Apache服务器中。我的理解是通过这个工具把PHP模块动态加载到Apache中
出现错误:configure: error: xml2-config not found. Please check your libxml2 installation.
运行yum install libxml2,然后再运行yum install libxml2-devel安装完毕后,重新运行上面的./configure命令。
5、编译
make
6、测试编译
make test
7、安装
make install
8、配置文件
cp /usr/local/src/php-5.3.16/php.ini-development /usr/local/php/lib/php.ini
把原来位于源代码里面的php.ini-development拷贝到/usr/local/php/lib/php.ini下,并且重命名为php.ini
9.重启apache
10、测试
在apache的htdocs下建立一个php文件test.php,里面的内容如下:
<?php
phpinfo();
?>
然后在浏览器里输入http://127.0.0.1/test.php
如果出现php的相关配置,成功,如果什么都没有输入,说明失败,重新以上步骤或者查找原因
如果决定在安装后改变配置选项,只需重复最后的三步configure, make, 以及 make install,然后需要重新启动 Apache 使新模块生效。Apache不需要重新编译。
测试结果如下图:
三、安装MySql
1、下载
到官网下载mysql-5.1.65.tar.gz(注意是源码包)
2、解压
tar -zxvf mysql-5.1.65.tar.gz
3、建立目标文件夹
mkdir /usr/local/mysql
也就是说等下安装的mysql要安装到这个文件夹里面
4、配置
./configure --prefix=/usr/local/mysql/
在./configure时出现错误:error: No curses/termcap library found
下载安装相应软件包
yum list|grep ncurses
yum -y install ncurses-devel
yum install ncurses-devel
5、编译
make
6、安装
make install
7、启动
MySQL服务并不会自动启动,还需要先初始化MySQL数据库,操作如下:
cd /usr/local/mysql/bin
sudo ./mysql_install_db --user=root
注意,这里最后的root是指可以操作数据库的用户,可以是当前用户,也可以新建用户,与linux上的root用户是两回事,可以自己取一个名字
./mysqld_safe --user=root & 这条命令负责启动mysql服务的守护进程,此外最后的&时必须的,因为希望守护进程在后台运行
这里的root就是刚才的那个
8、为根用户创建密码
./mysqladmin -u root password ‘123456’
如果root已经设置过密码,采用如下方法
./mysqladmin -u root password oldpass ‘123456’
9、测试
mysql -u root -p
会提示输入密码,就用刚才设置的密码
123456
如果出现mysql>,说明连接成功了,下面通过命令 创建一个数据库、建一个表,增加一条记录,为后面的测试准备
mysql> create database gywtest;
mysql> use gywtest;
mysql> create table student(id int(4) not null primary key auto_increment,stuname char(20));
mysql> insert into student(stuname) values('Tom');
注意每条命令后面有个分号,如果上面的都成功,后面就可以用这个测试。
四、将PHP与MySql结合起来
1、重新配置PHP,改变配置选项,只需重复PHP安装时的最后的三步configure, make, 以及 make install,然后需要重新启动 Apache 使新模块生效,Apache不需要重新编译。
2、配置
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysqli=/usr/local/mysql/bin/mysql_config 注意mysql_config 的路径
3、编译 make
4、安装 make installe
5、测试 写一个页面test.php,放在apache的web目录下,测试上面用命令创建的数据库
<?php
$mysqli=new mysqli();
$mysqli->connect('localhost','root','123456','gywtest');
// 创建查询
$sqlstr='select * from student';
//发送查询给MySql
$result=$mysqli->query($sqlstr);
while($row=$result->fetch_object())
{
$name=$row->stuname;
echo $name;
}
?>
Fatal error: Class 'mysqli' not found in /home/lufangtao/Project/DB.php on line 3
解决方法:
/usr/local/php/bin/phpize 这里回车运行
出错:
Cannot find config.m4.
Make sure that you run './phpize' in the top level source directory of the mole
解决方法:
PHP源码包文件夹下的EXT文件夹就是放置着目前版本的可用扩展,CD进去看看都有哪些你需要的?应该看到mysqli文件夹了吧~~~
在当前目录下执行phpize
[root@localhost mysqli]#/usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Modeule Api No: 20090626
Zend Extension Api No: 220090626
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
解决方法:
yum install autoconf再次运行上面的命令即可。
[root@localhost mysqli]#./configure –prefix=/opt/mysqli –with-php-config=/opt/php/bin/php-config –with-mysqli=/opt/mysql/bin/mysql_config
[root@localhost mysqli]#make
[root@localhost mysqli]#make install
安装完成后会有提示扩展所在目录路径,如:
/opt/php/lib/php/extensions/no-debug-zts-20090626php
所需的mysqli.so便会在此目录下,接下来修改/opt/php/etc/下的php.ini文件,加入mysqli扩展,即加入如下一行:
extension=/opt/php/lib/php/extensions/no-debug-zts-20090626/mysqli.so
这里还是回出现错误:
参考博客http://www.cnblogs.com/wangtao_20/archive/2011/03/07/1973621.html
解决不用扩展连接MySQL的方法。
最终还是没有解决MySQLi连接的问题,但是可以使用MySQL数据库了,下面是测试程序
复制代码
<?php
$link=mysql_connect('localhost','root','123456');
if(!$link) echo "F!";
else echo "S!";
mysql_select_db("students") or die("Could not select database");
$query="SELECT * FROM student;";
$result=mysql_query($query) or die("Query failed");
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n"; }
print "</table>\n";
/* 释放资源 */
mysql_free_result($result);
mysql_close();
?>
~
‘叁’ linux安装PHP提示不存在libxml2
linux安装LMAP环境
第一步就是要安装libxml
根据下面这个来就行了!
希望对你有帮助!
http://www.linuxdiyf.com/viewarticle.php?id=77310
‘肆’ linux安装php出现checking whether libxml build works... no 错误提示的解决方法
因为你的系统里面是Apache2,那么参数中的下面部分:
--with-apxs=/usr/local/apache/bin/apxs
应该修改为:
--with-apxs2=/usr/local/apache/bin/apxs
‘伍’ 求助,Linux系统安装php,报错!
请用 ./configure 还有就是你那一堆换行连接符 有问题 ,./configure 是autoconf 生成的一个对应不同的环境进行配置的一个shell 文件,如果你还是报错,那么检查你后面with的那一堆php扩展的依赖,一般你with 那么多是安装不过的 。
‘陆’ suse linux 怎么安装php运行环境
SuSE Linux上搭建apache+php+mysql环境
1.安装apache
apache安装包:httpd-2.2.9.tar.gz,安装步骤如下:
1) ./configure --prefix=/usr/local/httpd-2.2.9
2) make
3) make install
2.安装mysql
直接使用mysql非RPM二进制安装包,如:mysql-5.1.36-linux-i686-glibc23.tar.gz,具体步骤如下:
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
3.安装php依赖库
libxml2,expat,gd,gettext,这几个依赖库的安装使用标准的automake安装方式。
4. 安装php
php安装包:php-5.2.6.tar.gz,安装步骤如下:
1) ./configure --prefix=/usr/local/php-5.2.6 --enable-mbstring=LANG --with-mysql=/usr/local/mysql --with-gd=/usr/local/gd --with-gettext=/usr/local/gettext --with-libxml-dir=/usr/local/libxml2 --with-libexpat-dir=/usr/local/expat --with-apxs2=/usr/local/httpd/bin/apxs
参数--with-apxs2=/usr/local/httpd/bin/apxs是为了生成libphp5.so文件,所以是必须的。
2) make
3) make install
安装完成后把php.ini-dist复制到/usr/local/php/lib/,并重命名为php.ini。基本到这里PHP就安装成功了,如果中间出现错误,除了在配置的时候没有选对选项之后一般都不出现错误。
5.修改apache配置文件httpd.conf,添加如下两行:
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
并确保文件中有以下一句话,没有就自己添加在所有LoadMole之后:
LoadMole php5_mole moles/libphp5.so
6.启动apache
#/usr/local/httpd/bin/apachectl restart
‘柒’ 如何在linux下安装多个不同版本的PHP
Linux (测试环境 Ubuntu 12.04 Server X86_64)
1. 安装编译工具及所需类库
$ sudo apt-get install build-essential gcc g++ autoconf libjpeg62 libjpeg62-dev libpng12-0 libpng12-dev libfreetype6 libfreetype6-dev libxml2 libxml2-dev zlib1g zlib1g-dev bzip2 libbz2-dev openssl libssl-dev curl libcurl4-openssl-dev libpcre3 libpcre3-dev libevent-1.4-2 libevent-dev libmcrypt4 libmcrypt-dev mcrypt libltdl-dev libldap2-dev libsasl2-dev libmhash-dev libc-client2007e libc-client2007e-dev
2. 安装MySQL
$ sudo apt-get install mysql-server libmysqlclient-dev
3. 安装PHP
Linux下多版本PHP共存需要自己手工编译安装。
下载PHP源文件到/opt/src目录
$ mkdir /opt/src
$ cd /opt/src
$ wget http://museum.php.net/php5/php-5.2.17.tar.bz2 -O php-5.2.17.tar.bz2
$ wget http://cn2.php.net/get/php-5.3.28.tar.bz2/from/this/mirror -O php-5.3.28.tar.bz2
$ wget http://cn2.php.net/get/php-5.4.29.tar.bz2/from/this/mirror -O php-5.4.29.tar.bz2
$ wget http://cn2.php.net/get/php-5.5.14.tar.bz2/from/this/mirror -O php-5.5.14.tar.bz2
创建PHP各版本安装目录
$ mkdir -p /opt/php/{5217,5328,5429,5514}
安装PHP 5.2.17
$ cd /opt/src
$ tar -xvjf php-5.2.17.tar.bz2
$ cd php-5.2.17
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/libjpeg.so
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/libpng.so
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libkrb5.so /usr/lib/libkrb5.so
$ wget -O debian_patches_disable_SSLv2_for_openssl_1_0_0.patch “https://bugs.php.net/patch-display.php?bug_id=54736&patch=debian_patches...”
$ patch -p1 < debian_patches_disable_SSLv2_for_openssl_1_0_0.patch
$ ./configure --prefix=/opt/php/5217 --with-config-file-scan-dir=/opt/php/5217/etc/php.d --with-mysql --with-pdo-mysql --with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-ftp --disable-debug --disable-ipv6 --disable-short-tags --enable-calendar --with-mime-magic --with-imap --with-imap-ssl --with-kerberos
$ make
$ sudo make install
$ cp php.ini-recommended /opt/php/5217/lib/php.ini
安装PHP 5.3.28
$ cd /opt/src
$ tar -xvjf php-5.3.28.tar.bz2
$ cd php-5.3.28
$ ./configure --prefix=/opt/php/5328 --with-config-file-scan-dir=/opt/php/5328/etc/php.d --with-mysql --with-pdo-mysql --with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-ftp --disable-debug --disable-ipv6 --disable-short-tags --enable-calendar --with-imap --with-imap-ssl --with-kerberos
$ make
$ sudo make install
$ cp php.ini-development /opt/php/5328/lib/php.ini
安装PHP 5.4.29
$ cd /opt/src
$ tar -xvjf php-5.4.29.tar.bz2
$ cd php-5.4.29
$ ./configure --prefix=/opt/php/5429 --with-config-file-scan-dir=/opt/php/5429/etc/php.d --with-mysql --with-pdo-mysql --with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-ftp --disable-debug --disable-ipv6 --disable-short-tags --enable-calendar --with-imap --with-imap-ssl --with-kerberos
$ make
$ sudo make install
$ cp php.ini-development /opt/php/5429/lib/php.ini
安装PHP 5.5.14
$ cd /opt/src
$ tar -xvjf php-5.5.14.tar.bz2
$ cd php-5.5.14
$ ./configure --prefix=/opt/php/5514 --with-config-file-scan-dir=/opt/php/5514/etc/php.d --with-mysql --with-pdo-mysql --with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-ftp --disable-debug --disable-ipv6 --disable-short-tags --enable-calendar --with-imap --with-imap-ssl --with-kerberos
$ make
$ sudo make install
$ cp php.ini-development /opt/php/5514/lib/php.ini
4. 安装Apache
$ sudo apt-get install apache2
启用相应模块
$ a2enmod headers
$ a2enmod expires
$ a2enmod actions
$ a2enmod rewrite
5. 配置Apache
$ sudo vi /etc/apache2/httpd.conf
追加如下脚本映射和虚拟主机配置,原理同Windows的配置说明。
ServerName localhost
AddType application/x-httpd-php .php
ScriptAlias /php-5217/ "/opt/php/5217/bin/"
ScriptAlias /php-5328/ "/opt/php/5328/bin/"
ScriptAlias /php-5429/ "/opt/php/5429/bin/"
ScriptAlias /php-5514/ "/opt/php/5514/bin/"
<Directory /var/www/sites>
Options Indexes FollowSymLinks Includes ExecCGI
DirectoryIndex index.php index.html
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/sites/5217>
Action application/x-httpd-php "/php-5217/php-cgi"
</Directory>
<Directory /var/www/sites/5328>
Action application/x-httpd-php "/php-5328/php-cgi"
</Directory>
<Directory /var/www/sites/5429>
Action application/x-httpd-php "/php-5429/php-cgi"
</Directory>
<Directory /var/www/sites/5514>
Action application/x-httpd-php "/php-5514/php-cgi"
</Directory>
# Virtualhosts
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/sites/5217/test.local"
ServerName php5217.local
ErrorLog "/var/log/apache2/php5217.local-error.log"
CustomLog "/var/log/apache2/php5217.local-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/sites/5328/test.local"
ServerName php5328.local
ErrorLog "/var/log/apache2/php5328.local-error.log"
CustomLog "/var/log/apache2/php5328.local-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/sites/5429/test.local"
ServerName php5429.local
ErrorLog "/var/log/apache2/php5429.local-error.log"
CustomLog "/var/log/apache2/php5429.local-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/sites/5514/test.local"
ServerName php5514.local
ErrorLog "/var/log/apache2/php5514.local-error.log"
CustomLog "/var/log/apache2/php5514.local-access.log" common
</VirtualHost>
保存配置后,创建各站点的DocumentRoot目录,再往每个目录放置一个phpinfo的测试文件,完成后重启Apache服务器并在本地hosts文件加入域名解析,现在就可以访问各站点来测试多版本PHP共存了。
好了,基本的多版本PHP共存解决方案已经完成,如果还需要添加其他的PHP类库支持,后续自己再调用对应php目录下的pecl, php_config等脚本编译安装就可以了。
‘捌’ linux版安装PHP需要哪些软件
APACHE 2.2
MYSQL 5.1
GD2
LIBPNG
LIBXML
JPEG6B
PHP
也就这些包了!
一般做个基于PHP的网站主要就用这些。
尤其 GD和PHP的编译,需要相当大的耐心
GOOD LUCK!
‘玖’ 我发现我在操作PHP的时候,在Linux下安装PHP过程中,编译时出现configure: err
其实有些东西我也讲不太清楚,你可以参考下我的意见。nxu安装 PHP:
yum -y install libxml2 libxml2-devel 下载安装libxml2,通过libxml2编译安装PHP
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with
最保险的方法是,多去后盾人看一下教学视频,这样更加有用。
‘拾’ 在Linux下安装PHP时出错
你configure都没有通过,就别make了,至于configure: error: libxml2 version 2.6.11 or greater required,是库文件libxml2版本太低了,需要升级一下