LNMP为运行动态网站或服务器的架构,由Linux,Nginx,Mysql,PHP组成,其中的Mysql也可为MariaDB,PHP也可为Python。
rhel 6.5
服务器IP:172.25.69.11
本地测试主机IP:172.25.69.250
方法一:通过配置的yum源进行安装
方法二:下载源码包,通过源码编译进行安装
以下介绍方法二的实现
(1)将下载的PHP源码包解压
命令:tar jxf php-5.6.35.tar.bz2
(2)源码编译和安装
configure脚本执行:(添加安装选项)
./configure --prefix=/usr/local/lnmp/php \
--with-config-file-path=/usr/local/lnmp/php/etc \
--with-openssl \
--with-snmp \
--with-gd \
--with-zlib \
--with-curl \
--with-libxml-dir \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-gmp \
--with-gettext \
--with-pear \
--enable-mysqlnd \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-inline-optimization \
--enable-soap \
--enable-ftp \
--enable-sockets \
--enable-mbstring \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-mcrypt \
--with-mhash
其中可能遇到以下错误
error: xml2-config not found. Please check your libxml2 installation.
安装libxml2-devel.x86_64
error: Cannot find OpenSSL's
安装openssl-devel
error: Please reinstall the libcurl distribution -
easy.h should be in
安装:libcurl-devel-7.19.7-37.el6_4.x86_64
If configure fails try --with-vpx-dir=
安装:libjpeg-turbo-devel-1.2.1-1.el6.x86_64
If configure fails try --with-vpx-dir=
If configure fails try --with-vpx-dir=
安装:libpng-devel-1.2.49-1.el6_2.x86_64
If configure fails try --with-vpx-dir=
If configure fails try --with-xpm-dir=
安装:freetype-devel
configure: error: Unable to locate gmp.h
安装:gmp-devel-4.3.1-7.el6_2.2.x86_64
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
安装:libmcrypt和libmcrypt-devel (这两包可能在yum源中不存在,需要单独下载)
error: Could not find net-snmp-config binary. Please check your net-snmp installation.
安装:net-snmp-devel-5.5-49.el6.x86_64
configure 完成后使用make && make install
(3)进入安装目录下的配置文件目录
路径:/usr/local/lnmp/php/etc
将解压包下的默认配置文件(php.ini-production)拷贝至当前位置修改名称为php.ini
编辑该文件设定时区
date.timezone = Asia/Shanghai
(4)设置启动脚本
将安装目录下的启动脚本拷贝至/etc/init.d
启动脚本路径:/usr/local/lnmp/php/sbin/php-fpm
方法一:下载官方rpm包进行安装
方法二:下载源码包,根据自行设定进行安装
以下介绍方法二
(1)将下载的源码进行解压
命令: tar zxf nginx-1.16.0.tar.gz
(2)源码编译和安装
关闭debug日志
路径:/root/nginx-1.16.0/auto/cc/gcc
隐藏版本号
路径:/root/nginx-1.16.0/src/core/nginx.h
configure脚本执行
./configure --prefix=/usr/local/lnmp/nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-threads \
--with-file-aio \
--user=nginx \
--group=nginx
其中可能遇到缺少pcre,安装pcre-devel即可
configure完成后执行make && make install
(3)进入安装目录下的配置文件目录
编辑配置文件:/usr/local/lnmp/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;
}
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
(4)测试是否能访问php发布文件
发布文件目录:/usr/local/lnmp/nginx/html/index.php(发布文件由个人编写)
方法一:下载官方rpm包进行安装
方法二:下载源码包,根据自行设定进行安装
以下介绍方法二
(1)将下载的源码进行解压
命令: tar zxf mysql-boost-5.7.17.tar.gz
(2)源码编译和安装
在执行cmake脚本前先进行安装以下组件:cmake,ncurses-devel,gcc-c++.x86_64,bison
cmake脚本执行:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \、
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all \
-DWITH_BOOST=boost/boost_1_59_0/
若出现问题,安装所需软件后需删除CMakeCache.txt,再执行cmake
完成后执行make && make install
(3)配置Mysql
复制默认配置文件:/usr/local/lnmp/mysql/support-files 至/etc/my.cnf并编辑
basedir =/usr/local/lnmp/mysql #Mysql安装目录
datadir =/usr/local/lnmp/mysql/data #Mysql的数据目录
socket =/usr/local/lnmp/mysql/data/mysql.sock
新建mysql用户组,组号为27,并创建mysql用户
groupadd -g 27 mysql
useradd -u 27 -g 27 mysql
修改安装目录下的所属组
chgrp mysql /usr/local/lnmp/mysql -R
chown mysql data -R
(4)执行Mysql配置初始化文件
可将生成的二进制命令目录放入系统环境变量文件中,方便使用
编辑:~/.bash_profile
添加/usr/local/lnmp/mysql/bin
重新加载文件source ~/.bash_profile
初始化Mysql初始化文件
命令:/usr/local/lnmp/mysql/bin/mysqld --user=mysql --initialize
由图可得LkSHtzwlc2(?为root用户初始化密码
开启mysql
命令:/etc/init.d/mysqld start
Mysql的安全初始化
./mysql_secure_installation
Enter password for user root: #输入原root密码
New password: #设置新密码
Re-enter new password:
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
#是否添加验证密码插件
Press y|Y for Yes, any other key for No:
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) :
#是否修改root密码
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
#是否移除匿名用户
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
#是否允许匿名用户远程登陆
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
#是否移除测试数据库
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
#是否重新加载数据库
(1)在php配置文件添加mysql.socket
配置文件:/usr/local/lnmp/php/etc/php.ini
(2)将Discuz解压至Nginx发布目录下
访问该路径并进行安装
若出现以下错误
进入解压后的目录修改权限
选择全新安装
设置安装的数据库信息及管理员
安装成功