LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python。
下一章我们会在lnmp环境的基础上搭建wordpress(个人博客)
源码安装nginx
首先在根目录递归创建/data/server
mkdir -p /data/server
下载依赖包
yum -y install openssl openssl-devel zlib zlib-devel pcre pcre-devel
下载gcc编译器
yum -y install gcc gcc-c++
下载nginx包
wget http://nginx.org/download/nginx-1.16.0.tar.gz
解压nginx
tar -zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
探测目标环境生成makefile
./configure --prefix=/data/server/nginx
编译
make && make install
开启nginx
cd /data/server/nginx/sbin
./nginx
查看是否运行
ps aux | grep nginx
运行成功
源码安装php
下载依赖包
yum -y install openssl openssl-devel zlib zlib-devel pcre pcre-devel
yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel
yum install -y freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel bz2-devel
yum install -y bzip2 bzip2-devel
yum install epel-release.noarch
yum -y install libmcrypt-devel mhash mcrypt
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
下载php源码包解压
wget http://cn2.php.net/distributions/php-5.6.0.tar.xz
xz -d php-5.6.0.tar.xz
tar xf php-5.6.0.tar -C /usr/local/src/
创建www用户和用户组
groupadd www
useradd -g www -s /sbin/nologin -M www
编译
cd /usr/local/src/php-5.6.0/
./configure \
--prefix=/data/server/php56 \
--with-config-file-path=/data/server/php56/etc \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-opcache \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-readline\
--with-gd
可能会报错缺少libmcrypt
处理方法
源码安装配置变量
cd /usr/local/src
wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
编译
make && make install
复制配置文件到data server目录下
cp php.ini-development /data/server/php56/etc/php.ini
cp /data/server/php56/etc/php-fpm.conf.default /data/server/php56/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm56
chmod +x /etc/init.d/php-fpm56
/etc/init.d/php-fpm56 start
修改配置文件
vim /data/server/nginx/conf/nginx.conf
退出保存
编辑一个lnmp环境测试页面
cd /data/server/nginx/html
vim test.php
关闭防火墙
systemctl stop firewalld
setenforce 0
浏览器输入ip/test.php如下页面就是搭建成功
还需要mysql数据库的支持
接下来我们源码安装mysql
下载依赖包 解压
wget http://repo.openfusion.net/centos7-x86_64//perl-Data-Dumper-2.154-1.of.el7.x86_64.rpm
rpm -ivh perl-Data-Dumper-2.154-1.of.el7.x86_64.rpm
yum -y install cmake bison git ncurses-devel gcc gcc-c++
下载mysql5.6.22的包
cd /usr/local/src
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz
解压
tar -zxvf mysql-5.6.22.tar.gz
创建一个mysql的组
groupadd mysql
useradd -g mysql mysql
创建mysql目录还有data目录
mkdir -p /data/server/mysql/data
cd /usr/local/src/mysql-5.6.22
编译指定路径为data server 目录下的mysql
cmake -DCMAKE_INSTALL_PREFIX=/data/server/mysql -DMYSQL_UNIX_ADDR=/data/server/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/server/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DENABLE_DOWNLOADS=1
make && make install
注意修改mysql目录的属主和属组
chown -R mysql:mysql /data/server/mysql/data/
chown -R mysql:mysql /data/server/mysql/
cd /data/server/mysql
初始化数据库
scripts/mysql_install_db --defaults-file=./my.cnf --user=mysql
修改生成的文件属主和属组
chown -R mysql:mysql my.cnf
然后开启mysql服务
cd /data/server/mysql/support-files
./mysql.server start
开启之后进入交互环境
cd /data/server/mysql/bin
./mysql -u root -p
这样lnmp环境就算搭建完成了,下一章我们会在lnmp环境的基础上搭建wordpress(个人博客)