
(图片来源网络,侵删)
作为一名LINUX爱好者,我们经常需要在服务器上安装各种软件。而对于PHP开发者来说,PHP是必不可少的一种语言。虽然CentOS系统自带了PHP,但是版本较老,而且有些功能不支持。我们需要手动安装最新版本的PHP。本文将介绍CentOS下PHP源码安装的详细步骤。
在安装PHP前,我们需要先安装一些编译工具和依赖库,以便后续编译过程中使用。可以通过以下命令进行安装:
“`
yum install -y gcc gcc-c++ make autoconf libtool-ltdl-devel gd-devel
freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel
curl-devel libmcrypt-devel bzip2-devel readline-devel libxslt-devel
我们可以从PHP官网上下载最新的PHP源码包,也可以从镜像站点上下载。下载完成后,我们将源码包解压到/usr/local目录下。
cd /usr/local
tar -zxvf php-x.x.x.tar.gz
在编译前,我们需要先配置一些选项,以便编译出我们需要的PHP版本。我们可以通过以下命令进行配置:
cd php-x.x.x
./configure –prefix=/usr/local/php
–with-config-file-path=/usr/local/php/etc
–enable-fpm
–enable-mysqlnd
–with-mysqli=mysqlnd
–with-pdo-mysql=mysqlnd
–with-iconv-dir
–with-freetype-dir
–with-jpeg-dir
–with-png-dir
–with-zlib
–with-libxml-dir=/usr
–enable-xml
–disable-rpath
–enable-bcmath
–enable-shmop
–enable-exif
–enable-sysvsem
–enable-inline-optimization
–with-curl
–enable-mbregex
–enable-mbstring
–with-mcrypt
–enable-ftp
–with-gd
–enable-gd-native-ttf
–with-openssl
–with-mhash
–enable-pcntl
–enable-sockets
–with-xmlrpc
–enable-soap
–enable-short-tags
–enable-static
–with-xsl
–with-fpm-user=www
–with-fpm-group=www
–enable-ctype
–enable-json
–enable-zip
–with-bz2
配置好选项后,我们就可以开始编译和安装了。可以使用以下命令进行编译和安装:
make && make install
编译过程可能需要一些时间,请耐心等待。
安装完成后,我们需要对PHP进行一些配置。可以使用以下命令进行配置:
cp php.ini-development /usr/local/php/etc/php.ini
我们需要修改php.ini文件,以便PHP能够正常运行。可以使用以下命令进行修改:
vi /usr/local/php/etc/php.ini
我们需要将以下几个选项进行修改:
date.timezone = Asia/Shanghai
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = On
PHP-FPM是一个PHP FastCGI进程管理器,它可以提高PHP的性能和稳定性。我们需要启动PHP-FPM,可以使用以下命令进行启动:
/usr/local/php/sbin/php-fpm
我们需要对Nginx进行一些配置,以便它能够和PHP-FPM一起工作。可以使用以下命令进行配置:
vi /etc/nginx/nginx.conf
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
为大家分享一个Ubuntu小知识:在Ubuntu中,可以使用“Ctrl + Alt + T”快捷键打开终端窗口,非常方便。




