centos 7.2 搭建 lnmp

1、安装最新nginx源

yum install epel-release

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

2、安装nginx

yum install -y nginx

3、启动nginx

service nginx start

4、设置nginx开机启动

systemctl enable nginx.service

5、查看nginx是否开机启动

systemctl list-dependencies | grep nginx

 

安装php

 

添加CentOS 7的epel及remi源。

# yum install epel-release
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

 

以及CentOS 6.5的epel及remi源。

# rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

 

安装PHP5.6

yum源配置好了,下一步就安装PHP5.6。

# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

 

php -v 查看php版本

 

下载源码

  1. 打开php.net官网下载php 5.6.31源码

  2. 执行命令: wget http://cn2.php.net/distributions/php-5.6.31.tar.gz

  3. 解压php源码: tar zxvf php-5.6.31.tar.gz

  4. 进入解压源码目录: cd php-5.6.31

安装php需要的软件

yum install -y gcc gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel curl curl-devel libxslt-devel openssl-devel

注意如果软件包安装了就从安装列表去掉

编译(安装)配置

在php-5.6.31目录执行以下命令(安装php到/usr/local/php目录):

./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysql --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-sockets --enable-sysvsem --enable-xml --enable-zip

 

如果这步出错,就按照错误百度一步步解决(一般都是缺少相应的软件包造成的错误

编译php源码

 编译源码只需要执行命令: make

安装php源码

 安装源码只需要执行命令: make install

 

原文摘自 :https://jingyan.baidu.com/article/2d5afd692df18d85a3e28e4c.html

 

安装php 的第二种方法

 

配置yum源

# yum install epel-release
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

使用yum list命令查看可安装的包(Packege)。

# yum list --enablerepo=remi --enablerepo=remi-php56 | grep php

安装PHP5.6

yum源配置好了,下一步就安装PHP5.6。

# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

用PHP命令查看版本。

# php --version










yum -y install gcc gcc-c++ autoconf automake

yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel (安装依赖zlib、openssl和pcre)




wget http://nginx.org/download/nginx-1.12.2.tar.gz

tar -zxvf nginx-1.12.2.tar.gz

cd nginx-1.12.2

./configure --prefix=/usr/local/nginx

make

makeinstall

cd ../../usr/local/nginx/sbin/

./nginx 启动


安装php

在php.net 获取想要版本的php下载地址

wget http://cn2.php.net/get/php-5.6.34.tar.gz/from/this/mirror



tar -zxvf mirror

yum install libxml2 -y

yum install libxml2-devel -y

编译时为 php 添加 php-fpm 扩展
./configure --prefix=/usr/local/php56 --enable-fpm

make

make install

启动php-fpm(会报错没有php-fpm.conf)

mv php-fpm.conf.default php-fpm.conf


配置nginx 使用php-fpm

vim nginx.conf


添加此段代码使nginx 处理时交由php-fpm 解析

location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;

include /usr/local/nginx/conf/fastcgi_params;

fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

 

在 usr/locl/nginx/html  创建test.php 文件并使用 ip地址/test.php访问,访问成功即成功









 

posted @ 2018-03-17 00:51  一个一个人  阅读(118)  评论(0编辑  收藏  举报