搭建LNMP (二)

LNMP环境搭建

        个人建站经常使用Wordpress或者Discuz这两个开源软件。而这都需要LNMP基础环境的支持。本文介绍怎么在Centos7下面安装nginx+mysql+PHP

        本文转自我个人的公众号:天目星    ,请大家多多关注。

请关注我的微信公众号


 

 01 前言   

    上期介绍了Nginx跟myslq的安装,现在我们来安装php,搭建好基础环境后我们来尝试搭建我们自己的第一个站点。

 

一、安装PHP

    安装PHP依赖包:

        yum install openssl openssl-devel libxml2 libxslt libxslt-devel libxml2-develbzip2 bzip2-devel libcurl libcurl-devel libpng libpng-devel freetype freetype-devellibmcrypt libmcrypt-devel gmp gmp-devel readline readline-devel libjpeg libjpeg-devel --enable-opcache

 

    前往PHP官网下载:php-7.2.0.tar.gz

    解压软件:

        tar xvf php-7.2.0.tar.gz

    编译:

        ./configure --prefix=/usr/local/php --enable-fpm --enable-bcmath --enable-mbstring --enable-zip --disable-fileinfo --with-libzip --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-curl --with-gd --with-openssl --with-zlib --enable-ftp --with-xmlrpc --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --without-pear


(编译问题小解答:--with-libzip需要libzip版本>=0.11,而centos7自带的版本是0.10的,需要卸载后自行下载源码包编译安装。另外php7不再支持--with-mcrypt;mysql库也使用新的--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd)


        make

        make install

    配置php.ini文件:

        cp php.ini-development /etc/php.ini

    创建php-fpm运行账号:

        groupadd -r -g 310 www-fpm

        useradd -u 310 -g 310 -s /sbin/nologin www-fpm

    配置fpm的conf文件:

        cd /usr/local/php/etc

        cp php-fpm.conf.default php-fpm.conf

        cd /usr/local/php/etc/php-fpm.d

        cp www.conf.default www.conf

    配置php-fpm运行账号:

        vim www.conf

user = www-fpmgroup = www-fpm

    

    配置php-fpm启动服务:

        vim /usr/lib/systemd/system/php-fpm.service

[Unit]Description=php-fpmAfter=network.target[Service]Type=forkingExecStart=/usr/local/php/sbin/php-fpmPrivateTmp=True[Install]WantedBy=multi-user.target

 

        启动fpm:systemctl start php-fpm.service

 

二、通过以上的操作我们已经搭建好lnmp环境,我们写一个phpinfo查看php配置列表。

    配置nginx.conf

        vim /usr/local/nginx/conf/nginx.conf

server {   listen       80;   server_name  localhost;   #charset koi8-r;   #access_log  logs/host.access.log  main;   location / {      root   html;      index  index.php index.html index.htm;   }      error_page   500 502 503 504  /50x.html;   location = /50x.html {       root   html;   }           # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000   location ~ \.php$ {       root           html;       fastcgi_pass   127.0.0.1:9000;       fastcgi_index  index.php;       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;       include        fastcgi_params;   }

 

    在$document_root目录下新增index.php

<?php  phpinfo();?>

    

    启动NMP服务:

        service mysql.service start

        systemctl start php-fpm.service

        systemctl start nginx.service

 

    打开浏览器访问:

        网址:http://<Your IP Address>/index.php


 

    请大家多多关注,后续使用Wordpress或者Discuz搭站。

 

LNMP系列:

1)搭建LNMP(一)

2)搭建LNMP(二) 

3)搭建LNMP (三) --搭建wordpress站点

 

请关注我的个人公众号

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值