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-fpm
group = www-fpm
配置php-fpm启动服务:
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
PrivateTmp=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系列:
