一、 介绍
微擎是一家开源的公众平台 SAAS 领域技术服务提供商,成立于 2013 年 7 月,总部位于安徽宿州。微擎是免费开源的公众平台管理系统,拥有近百万的注册用户数,开发者认证超 20,000 名,3,000 + 款应用插件,10,000 + 应用场景,服务规模超 200,000 家,直接间接服务用户过亿 -- 百度百科
二、搭建 LNMP 环境
-
查看 wget 是否安装
`rpm -qa wget` 没有则安装 `yum install wget`
-
查看是否安装编译器
`rpm -qa gcc` 没有则安装 `yum install gcc gcc-c++`
安装 Nginx
- 安装 Nginx 依赖:
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
- 下载并解压 Nginx:
cd /usr/local/src
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
- 编译安装 Nginx:
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx
make
make install
- 创建 nginx 账号:
groupadd nginx
useradd -M -g nginx -s /sbin/nologin nginx
cd /usr/local/nginx/conf
vim nginx.conf
将第一行 user 改为: user nginx nginx
完成后执行命令 /usr/local/nginx/sbin/nginx -t
ESC+:wq+Enter 退出并保存
- 启动 Nginx:
/usr/local/nginx/sbin/nginx
,浏览器输入服务器公网 IP,出现 Welcome to nginx! 则启动成功 安装 MySQL
- 下载并应用 MySQL 的 yum 资源包:
cd ~
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
yum install mysql-server
-
改变文件属主和属组:
`chown mysql:mysql -R /var/lib/mysql`
-
初始化并启动 MySQL:
`mysqld --initialize` `service mysqld start`
-
修改密码并登陆 MySQL:
`mysqladmin -u root password "your-password"` `mysql -u root -p` 输入密码登陆,出现`mysql>`则成功
- 安装 PHP
- 安装 PHP 依赖:
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
-
下载 PHP:
`wget https://www.php.net/distributions/php-7.3.21.tar.gz` `tar -zxvf php-7.3.21.tar.gz`
编译安装:
cd php-7.3.21
./configure --prefix=/usr/local/php --disable-fileinfo --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --with-curl --enable-ftp --with-gd --with-xmlrpc --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-mbstring --with-mcrypt=/usr/local/libmcrypt --enable-zip --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --without-pear --enable-bcmath
make
make install
-
移动 PHP 配置文件:
`cp php.ini-development /etc/php.ini`
配置 php-fpm 运行账号:
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d
cp www.conf.default www.conf
vim www.conf
将其中的user=nobody
和group=nobody
改为user=nginx
和group=nginx
- 使 Nginx 支持 PHP
- 修改配置文件:
vim /usr/local/nginx/conf/nginx.conf
#location ~ .php$ {
# root html;
# fastcgi\_pass 127.0.0.1:9000;
# fastcgi\_index index.php;
# fastcgi\_param SCRIPT\_FILENAME /scripts$fastcgi\_script\_name;
# include fastcgi\_params;
#}
将其中的改为注释取消,ESC+:wq+Enter 退出并保存
-
将 Nginx 添加到系统服务:
`vim /etc/init.d/nginx` 内容为:
#!/bin/sh
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
\[ "$NETWORKING" = "no" \] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX\_CONF\_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
\[ -x $nginx \] || exit 5
\[ -f $NGINX\_CONF\_FILE \] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX\_CONF\_FILE
retval=$?
echo
\[ $retval -eq 0 \] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
\[ $retval -eq 0 \] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force\_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX\_CONF\_FILE
}
rh\_stlatus() {
status $prog
}
rh\_status\_q() {
rh\_status >/dev/null 2>&1
}
case "$1" in
start)
rh\_status\_q && exit 0
$1
;;
stop)
rh\_status\_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh\_status\_q || exit 7
$1
;;
force-reload)
force\_reload
;;
status)
rh\_status
;;
condrestart|try-restart)
rh\_status\_q || exit 0
;;
\*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
chmod 755 /etc/init.d/nginx
chkconfig –add nginx
-
重启 Nginx:
`service nginx restart`
- 设置 php-fpm 为系统服务:
-
添加配置文件:
`vim /etc/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
ESC+:wq+Enter 退出并保存
- 设置 php-fpm 开机自启并启动 php-fpm:
-
设置 php-fpm 开机自启动:
`systemctl enable php-fpm.service`
-
启动 php-fpm:
`systemctl start php-fpm.service`
-
查看启动是否成功:
`ps aux | grep php-fpm`
三、搭建微擎
- 创建站点:
-
创建 Nginx 配置文件
`mkdir -p /usr/local/nginx/vhost/weengine` `vim /usr/local/nginx/vhost/vhost_weengine.conf` 内容为:
server {
listen 80;
server\_name localhost;
#charset koi8-r;
#access\_log logs/host.access.log main;
location / {
root vhost/weengine;
index index.html index.htm;
}
#error\_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error\_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy\_pass http://127.0.0.1;
#}
# 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 /usr/local/nginx/vhost/weengine$fastcgi\_script\_name;
include fastcgi\_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /.ht {
# deny all;
#}
}
vim /usr/local/nginx/conf/nginx.conf
修改nginx默认端口listen 800;
include /usr/local/nginx/vhost/\*.conf;
vim /usr/local/nginx/conf/nginx.conf
在 http{} 代码块最后添加
include /usr/local/nginx/vhost/*.conf;
重启 nginx
service nginx restart
-
下载并解压微擎
`cd /usr/local/nginx/vhost/weengine` `wget https://cdn.w7.cc/download/WeEngine-Laster-Online.zip` `unzip https://cdn.w7.cc/download/WeEngine-Laster-Online.zip`
- 配置微擎
- 浏览器输入公网 IP/install.php 按提示一步步配置即可
参考文章:
LNMP 环境搭建 (linux+Nginx + Mysql + PHP)
service nginx start|stop|reload 报错:Failed to reload nginx.service: Unit not found.【解决方案】