编译安装php
1. 安装remi扩展源
```
yum install epel-release
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
```
2. 安装yum管理工具
```
yum install yum-utils
```
3. 查找是否有php74
```
yum search php74
```
4. 确认安装结果
```
yum list installed | grep php
```
5. 安装
```
yum install -y php74-php-fpm php74-php-cli php74-php-bcmath php74-php-gd php74-php-json php74-php-mbstring php74-php-mcrypt php74-php-mysqlnd php74-php-opcache php74-php-pdo php74-php-pecl-crypto php74-php-pecl-mcrypt php74-php-pecl-geoip php74-php-recode php74-php-snmp php74-php-soap php74-php-xmll php74-php-ldap
```
6. 建立软连接,通过remi安装的php的指令是php74,这里建立一下软链接
```
ln -s /opt/remi/php74/root/usr/bin/php /usr/local/bin/php
```
7. 查看php版本
```
php -v
```
```
启动
systemctl start php74-php-fpm
开机自启
systemctl enable php74-php-fpm
```
二进制部署
## centso
安装依赖
```
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libzip-devel pcre-devel sqlite-devel bzip2 bzip2-devel libxslt-devel openldap openldap-devel autoconf gd mhash mhash-devel php-mysqlnd readline readline-devel
```
```
yum install https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-6.8.2-2.el7.x86_64.rpm
yum install https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-devel-6.8.2-2.el7.x86_64.rpm
```
## ubuntu
安装依赖
```
sudo apt-get install libxml2-dev build-essential openssl libbz2-dev libssl-dev make curl libcurl4-gnutls-dev libjpeg-dev libpng-dev sqlite3 libsqlite3-dev libmcrypt-dev libfreetype6-dev libzip-dev
```
下载php7.4压缩包
```
https://www.php.net/distributions/php-7.4.0.tar.gz
```
解压压缩包,cd进入解压后的目录
```
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-curl --enable-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xmlrpc --with-xsl --with-zlib --with-ldap --with-bz2 --with-jpeg --with-freetype --with-mhash --enable-fpm --enable-bcmath --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-fpm
```
编译
```
make
```
安装
```
make install
```
配置php-fpm
```
cp php.ini-production /usr/local/php/etc/php.ini #配置文件php.ini位置
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp /sapi/fpm/init.d.php-fpm /usr/local/php/bin/php-fpm
```
php-fpm服务化
```
vim /usr/local/php/etc/php-fpm.conf
```
找到以下内容并修改:
```
; Pid file
; Note: the default prefix is /usr/local/php/var
; Default Value: none
pid = /var/run/php-fpm.pid
```
vim /etc/systemd/system/php.service
```
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
```
systemctl daemon-reload
systemctl start php
apache支持php,安装php是加入--with-apxs2=/usr/local/httpd/bin/apxs 这个参数进行编译
```
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/etc/apache/bin/apxs --with-curl --enable-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-mysqli --with-ldap --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-fpm
```
安装完成之后需要配置一下APACHE的配置文件
```
vi /etc/apache/conf/httpd.conf
```
找到 AddType 的地方添加一行
```
AddType application/x-httpd-php .php(注意空格!!!!!!!)
AddType application/x-httpd-php-source .phps
另外要显示中文的话,
修改:
AddDefaultCharset gb2312
```
找到 DirectoryIndex index.html
```
在index.html 添加一个index.php或者default.php
```
重启apache
隐藏版本号(找到php.ini)
vim php.ini
```
expose_php = Off
```
完成
如果缺少某模块lddp到源码安装目录,编译安装即可
```
cp -frp /usr/lib64/libldap* /usr/lib/ #重要,不然要报错
cd /opt/php-7.4.0/ext/ldap/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-ldap
make
make install
```
在配置文件里添加
vim /usr/local/php/etc/php.ini
```
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/ldap.so
```
重启php即可