源码安装lnmp
环境准备:先安装准备环境 ( 特别注意:本例 php7.3.5+nginx1.16+mysql8 安装目录为 /lnmp )
准备工作(执行) yum install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2-devel libpng-devel curl-devel numactl
mkdir -p /lnmp/php7
mkdir /lnmp/nginx
nginx
1. 下载 wget http://nginx.org/download/nginx-1.16.0.tar.gz (版本可自行选择)
2. 解压 tar xvf nginx-1.16.0.tar.gz
3. 进入 cd nginx-1.16.0
4. ./configure --prefix=/lnmp/nginx --with-http_ssl_module
5. make
6. make install
7. cp /lnmp/nginx/sbin/nginx /usr/bin/ (到此完成完成)
命令: 开启 nginx
查看开启后服务 netstat -anp | grep nginx
关闭 nginx -s stop
平滑重启 nginx -s reload
8.nginx开启php配置 1.
2.
try_files $uri $uri/ /index.php?$query_string;
if (!-e $request_filename){
rewrite ^/(.*) /index.php last;
}
configure参数说明
–prefix=path nginx安装路径
–sbin-path=path 启动程序路径
–pid-path=path pid路径
–error-log-path=path
–http-log-path=path acess.log
–user=name 用户
–group=name 用户组
–without-http_rewrite_module
–without-http_proxy_module
–without-http_gzip_module
–with-http_ssl_module
php
1. wget https://www.php.net/distributions/php-7.3.5.tar.gz (版本可自行选择)
2. tar xvf php-7.3.5.tar.gz
3. cd php-7.3.5
4. ./configure --prefix=/lnmp/php7 --enable-fpm --with-mysqli --with-curl --with-pdo_mysql --with-pdo_sqlite --enable-mysqlnd --enable-mbstring --with-gd
5. make && make install
6. cp php.ini-development /lnmp/php7/lib/php.ini
7. cd /lnmp/php7/etc/
重命名 mv php-fpm.conf.default php-fpm.conf
mv php-fpm.d/www.conf.default php-fpm.d/www.conf
8. cp /lnmp/php7/sbin/php-fpm /usr/bin/ (这样全局可用php-fpm开启php,关闭命令为killall php-fpm, 否则使用 /lnmp/php7/sbin/php-fpm开启php )
9. 修改php.ini cgi.fix_pathinfo=0 ( find / -name php.ini 可搜索此文件位置 )
开启 php-fpm
关闭 killall php-fpm
mysql
1. https://dev.mysql.com/downloads/mysql/ (自行选择 下载缓慢时可用迅雷下载)
( wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz)
2. tar -Jxf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
3. mv mysql-8.0.18-linux-glibc2.12-x86_64 /lnmp/mysql (移动压缩包到/lnmp/mysql目录下,并重命名文件)
4. cd /lnmp/mysql
mkdir data (在MySQL根目录下新建一个文件夹data,用于存放数据)
5. groupadd mysql (创建 mysql 用户组和 mysql 用户)
useradd -g mysql mysql
6. chown -R mysql.mysql /lnmp/mysql/ (改变 mysql 目录权限)
bin/mysqld --initialize --user=mysql --basedir=/lnmp/mysql --datadir=/lnmp/mysql/data (初始化)
(不慎忘记mysql密码可用此方法找回 http://www.cnblogs.com/wuotto/p/9682400.html )
7. vim /etc/my.cnf (修改my.cnf文件 把下方内容粘贴进去 如果安装路径不同填写自己的路径)
[mysqld]
basedir = /lnmp/mysql
datadir = /lnmp/mysql/data
socket = /tmp/mysql/mysql.sock
character-set-server=utf8
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket = /tmp/mysql/mysql.sock
default-character-set=utf8
注意事项: chown -R mysql:mysql /tmp/mysql/ (文件夹不存在就先创建mkdir /tem/mysql)
8. cp -a /lnmp/mysql/support-files/mysql.server /etc/init.d/mysqld (配置mysqld服务)
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
----------------- 到这里已经可以启动mysql了哦 命令: service mysqld start ----------------------------------------------
9 vim /etc/profile (配置全局环境变量)
在 profile 文件底部添加如下两行配置,保存后退出
export PATH=$PATH:/lnmp/mysql/bin:/lnmp/mysql/lib
export PATH
设置环境变量立即生效
source /etc/profile
10 chmod -R 777 /tmp/mysql
至此lnmp的安装就完成了