centos7 离线安装PHP及PHP相关扩展
2017-12-21 14:07
393 查看
1、安装PHP7
下载地址 http://hk1.php.net/get/php-7.2.0.tar.gz/from/this/mirror下载php7(php-7.1.12.tar.gz)包导入centos7 /data/rj
2.解压包
tar -zxvf php-7.1.12.tar.gz3.安装php 之前需要安装mcrypt
1).下载Libmcrypt,mhash,mcrypt安装包
libmcrypt-2.5.8.tar.gz#http://sourceforge.net/project/showfiles.php?group_id=87941&package_id=91774&release_id=487459
mhash-0.9.9.tar.gz
#http://sourceforge.net/project/showfiles.php?group_id=4286&package_id=4300&release_id=645636
mcrypt-2.6.8.tar.gz
# http://sourceforge.net/project/showfiles.php?group_id=87941&package_id=91948&release_id=642101
2) .先安装Libmcrypt
tar -zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8
###/usr/local/php5/bin/phpize #动态编译php模块,使其可以使用configure编译。
./configure
make
make install # libmcript默认安装在/usr/local
3).安装mhash
tar -zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9
./configure
make
make install
4).安装mcrypt
tar -zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8
./configure
make
make install
注: 可能会出现的错误 configure: error: *** libmcrypt was not found解决方案
()安装到mcrypt的时候出现了问题
./configure
提示出错,首先提示
*** Could not run libmcrypt test program, checking why…
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means LIBMCRYPT was incorrectly installed
*** or that you have moved LIBMCRYPT since it was installed. In the latter case, you
*** may want to edit the libmcrypt-config script: no
configure: error: *** libmcrypt was not found
找了相关资料,得出解决方法明明我安装了libmcrypt 2.5.8 ,可是竟然提示没有发现!然后在/usr/local/bin/找到了LIBMCRYPT_CONFIG ,这一步明确了是PATH变量的问题 !
方法是ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config
之后继续进行./configure
仍然报错:
*** Could not run libmcrypt test program, checking why…
*** The test program compiled, but did not run. This usually means
*** that the run-time linker is not finding LIBMCRYPT or finding the wrong
*** version of LIBMCRYPT. If it is not finding LIBMCRYPT, you’ll need to set your
*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point
*** to the installed location Also, make sure you have run ldconfig if that
*** is required on your system
***
*** If you have an old version installed, it is best to remove it, although
*** you may also be able to get things to work by modifying LD_LIBRARY_PATH
***
configure: error: *** libmcrypt was not found
继续查找,还是变量的问题
解决方法如下:运行
export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
然后make ; make install
完成
4.下载php及PHP扩展相关的包
这里需要的包很多就不一一列出了, 可以查看我的链接链接: https://pan.baidu.com/s/1hsriqg8 密码: uhky
也可以通过centos的镜像包中查找相关的rpm包
将已下载的相关包放到/data/other
rpm -Uvh /data/other/*.rpm --nodeps --force
注:--nodeps就是安装时不检查依赖关系,比如你这个rpm需要A,但是你没装A,这样你的包就装不上,
用了--nodeps你就能装上了。--force就是强制安装,比如你装过这个rpm的版本1,如果你想装这个
rpm的版本2,就需要用--force强制安装
5. 切换到 php7解压包后的目录
cd php-7.1.12如果已安装mysql 可以加 --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr/bin/mysql
./configure --prefix=/usr/local/php7 --with-config-file-path=/etc --with-bz2 --with-curl --with-gd --with-openssl -with-gettext --with-xsl --with-zlib-dir --enable-pcntl --enable-sockets --enable-calendar --enable-exif --enable-ftp --enable-mbstring
--enable-fpm --enable-zip --with-mcrypt --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr/bin/mysql
其中:###
--prefix=/usr/local/php7 将php7安装到指定目录
--enable-fpm 编译 PHP 时需要 --enable-fpm 配置选项来激活 FPM 支持。
如果安装mysql
--with-mysqli=--with-mysqli=/usr/bin/mysql_config(查看mysql_config位置)
--with-pdo-mysql=/usr/bin/mysql(查看mysql安装位置)
####
出现(Thank you for using PHP.即为成功)
make (如果看到Don't forget to run 'make test' 编译成功)
make install
6. 测试PHP安装是否成功
cdvi test.php
<?php
phpinfo();
使用PHP命令执行test.php文件
/usr/local/php7/bin/php test.php
cd /usr/local/php7/bin/
./php -m 查看PHP已安装的扩展包
配置环境变量
将 PHP放入环境变量才能执行 php xxx.php 否则执行php为 /usr/local/php7/bin/php test.phpvi /etc/profile
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
export PATH=$PATH:/usr/local/php7/bin
保存后
source /etc/profile
php -v
php -m
重启nginx
systemctl restart nginx
配置PHP
cp php.ini-production /usr/local/php7/etc/php.inivi /usr/local/php7/etc/php.ini
zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/opcache.so
复制php-fpm.conf
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
vim /usr/local/php7/etc/php-fpm.conf
把pid 改成 /run/php-fpm.pid
编辑php-fpm配置www.conf会加载在php-fpm.conf中
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
加php-fpm管理器到systemctl中
vi /usr/lib/systemd/system/php-fpm.service[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
保存退出
重启php
systemctl start php-fpm.service
systemctl enable php-fpm.service
systemctl is-enabled php-fpm.service
systemctl指令
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl is-enabled *.service #服务是否开机运行
systemctl start *.service #启动服务
systemctl stop *.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl --failed #显示启动失败的服务
可以查看:http://bbs.qcloud.com/thread-9907-1-1.html
修改php.ini
vi /usr/local/php7/etc/php.iniexpose_php=Off ##为了防止黑客获取服务器中php版本的信息,可以关闭该信息斜路在h
4000
ttp头中
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE
相关文章推荐
- PHPWAMP安装Redis扩展的方式与相关扩展的下载
- 源码编译安装PHP以及相关扩展的安装
- 浅析PHP安装扩展mcrypt以及相关依赖项(PHP安装PECL扩展的方法)
- CentOs7用phpize安装mcrypt扩展时遇到错误
- Centos7 安装redis 和 phpredis扩展
- centos7下安装mongodb和php扩展mongodb
- PHP安装扩展mcrypt以及相关依赖项 【PHP安装PECL扩展的方法】
- centos7 安装memcached和php-memcached扩展以及memcached使用方式
- 【PHP7.1】linux centos7 安装phpredis扩展
- centos7安装php的zip扩展
- centos7下面php5.6添加postgresql相关扩展【试行】
- centos7 离线安装redis 及PHP扩展redis
- PHP 生成、识别二维码及安装相关扩展/工具
- centos7安装redis3.0以及phpredis扩展
- Redhat6.2下安装 nginx php mysql memcached mongoDB及相关扩展
- linux连接mssql数据库,在Centos7下为PHP安装mssql扩展
- CentOS7安装redis数据库及php-redis扩展
- Centos7安装php-redis扩展
- Centos7 用yum命令安装LAMP环境(php+Apache+Mysql)以及php扩展
- PHPWAMP安装Redis扩展的方式与相关扩展的下载