Table of Contents
烂泥:php5.6源码安装与apache集成,php5.6apache
Home php教程 php手册 烂泥:php5.6源码安装与apache集成,php5.6apache

烂泥:php5.6源码安装与apache集成,php5.6apache

Jun 13, 2016 am 09:19 AM
php5

烂泥:php5.6源码安装与apache集成,php5.6apache

本文由秀依林枫提供友情赞助,首发于烂泥行天下。

apache对php的支持是通过apache的mod_php5模块来支持的,这点与nginx不同。nginx是通过第三方的fastcgi处理器才可以对php进行解析,有关nginx与php集成,请看《烂泥:php5.6源码安装及php-fpm配置与nginx集成》。

如果源码编译安装php的话,需要在编译时指定--with-apxs2=/usr/local/apache2/bin/apxs表示告诉编译器通过apache的mod_php5模块来提供对php的解析。

同时php安装的最后一步make install时,我们会看到将动态链接库libphp5.so拷贝到apache2的安装目录的modules目录下,并且还需要在httpd.conf配置文件中添加LoadModule语句来动态将libphp5.so模块加载进来,从而实现Apache对php的支持。

php与apache集成需要以下几个步骤:

1、安装libiconv库

2、php源码安装

3、配置apache使其支持php

4、测试php

一、安装libiconv库

libiconv库为需要做转换的应用程序提供了一个iconv命令,以实现一个字符编码到另一个字符编码的转换,比如它可以将UTF8编码转换成GB18030编码,反过来也行。

php与apache集成时一定要安装libiconv库,否则在make时系统会报错。报错信息如下:

make: *** [sapi/cli/php] Error 1

/usr/bin/ld: cannot find -liconv

collect2: ld returned 1 exit status

make: *** [sapi/cli/php] Error 1

现在开始正式安装libiconv库,首先下载libiconv库,如下:

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

解压libiconv库,如下:

tar -xf libiconv-1.14.tar.gz

安装libiconv库,首先查看安装帮助信息。如下:

./configure --help

通过上图的帮助,我们可以看到libiconv库默认的安装路径为/usr/local。现在开始安装libiconv库,如下:

./configure --prefix=/usr/local

make && make install

libiconv库安装完毕后,建议把/usr/local/lib库加入到到/etc/ld.so.conf文件中,然后使用/sbin/ldconfig使其生效。如下:

echo "/usr/local/lib">>/etc/ld.so.conf

/sbin/ldconfig

如果没有进行此步操作的话,在安装php执行make install,系统就会报错。报错信息如下:

/root/php-5.6.2/sapi/cli/php: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory

二、php源码安装

有关php源码安装可以参照《烂泥:php5.6源码安装及php-fpm配置与nginx集成》文章, 下载并编译php命令如下:

wget http://mirrors.sohu.com/php/php-5.6.2.tar.gz

./configure --enable-fpm --enable-mbstring --with-mysql=/usr/local/mysql --with-iconv-dir=/usr/local --with-apxs2=/usr/local/apache2/bin/apxs

注意上述命令中--enable-fpm的作用是开启php的fastcgi功能,即开启php-fpm功能。

--with-mysql=/usr/local/mysql是启用php支持mysql的功能,/usr/local/mysql是mysql数据库的安装路径。

--enable-mbstring表示启用mbstring模块mbstring模块的主要作用在于检测和转换编码,提供对应的多字节操作的字符串函数。目前php内部的编码只支持ISO-8859-*、EUC-JP、UTF-8,其他的编码的语言是没办法在php程序上正确显示的,所以我们要启用mbstring模块。

--with-iconv-dir=/usr/local指定php存放libiconv库的位置。

--with-apxs2=/usr/local/apache2/bin/apxs指定php查找apache的位置。

编译完毕后,我们再来make。在make时,我们注意要加上-liconv参数。如果不加上-liconv参数,系统在make编译会报错。报错信息如下:

Generating phar.php

php-5.3.16/sapi/cli/php: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory

使用命令如下:

make ZEND_EXTRA_LIBS='-liconv'

我们也可以通过修改Makefile文件,在ZEND_EXTRA_LIBS行加入-liconv。如下:

vi Makefile

make install

通过上图,我们可以很明显的看到apache配置文件httpd中启用php支持,同时也把libphp5.so文件复制到apache的模块目录下。

三、配置apache使其支持php

php安装完毕后,我们就可以通过修改apache的配置文件httpd.conf来使其支持php。

我们只需要在httpd.conf文件中加入如下两行代码:

LoadModule php5_module modules/libphp5.so

AddType application/x-httpd-php .php

注意,其中LoadModule php5_module modules/libphp5.so行,我们查看httpd.conf文件时会发现该行已经存在。那是因为在安装php时,添加的。现在我们只需要添加AddType application/x-httpd-php .php行即可。

vi /usr/local/apache2/conf/httpd.conf

除此之外,我们还需要修改apache的默认主页文件,添加index.php。内容如下:

echo "">/usr/local/apache2/htdocs/index.php

cat /usr/local/apache2/htdocs/index.php

四、测试php

以上修改完毕后,我们重新启动apache,使用如下命令:

/etc/init.d/httpd graceful

注意该命令可以优雅的重启apache。

打开站点,如下:

通过上图,我们可以很明显的看到apache已经支持php。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between php5 and php8 What is the difference between php5 and php8 Sep 25, 2023 pm 01:34 PM

The differences between php5 and php8 are in terms of performance, language structure, type system, error handling, asynchronous programming, standard library functions and security. Detailed introduction: 1. Performance improvement. Compared with PHP5, PHP8 has a huge improvement in performance. PHP8 introduces a JIT compiler, which can compile and optimize some high-frequency execution codes, thereby improving the running speed; 2. Improved language structure, PHP8 introduces some new language structures and functions. PHP8 supports named parameters, allowing developers to pass parameter names instead of parameter order, etc.

How to change port 80 in php5 How to change port 80 in php5 Jul 24, 2023 pm 04:57 PM

How to change port 80 in php5: 1. Edit the port number in the Apache server configuration file; 2. Edit the PHP configuration file to ensure that PHP works on the new port; 3. Restart the Apache server, and the PHP application will start running on the new port. run on the port.

How to solve the problem that php5 is not listening on port 9000 How to solve the problem that php5 is not listening on port 9000 Jul 10, 2023 pm 04:01 PM

Solution steps for php5 not listening to port 9000: 1. Check the PHP-FPM configuration file; 2. Restart the PHP-FPM service; 3. Turn off the firewall or configure port forwarding; 4. Check whether other processes occupy port 9000.

What is the difference between php7 and php5 syntax What is the difference between php7 and php5 syntax Jul 10, 2023 pm 03:25 PM

The syntax differences between php7 and php5 are: 1. PHP7 introduces strict type declarations, while the type of PHP5 variables is implicit; 2. PHP7 introduces support for scalar type declarations, but PHP5 does not; 3. PHP7 introduces NULL Merge operator, while PHP5 checks whether a variable exists and is not null, you need to use a conditional statement; 4. PHP7 adds a new comparison operator "<=>", but PHP5 does not; 5. PHP7 introduces a new feature anonymous class , while PHP5 does not.

How to change port 80 in php5 How to change port 80 in php5 Mar 21, 2023 pm 04:32 PM

​If you are a website administrator, you may encounter a situation where you need to change the PHP5 port from the default port 80. This process may be a little hurried, but as long as you follow the steps below, it will be easily completed.

How to solve the problem that php5 is not listening on port 9000 How to solve the problem that php5 is not listening on port 9000 Mar 21, 2023 pm 04:32 PM

When using PHP5, some users may encounter the situation that port 9000 cannot be listened to. At this time, we need to perform some configuration and troubleshooting work to solve this problem.

What are the differences between the version of php7 and 5? What are the differences between the version of php7 and 5? Sep 15, 2023 pm 04:11 PM

The differences between the version of php7 and 5 include performance improvements, scalar type declarations, return value type declarations, exception handling improvements, anonymous classes, syntax improvements, new operators, enhanced error handling and the removal of some old features. Detailed introduction: 1. Performance improvement. PHP7 introduces a new Zend engine, named Zend Engine 3.0, which brings significant performance improvement. The performance of PHP7 is approximately twice that of PHP5, mainly through improved memory management. , optimized function calls and exception handling, enhanced garbage collection, etc.

Discuss the syntax differences between PHP7 and PHP5 Discuss the syntax differences between PHP7 and PHP5 Mar 21, 2023 pm 07:10 PM

PHP is a widely used server-side programming language used to develop dynamic websites and applications. In recent years, the release of PHP7 has attracted some attention. PHP7 has many improvements and optimizations over previous versions (such as PHP5). In this article, we will explore the syntax differences between PHP7 and PHP5.

See all articles