linuxphp56编译安装教程
基本安装方法
安装工具包
$
sudo
apt-get
install
python-software-properties
添加ppa源
$
sudo
add-apt-repository
ppa:yola/php5
安装php5-fpm
sudo
apt-get
update
sudo
apt-get
install
php5-fpm
其它必要的软件安装接
sudo
apt-get
install
nginx
配置php-fpm
php-fpm的解析器是C/S结构,它的配置文件位于:
(1)/etc/php5/fpm/php-fpm.conf
(2)/etc/php5/fpm/pool.d/
一般没什么严格的配置的要求,或者说这块我还没有具体的研究每个配置参数的意义
我采用了tcp模式与fastcgi进程进行连接,因此我修改了tcp监听的地址和端口,修改了一下监视目录的名称,这里不做具体详细解释了,大家可以参考官方文档根据自己的需求进行配置
重启php5-fpm
安装提示错误解决
如果服务器的系统源中没有php5-fpm,安装的时候会提示:
Reading
state
information...
Done
E:
Couldn't
find
package
php5-fpm
解决办法
1.
添加非官方的源到
/etc/apt/sources.list
echo
"deb
http://ppa.launchpad.net/brianmercer/php/ubuntu
lucid
main"
>>
/etc/apt/sources.list
echo
"deb-src
http://ppa.launchpad.net/brianmercer/php/ubuntu
lucid
main"
>>
/etc/apt/sources.list
2.
安装php5-fpm
sudo
apt-get
update
&&
sudo
apt-get
install
php5-fpm
3.
安装php扩展组件
sudo
apt-get
install
php-apc
php5-curl
php5-gd
php5-imagick
php5-mysql\
php5-memcache
php5-memcached
php5-mcrypt
4.
启动php-fpm
sudo
/etc/init.d/php5-fpm
start
php.in位于/etc/php5/fpm/php.ini
php-fpm.ini位于/etc/php5/fpm/php5-fpm.conf
php-fpm启动时报错
PHP
Warning:
PHP
Startup:
Unable
to
load
dynamic
library
'/usr/lib/php5/20060613+lfs/gd.so'
-
/usr/lib/php5/20060613+lfs/gd.so:
undefined
symbol:
gdImageCreateFromJpeg
in
Unknown
on
line
0
locate
libgd
查看gd的动态库位置,如果/usr/local/lib/目录里有则
rm
/usr/local/lib/libgd*
重启php-fpm即可
去掉php-fpm启动时警告提示信息
PHP
Deprecated:
Comments
starting
with
'#'
are
deprecated
in
/etc/php5/fpm/conf.d/imagick.ini
on
line
1
in
Unknown
on
line
0
把#变成;即可去掉该提示
② linux下安装php编译参数
在Linux下安装PHP,源代码方式安装,总需要配置很多参数。这里列出常用配置参数,并详细用中文解释说明了。给大家一些参考./configure
--prefix=/usr/local/php
php
安装目录
--with-apxs2=/usr/local/apache/bin/apxs
--with-config-file-path=/usr/local/php/etc
指定php.ini位置
--with-MySQL=/usr/local/mysql
mysql安装目录,对mysql的支持
--with-mysqli=/usr/local/mysql/bin/mysql_config
mysqli文件目录,优化支持
--enable-safe-mode
打开安全模式
--enable-ftp
打开ftp的支持
--enable-zip
打开对zip的支持
--with-bz2
打开对bz2文件的支持
--with-jpeg-dir
打开对jpeg图片的支持
--with-png-dir
打开对png图片的支持
--with-freetype-dir
打开对freetype字体库的支持
--without-iconv
关闭iconv函数,种字符集间的转换
--with-libXML-dir
打开libxml2库的支持
--with-xmlrpc
打开xml-rpc的c语言
--with-zlib-dir
打开zlib库的支持
--with-gd
打开gd库的支持
--enable-gd-native-ttf
支持TrueType字符串函数库
--with-curl
打开curl浏览工具的支持
--with-curlwrappers
运用curl工具打开url流
--with-ttf
打开freetype1.*的支持,可以不加了
--with-xsl
打开XSLT
文件支持,扩展了libxml2库
,需要libxslt软件
--with-gettext
打开gnu
的gettext
支持,编码库用到
--with-pear
打开pear命令的支持,php扩展用的
--enable-calendar
打开日历扩展功能
--enable-mbstring
多字节,字符串的支持
--enable-bcmath
打开图片大小调整,用到zabbix监控的时候用到了这个模块
--enable-sockets
打开
sockets
支持
--enable-exif
图片的元数据支持
--enable-magic-quotes
魔术引用的支持
--disable-rpath
关闭额外的运行库文件
--disable-debug
关闭调试模式
--with-mime-magic=/usr/share/file/magic.mime
魔术头文件位置
CGI方式安装才用的参数
--enable-fpm
打上php-fpm
补丁后才有这个参数,cgi方式安装的启动程序
--enable-fastcgi
支持fastcgi方式启动php
--enable-force-cgi-redirect
同上
,帮助里没有解释
--with-ncurses
支持ncurses
屏幕绘制以及基于文本终端的图形互动功能的动态库
--enable-pcntl
freeTDS需要用到的,可能是链接mssql
才用到
mhash和mcrypt算法的扩展
--with-mcrypt
算法
--with-mhash
算法
--with-gmp
--enable-inline-optimization
--with-openssl
openssl的支持,加密传输时用到的
--enable-dbase
--with-pcre-dir=/usr/local/bin/pcre-config
perl的正则库案安装位置
--disable-dmalloc
--with-gdbm
dba的gdbm支持
--enable-sigchild
--enable-sysvsem
--enable-sysvshm
--enable-zend-multibyte
支持zend的多字节
--enable-mbregex
--enable-wddx
--enable-shmop
--enable-soap
③ 在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开发环境
1、MySQL的安装
在MySQL官网下载MySQL的安装文件MySQL-server-4.0.20-0.i386.rpm,执行下面的命令完成MySQL的安装。
rpm -ivh MySQL-server-4.0.20-0.i386.rpm
在没有设置MySQL密码的情况下,通过以下命令测试MySQL是否安装成功。
mysql -u root
出现类似welcome to the mysql mointor. commands end with;or \g的字样,说明安装成功。
2、Apache的安装
从Apache的官网下载unix版本的压缩包,以httpd-2.0.52.tar.gz为例,假设资源包放在/usr/local/src下,进入这个目录后解压缩,命令如下:
cd /usr/local/src
tar -zxvf httpd-2.0.52.tar.gz
解压缩后,进入目录httpd-2.0.52,执行以下命令:
./configure --prefix=/usr/local/apache2 --enable--mole=so
其中--prefix=/usr/local/apache2用来指定Apache的安装目录。接下来进行编译,执行一下命令完成安装。
make
mae install
3、配置php开发环境的安装
1)从php官网下载php5.1.4.tar.gz的压缩包,解压缩该文件包,命令如下:
tar -zxf php5.1.4.tar.gz
2)转到解压缩后的目录,执行以下命令完成php安装目录等相关配置:
./configure --prefix=/usr/local/php -with-mysql=/var/lib/mysql
3)接着编译PHP,命令如下:
make
make install
4)复制当前目录下的文件PHP大安装目录的lib目录下,并改名为php.ini,命令如下:
cp php.ini-dist /usr/local/php/lib/php.ini
⑤ 如何在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等脚本编译安装就可以了。
⑥ 如何编译安装PHP扩展
一开始安装PHP的时候,我们并不知道需要哪些扩展,所以只有等到我们真正用到的时候才想办法去安装。
安装PHP扩展最简单的办法就是
sudo apt-get install php5-xxx
但有的时候并非我们所愿,源里面并没有我们需要的扩展,这时候就需要我们下载源码自己编译安装了。
这篇文章中我将介绍在本地Linux平台下编译安装PHP扩展的方法。
现在网站根目录下创建 index.php 打印基本的配置信息,以验证我们是否安装成功。
配置编译环境
我们需要安装一些编译必须的库,还有 php-dev 版本
Ubuntu
sudo apt-get install php5-dev php5-mysql gcc libpcre3-dev
Fedora
sudo yum install php-devel php-mysqlnd gcc libtool
RHEL
sudo yum install php-devel php-mysql gcc libtool
Suse
yast2 -i php5-pear php5-devel php5-mysql gcc
安装扩展
PHP有两种可供安装的扩展:一种是PHP原生的但是默认没有安装的,另一种的第三方开发的扩展。
下面依次介绍两种扩展的安装方法:
安装之前我们需要一份和当前机器上相同版本的PHP源码
cd code
wget http://cn2.php.net/distributions/php-5.5.9.tar.bz2
tar xvjf php-5.5.9.tar.bz2
cd php-5.5.9
前往此处 下载相应的源码包。
在 /ext 目录下面可以看到所有PHP原生的扩展。
安装原生扩展
以 PHP-intl 为例,这是PHP国际化的扩展。
为了安装这个扩展我们需要先安装ICU 库
sudo apt-get install icu-devtools icu-doc libicu-dev libicu52 libicu52-dbg
ICU 安装成功之后进入/ext/intl 目录:
cd intl
phpize
./configure --enable-intl
make
sudo make install
下面解释一下上面的每个命令:
phpize : 是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块
./configure --enable-intl: 配置编译环境,相当于告诉编译器编译PHP源码的时候加上intl这个扩展。
make: 将会把源码编译成 intl.so
make install : 将会把 intl.so 移动到当前安装的 PHP 的扩展目录。
接下来我们要做的就是在php.ini中启用这个扩展,这一步将会在最后给出示例。
安装第三方扩展
将以这个 扩展为例,这个扩展主要实现了PHP识别条形码的功能。
先安装必要的依赖
sudo apt-get install pkg-config
git clone https://github.com/mongodb/mongo-php-driver
cd mongo-php-driver
phpize
./configure
make
sudo make install
将会生成一个文件,将其拷贝到PHP的扩展目录下面。
启用扩展
在php.ini中启用扩展的方式有很多:
直接在php.ini文件中添加 extension=mongo.so,这是最简单直接的方法。
也可以单独建一个ini文件,然后在php.ini中包含这些文件就可以了。
下面介绍一下第二种方法:
cd `/etc/php5/mods-available`
这个目录里可以放新建的ini文件,然后执行
sudo touch mongo.ini
echo "extension=mongo.so" | sudo tee -a mongo.ini
sudo touch intl.ini
echo "extension=intl.so" | sudo tee -a intl.ini
上面的命令将会创建ini文件,并且写如相应的配置信息。
然后执行下面的命令启用扩展即可(需要安装 php5enmod 工具):
sudo php5enmod mongo
sudo php5enmod intl
如果未安装 php5enmod 工具,则需要手动配置:
ln -s /etc/php5/mods-available/mongo.ini /etc/php5/cli/conf.d/mongo.ini
ln -s /etc/php5/mods-available/intl.ini /etc/php5/cli/conf.d/intl.ini
ln -s /etc/php5/mods-available/mongo.ini /etc/php5/fpm/conf.d/mongo.ini
ln -s /etc/php5/mods-available/intl.ini /etc/php5/fpm/conf.d/intl.ini
最后在执行一下重启操作就可以了:
sudo service nginx restart
sudo service php5-fpm restart
⑦ 如何在linux上安装php5.6,谢谢,
不知道你问的linux,是哪个发行版本,常用的如 ubntu,centos,debian等。
我列一个centos7(服务器常用这个版本)的安装方法吧
centos7默认使用yum install 来安装程序,但默认源安装的php是5.4的,版本比较低,
要安装高版本的,要么下载源代码手动编译安装,但对不熟悉的,万一出点错误,会越搞越乱。我一般使用epel源安装php,里面各个版本都有,最新的php7.3
首先安装epel
rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
这里面的url是目前我用的,如果提示出错,就是换url了,可以在电脑上手动打开epel源列表去检查 epel-release是哪个版本,换上对应的名字
按版本安装php
rpm-Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yuminstallphp56wphp56w-mysqlphp56w-pdophp56w-gdphp56w-sslphp56w-mbstringphp56w-cliphp56w-xmlphp56w-bcmath
我这里列的是一些常用的php扩展,如果需要其它的,手动加上即可
如果需要安装php其它版本,把包名里的56改成对应版本即可 ,如
yuminstallphp71wphp71w-mysqlphp71w-pdophp71w-gdphp71w-sslphp71w-mbstringphp71w-cliphp71w-xmlphp71w-bcmath
yuminstallphp72wphp72w-mysqlphp72w-pdophp72w-gdphp72w-sslphp72w-mbstringphp72w-cliphp72w-xmlphp72w-bcmath
可对应安装php7.1和php7.2,这种安装方法,会默认配置好对应的设置,php.ini在/etc/中查找,命令行也默认启用了 (php-cli)
⑧ linux centos 怎么安装 php编程 软件
Gettext
1 首先进入到php源码包中
cd /opt/php-5.1.2/ext/gettext
2 在gettext文件夹下产生configure文件
/opt/php/bin/phpize
3 配置编译
./configure --with-php-config=/opt/php/bin/php-config --with-gettext
make && make install
4 在/opt/php/lib/php/extensions下产生一个gettext.so文件
5 确定 php.ini文件中的extension_dir=/opt/php/lib/php/extensions 跟 extension=gettext.so
6 重新编译 php
Zlib
1 首先进入到php源码包中
cd /opt/php-5.1.2/ext/zlib
2 在zlib文件夹下产生configure文件
/opt/php/bin/phpize
3 配置编译
./configure --with-php-config=/opt/php/bin/php-config --with-zlib
make && make install
4 在/opt/php/lib/php/extensions下产生一个zlib.so文件
5 确定 php.ini文件中的extension_dir=/opt/php/lib/php/extensions 跟 extension=zlib.so
6 重新编译 php
mbString
配制mbstring扩展
1 运行 /opt/php/bin/phpize
2 进入到 php源码包中的ext/mbstring下
cd /opt/php-5.1.2/ext/mbstring
./configure --with-php-config=/opt/php/bin/php-config --enable-mbstring
make && make install
3 这样就在/opt/php/lib/php/extensions下生成一个mbstring.so
4然后保证extension_dir指向正确的位置,extension=php_mbstring.dll开启
这样mbstring就开启了
Mod_rewrite
以RHEL5为例
1)首次安装apache,在编译时增加--enable-rewrite选项。
如./configure --prefix=/usr/local/apachel --enable-so --enable-mods-shared=all --enable-rewrite --enable-cache
2)增加mod_rewrite模块
# find mod_rewrite.c //在apache的源码安装目录中寻找mod_rewrite.c文件
一般会在httpd-2.28/moles/mappers下
# /opt/httpd/bin/apxs -c mod_rewrite.c //apxs应指定绝对路径,在你当前正在使用apache的bin目录里
# /opt/httpd/bin/apxs -i -a -n mod_rewrite mod_rewrite.la
如果没有什么错误的话,应该在你的apache的moles目录中编译出一个mod_rewrite.so文件。
编辑httpd.conf文件,确认httpd.conf中已经包含mod_rewrite.so的加载语句,如下:
LoadMole rewrite_mole moles/mod_rewrite.so
这时,你的apache应该已经支持rewrite了。
重启apache即可。
⑨ linux怎样一键安装web环境php+apache+mysql
1、首先要先下载下来一键安装包
2、下载完成后解压zip的文件包解压命令“uzip sh-php.zip”
3、加压完成以后,给解压的文件夹赋权限,在安装的时候需要权限,执行命令“chmod -R 777 filename/”最高的权限
4、cd fielname 进入文件夹,找到install.sh 执行sh install.sh这个命令进行安装。
5、执行命令以后会提示你安装什么版本的软件,根据自己的需要来选择您需要的软件
6、选择完成以后,输入y继续然后就会下载依赖的一些系统组件
7、下面就是等待下载完成,编译,make 安装make
8、编译安装完成以后,会到这个account.log的文件里面会有mysql的密码和ftp的密码,安装完成以后环境就配置完成了,就可以部署网站了
⑩ linuxphp网站怎么安装
配置php服务
安饥塌装yasm汇编器(解压与编译过程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvfyasm-1.2.0.tar.gz
[root@linuxprobesrc]cdyasm-1.2.0
[[email protected]]./configure
[[email protected]]make
[[email protected]]makeinstall
安装libmcrypt加密算法扩展库(解烂银圆压与编译过程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvflibmcrypt-2.5.8.tar.gz
[root@linuxprobesrc]cdlibmcrypt-2.5.8
[[email protected]]./configure
[[email protected]]make
[[email protected]]makeinstall
安装libvpx视频编码器(解压与编译过程搏旦已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarxjvflibvpx-v1.3.0.tar.bz2
[root@linuxprobesrc]cdlibvpx-v1.3.0
[[email protected]]./configure--prefix=/usr/local/libvpx--enable-shared--enable-vp9
[[email protected]]make
[[email protected]]makeinstall
安装Tiff标签图像文件格式(解压与编译过程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvftiff-4.0.3.tar.gz
[root@linuxprobesrc]cdtiff-4.0.3
[[email protected]]./configure--prefix=/usr/local/tiff--enable-shared
[[email protected]]make
[[email protected]]makeinstall
安装libpng图片(png格式)函数库(解压与编译过程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvflibpng-1.6.12.tar.gz
[root@linuxprobesrc]cdlibpng-1.6.12
[[email protected]]./configure--prefix=/usr/local/libpng--enable-shared
[[email protected]]make
[[email protected]]makeinstall
安装freetype字体引擎(解压与编译过程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvffreetype-2.5.3.tar.gz
[root@linuxprobesrc]cdfreetype-2.5.3
[[email protected]]./configure--prefix=/usr/local/freetype--enable-shared
[[email protected]]make
[[email protected]]makeinstall
安装jpeg图片(jpeg格式)函数库(解压与编译过程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvfjpegsrc.v9a.tar.gz
[root@linuxprobesrc]cdjpeg-9a
[root@linuxprobejpeg-9a]./configure--prefix=/usr/local/jpeg--enable-shared
[root@linuxprobejpeg-9a]make
[root@linuxprobejpeg-9a]makeinstall
安装libgd图像处理程序(解压与编译过程已省略):
[root@linuxprobejpeg-9a]cd/usr/local/src
[root@linuxprobesrc]tarzxvflibgd-2.1.0.tar.gz
[root@linuxprobesrc]cdlibgd-2.1.0
[[email protected]]./configure--prefix=/usr/local/libgd--enable-shared--with-jpeg=/usr/local/jpeg--with-png=/usr/local/libpng--with-freetype=/usr/local/freetype--with-fontconfig=/usr/local/freetype--with-xpm=/usr/--with-tiff=/usr/local/tiff--with-vpx=/usr/local/libvpx
[[email protected]]make
[[email protected]]makeinstall
安装t1lib图片生成函数库(解压与编译过程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvft1lib-5.1.2.tar.gz
[root@linuxprobesrc]cdt1lib-5.1.2
[[email protected]]./configure--prefix=/usr/local/t1lib--enable-shared
[[email protected]]make
[[email protected]]makeinstall
将函数库文件放至合适的位置:
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]ln-s/usr/lib64/libltdl.so/usr/lib/libltdl.so
[root@linuxprobesrc]cp-frp/usr/lib64/libXpm.so*/usr/lib/
安装php服务程序(命令比较长,请一定要复制完整!!!):
[root@linuxprobesrc]tar-zvxfphp-5.5.14.tar.gz
[root@linuxprobesrc]cdphp-5.5.14
[[email protected]]exportLD_LIBRARY_PATH=/usr/local/libgd/lib
[[email protected]]./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-mysql-sock=/tmp/mysql.sock--with-pdo-mysql=/usr/local/mysql--with-gd--with-png-dir=/usr/local/libpng--with-jpeg-dir=/usr/local/jpeg--with-freetype-dir=/usr/local/freetype--with-xpm-dir=/usr/--with-vpx-dir=/usr/local/libvpx/--with-zlib-dir=/usr/local/zlib--with-t1lib=/usr/local/t1lib--with-iconv--enable-libxml--enable-xml--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--enable-opcache--enable-mbregex--enable-fpm--enable-mbstring--enable-ftp--enable-gd-native-ttf--with-openssl--enable-pcntl--enable-sockets--with-xmlrpc--enable-zip--enable-soap--without-pear--with-gettext--enable-session--with-mcrypt--with-curl--enable-ctype
[[email protected]]make
[[email protected]]makeinstall
复制php服务程序的配置文件到安装目录:
[[email protected]]cpphp.ini-proction/usr/local/php/etc/php.ini
删除默认的php配置文件:
[[email protected]]rm-rf/etc/php.ini
创建php配置文件的软连接到/etc/目录中:
[[email protected]]cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
[[email protected]]ln-s/usr/local/php/etc/php-fpm.conf/etc/php-fpm.conf
[[email protected]]ln-s/usr/local/php/etc/php.ini/etc/php.ini
编辑php服务程序的配置文件:
[[email protected]]vim/usr/local/php/etc/php-fpm.conf
//将第25行参数前面的分号去掉。
pid=run/php-fpm.pid
//修改第148和149行,将user与group修改为www。
user=www
group=www
添加php-fpm服务程序到开机启动项:
[[email protected]]cpsapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm
[[email protected]]chmod+x/etc/rc.d/init.d/php-fpm
[[email protected]]chkconfigphp-fpmon
为了保障网站的安全性,禁用掉不安全的功能:
[[email protected]]vim/usr/local/php/etc/php.ini
//修改第305行的disable_functions参数,追加参数为:
disable_functions=passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
配置nginx服务程序支持php:
[[email protected]]vim/usr/local/nginx/conf/nginx.conf
//将第2行前面的号去掉并修改为userwwwwww;
//将第45行参数修改为indexindex.htmlindex.htmindex.php;
//将第65-71行前面的号去掉,修改为:
location~.php${
roothtml;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
重启nginx与php-fpm服务程序:
[[email protected]]systemctlrestartnginx
[[email protected]]systemctlrestartphp-fpm