Home php教程 php手册 烂泥:php5.6源码安装及php

烂泥:php5.6源码安装及php

Jun 06, 2016 pm 07:52 PM
php php5.6 Install Source code

本文由 秀依林枫 提供友情赞助,首发于 烂泥行天下 。 LNMP环境的搭建中,现在只有php没有源码安装过。这篇文章就把这个介绍下。 注意本篇文章使用的centos 6.5 64bit。 登陆centos下载php5.6的安装包。php的软件包可以去国内的souhu镜像站点去下载。 wget h

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

LNMP环境的搭建中,现在只有php没有源码安装过。这篇文章就把这个介绍下。

注意本篇文章使用的centos 6.5 64bit。

登陆centos下载php5.6的安装包。php的软件包可以去国内的souhu镜像站点去下载。

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

烂泥:php5.6源码安装及php

在安装之前,我们需要安装php5.6编译时所依赖的软件包。如下:

yum -y install gcc gcc-c++ libxml2 libxml2-devel

烂泥:php5.6源码安装及php

烂泥:php5.6源码安装及php

以上软件包安装完毕后,我们现在来解压刚刚下载的php5.6源码包。使用如下命令:

tar -xf php-5.6.2.tar.gz

烂泥:php5.6源码安装及php

进入php5.6的解压目录,现在开始配置php5.6,使用如下命令:

cd php-5.6.2

./configure --enable-fpm --enable-mbstring --with-mysql=/usr/local/mysql

烂泥:php5.6源码安装及php

如果没有错误的情况下,配置完毕后。系统会出现如下的提示信息:

烂泥:php5.6源码安装及php

注意上述命令中--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模块。

同时我们也只是简单的开启和扩展php的一部分功能,其他需要的功能,请自行添加。

配置完毕后,我们现在来编译php,使用make命令,如下:

make

烂泥:php5.6源码安装及php

php编译的时间比较长,根据机器的性能不同需要等待10-20分钟左右。编译完毕后的截图,如下:

烂泥:php5.6源码安装及php

编译完毕后,我们现在开始安装php,使用如下命令:

make install

烂泥:php5.6源码安装及php

安装完毕后,我们可以通过php –v命令查看是否安装成功。如下:

php –v

烂泥:php5.6源码安装及php

通过这样安装完毕后,你会发现在/usr/local/lib目录下没有php.ini文件。在这我们就先复制php安装文件提供的模版,如下:

cp php.ini-production /usr/local/lib/php.ini

烂泥:php5.6源码安装及php

注意php.ini文件一般在/usr/local/lib/和/etc目录下。有关php安装完毕后,没有php.ini文件的,我们再另外一篇文章再介绍。

不要以为到这php的安装就完毕了,LNMP环境中的nginx是不支持php的,需要通过fastcgi来处理有关php的请求。而php需要php-fpm这个组件来支持。

在php5.3.3以前的版本php-fpm是以一个补丁包的形式存在的,而php5.3.3以后的php-fpm只需要在安装php-fpm开启这个功能即可。这个也就是前边,我们再配置php使用到的那个命令--enable-fpm。

php-fpm功能开启后,我们还需要配置php-fpm。其实php-fpm的配置文件在安装php时,已经为我们提供了一个配置文件的模版。该模版为/usr/local/etc/php-fpm.conf.default,如下:

more /usr/local/etc/php-fpm.conf.default

烂泥:php5.6源码安装及php

我们现在只需要复制一份该文件,并重命名为php-fpm.conf,如下:

cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf

烂泥:php5.6源码安装及php

为了让php-fpm已服务的形式启动。我们需要复制php安装目录下/sapi/fpm/init.d.php-fpm文件。如下:

cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

烂泥:php5.6源码安装及php

通过上图,我们也可以很清楚的看到php-fpm文件目前没有执行权限。赋予php-fpm执行权限,并启动php-fpm,如下:

chmod a+x /etc/init.d/php-fpm

/etc/init.d/php-fpm start

netstat -tunlp |grep 9000

烂泥:php5.6源码安装及php

通过上图,我们可以很明显的看到php-fpm已经正常启动。

注意php-fpm默认监听的是9000端口。

现在再来配置nginx,使其支持php,如下:

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

烂泥:php5.6源码安装及php

然后在nginx的网站根目录下新建index.php文件内容如下:

vi /usr/local/nginx/html/index.php

烂泥:php5.6源码安装及php

现在来启动nginx,如下:

/usr/local/nginx/sbin/nginx

netstat -tunlp |grep 80

烂泥:php5.6源码安装及php

nginx启动完毕后,现在来访问网站,如下:

烂泥:php5.6源码安装及php

烂泥:php5.6源码安装及php

通过上图,我们可以很明显的看到。php目前已经安装成功,并且也成功的支持mysql数据库。同时也与nginx集成完毕。

至此。我们的php5.6的安装到此结束。

 

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 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)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

See all articles