Centos7安装PHP及Nginx的教程详解

2019-01-16 21:07:18丽君

然后通过一下命令编译:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts -with-mcrypt=/usr/include --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --enable-ftp --enable-session --with-gettext --with-jpeg-dir --with-freetype-dir --enable-fastcgi --without-gdbm --disable-fileinfo

然后通过以下命令完成最后的编译安装:

make && make install

如果安装过程提示有错误或者依赖就需要根据具体的情况去解决,至此我们可以通过php -v命令查看是否成功安装。

注:如果查看的版本和自己安装版本不一致,可以查找提示的版本文件在哪个位置,然后删除,也可以不用管。之后我们在通过修改环境变量的方式指向我们安装的文件目录,操作方式如下:

首先编辑环境变量文件: vim /etc/profile

文件末尾加上  export PATH="/usr/local/php/bin:$PATH"

其中"/usr/local/php/bin"为你安装的具体路径,保存退出后,执行以下更改即可,执行命令:

source /etc/profile

这个时候我们再次使用php -v查看当前版本就可以看到我们所安装的版本号了。

二、安装Nginx

Nginx作为除apache外最主流的服务器软件了,因此安装Ngix也是一种基本配置了,编译安装的方式均类似:

第一步、检查安装相关依赖包

yum -y install gcc gcc-c++ autoconf automake make yum -y install zlib zlib-devel openssl yum -yinstallopenssl-devel pcre pcre-devel

第二步、前往nginx官网找到你想要安装的版本链接,官网地址:http://nginx.org/download/,如下图所示:

Nginx版本列表

复制相应的版本链接,进入上面的操作目录,/usr/local进行操作

进入目录: cd /usr/local

下载文件: wget http://nginx.org/download/nginx-1.8.0.tar.gz

解压文件: tar -zxvf nginx-1.8.0.tar.gz

进入解压后文件目录: cd nginx-1.8.0