LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
(1)Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。
(2)Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
(3)Mysql是一个小型关系型数据库管理系统。 PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。
(4)这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。
mysql源码编译
需要
mysql-boost-5.7.17.tar.gz
cmake-2.8.12.2-4.el6.x86_64.rpm
yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y
yum install -y gcc gcc-c++ ncurses-devel bison
tart zxf mysql-boost-5.7.17.tar.gz
进入安装目录
cd mysql-5.7.17
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/
make && make install
大概2G(时间大约在半小时左右)
###########################################
注意: #
如果主机曾经装过mysql,则需要删除之前的mysql #
yum remove mysql -y #
userdel -r mysql #
###########################################
cd support-files/
cp mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
cp my-default.cnf /etc/my.cnf
vim /etc/my.cnf
加入
basedir = /usr/local/lnmp/mysql
datadir = /usr/local/lnmp/mysql/data
socket = /usr/local/lnmp/mysql/data/mysql.sock
对mysql服务进行限制(利用mysql用户),将mysql服务的工作空间局限在mysql用户的家目录中,创建mysql组和mysql用户
groupadd -g 27 mysql
useradd -u 27 -g 27 mysql
mkdir /usr/local/lnmp/mysql/data
chown root /usr/local/lnmp/mysql -R
chown mysql.mysql /usr/local/lnmp/mysql/data
将编译生成的mysql二进制命令放进系统的环境变量文件中,保证可以直接调用该二进制命令
vim ~/.bash_profile
PATH最后加:/usr/local/lnmp/mysql/bin
source ~/.bash_profile
mysqld --user=mysql --initialize -----------最后一行会给出数据库初始密码
/etc/init.d/mysqld start--------开启服务
mysql_secure_installation -p''-------------用初始密码登陆
进行初始化 并且重置密码
如果出现套接问题 ps aux |grep mysql 直接kill -9 就好
PHP源码编译
libmcrypt-2.5.8-9.el6.x86_64 libmcrypt-devel-2.5.8-9.el6.x86_64
软件包依赖性:
yum install net-snmp-devel curl-devel libxml2-devel libpng-devel libjpeg-devel freetype-devel gmp-devel openldap-devel -y
yum install libxml2-devel libcurl-devel openssl-devel libmcrypt libmcrypt-devel re2c net-snmp net-snmp-devel -y
tar jxf php-5.3.6.tar.bz2
cd php-5.3.6
./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
make && make install
useradd nginx
cd php-5.6.35
cd php
cd /usr/local/lnmp/php/etc/
cp php-fpm.conf.default php-fpm.conf
修改
pid = run/php-fpm.pid
cp php.ini-production /usr/local/lnmp/php/etc/php.ini
cd sapi/fpm
cp init.d.php-fpm /etc/init.d/php-fpm
修改时区timezone 为 Asia/Shanghai
/etc/init.d/php-fpm start
nginx源码编译
yum install -y pcre-devel
nginx-1.14.0.tar.gz
tar xf nginx-1.14.0.tar.gz
/mnt/lnmp/nginx-1.14.0/auto/cc
#CFLAGS="$CFLAGS -g"
vim src/core/nginx.h
#define NGINX_VERSION "1.0.2”
#define NGINX_VER "nginx" (修改此行, 去掉后面的 “ NGINX_VERSION”,为了安全,这样编译后外界无法获取程序的版本号)
./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio --user=nginx --group=nginx
make && make install
ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/
vim /usr/local/lnmp/nginx/conf/nginx.conf
worker_processes 8;
error_log logs/error.log crit;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
在server{}中
index index.php index.html index.htm;
打开
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.conf;
}
vim /usr/local/lnmp/nginx/html/index.php
<?php
phpinfo()
?>
nginx -t #检测语法
nginx #运行 nginx
nginx -s reload #重载主配置文件
nginx -s stop #关闭 nginx
netstat -antlpe | grep nginx
搭建论坛
yum install unzip -y
unzip Discuz_X3.2_SC_UTF8.zip
mv upload /usr/local/lnmp/nginx/html/bbs
chmod 777 uc_server/ uc_client/ config/ data/ -R
chmod 755 /usr/local/lnmp/mysql/data/
vim /usr/local/lnmp/php/etc/php.ini
pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock
mysql.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
mysqli.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
/etc/init.d/php-fpm reload
172.25.11.1/bbs
即可
创建用户后 使用数据库查询
select * from pre_ucenter_members;