- LNMP环境搭建
- 1 nginx 源码安装
- 1.1 资源下载
- 1.2 编译安装
- 1.3 配置
- 1.3.1 nginx.conf配置
- 1.3.2 将nginx添加为系统服务
- 1.4 验证
- 2 mariadb 源码安装
- 2.1 资源下载
- 2.2 编译安装
- 各参数的意义
- 2.3 配置
- 2.4 验证
- 3 php-fmp 源码安装
- 3.1 资源下载
- 3.2 编译安装
- 3.3 配置
- 3.4 验证
首先安装 gcc,g++,make,cmake工具;
1 nginx 源码安装 1.1 资源下载cd /usr/local/src/ sudo wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz sudo wget http://zlib.net/zlib-1.2.11.tar.gz sudo wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz sudo wget http://nginx.org/download/nginx-1.19.7.tar.gz1.2 编译安装
sudo tar zxf pcre-8.44.tar.gz cd pcre-8.44/ sudo ./configure sudo make && sudo make install cd /usr/local/src/ sudo tar zxf zlib-1.2.11.tar.gz cd zlib-1.2.11/ sudo ./configure sudo make && sudo make install cd /usr/local/src/ sudo tar zxf openssl-1.1.1k.tar.gz sudo tar zxf nginx-1.19.7.tar.gz cd nginx-1.19.7/ sudo ./configure --user=nginx --group=nginx --with-http_gzip_static_module --with-http_stub_status_module --with-file-aio --with-http_realip_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.44 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.1.1k sudo make && sudo make install # 添加nginx组和用户 sudo groupadd -r nginx && sudo useradd -r -g nginx -s /sbin/nologin -d /usr/local/nginx nginx # 修改配置用户权限 sudo chown -R nginx:nginx /usr/local/nginx1.3 配置 1.3.1 nginx.conf配置
# 备份配置文件 sudo cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.default # 测试nginx配置是否成功 sudo /usr/local/nginx/sbin/nginx -t # 停止nginx服务 sudo /usr/local/nginx/sbin/nginx -s stop # 重启nginx服务 sudo /usr/local/nginx/sbin/nginx -s reload1.3.2 将nginx添加为系统服务
# 创建文件 sudo vim /lib/systemd/system/nginx.service
添加如下:
[Unit] Description=nginx-The High-performance HTTP Server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop ExecQuit=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
说明:
Description=nginx-The High-performance HTTP Server //描述服务
After=network.target remote-fs.target nss-lookup.target //描述服务类别[Service]
Type=forking //后台运行的形式
PIDFile=/usr/local/nginx/logs/nginx.pid //PID文件的路径
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf //启动准备
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf //启动命令
ExecReload=/usr/local/nginx/sbin/nginx -s reload //重启命令
ExecStop=/usr/local/nginx/sbin/nginx -s stop //停止命令
ExecQuit=/usr/local/nginx/sbin/nginx -s quit //快速停止
PrivateTmp=true //给服务分配临时空间[Install]
WantedBy=multi-user.target //服务用户的模式
# 赋予该文件执行权限 sudo chmod +x /lib/systemd/system/nginx.service # 在启动服务之前,需要先重载systemctl命令 sudo systemctl daemon-reload # 启动nginx服务 sudo systemctl start nginx # 使能自启动 sudo systemctl enable nginx1.4 验证
浏览器输入 服务器IP地址 出现如下页面即nginx安装成功。
cd /usr/local/src/ # 下载 sudo wget https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.5.12/source/mariadb-10.5.12.tar.gz # 安装依赖 sudo apt install -y libncurses5-dev2.2 编译安装
sudo mkdir -p /data/mariadb /var/log/mariadb # 1.解压 sudo tar zxf mariadb-10.5.12.tar.gz cd mariadb-10.5.12 # 2.编译配置 sudo cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb -DMYSQL_DATADIR=/data/mariadb -DSYSCONFDIR=/etc -DMYSQL_USER=mysql -DWITHOUT_TOKUDB=1 -DWITH_INNObase_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STPRAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWIYH_READLINE=1 -DWIYH_SSL=system -DVITH_ZLIB=system -DWITH_LOBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DOWNLOAD_BOOST=1 -DENABLE_DOWNLOADS=1 -DWITH_BOOST=/usr/local/boost
各参数的意义-DCMAKE_INSTALL_PREFIX 是指定安装的位置, 这里是/usr/local/mariadb
-DMYSQL_DATADIR 是指定MySQL的数据目录,这里是/data/mariadb
-DSYSConFDIR 是指定配置文件所在的目录,一般都是/etc ,具体的配置文件是/etc/my.cnf
-DWITHOUT_TOKUDB=1 这个参数一般都要设置上,表示不安装tokudb引擎,tokudb是MySQL中一款开源的存储引擎,
可以管理大量数据并且有一些新的特性,这些是Innodb所不具备的,这里之所以不安装,
是因为一般计算机默认是没有Percona Server的,并且加载tokudb还要依赖jemalloc内存优化,
一般开发中也是不用tokudb的,所以暂时屏蔽掉,否则在系统中找不到依赖会出现:
CMake Error at storage/tokudb/PerconaFT/cmake_modules/TokuSetupCompiler.cmake:179 (message)
这样的错误
然后后面那些参数都是可选的,可以加也可以不加,最后的编码建议设置一下,所以编译指令也可以简化成下面这样:
# 3.编译 sudo make && sudo make install # 创建mysql组与用户 sudo groupadd -r mysql && sudo useradd -r -g mysql -s /sbin/nologin -d /usr/local/mariadb mysql # 修改配置用户权限 sudo chown mysql:mysql -R /usr/local/mariadb /data/mariadb /var/log/mariadb
2.3 配置编译出现 g++: internal compiler error: Killed (program cc1plus) 错误处理方法:
sudo dd if=/dev/zero of=/swapfile bs=64M count=16 sudo mkswap /swapfile sudo swapon /swapfile编译完成后删除
sudo swapoff /swapfile sudo rm /swapfile
sudo /usr/local/mariadb/scripts/mysql_install_db --user=mysql --datadir=/data/mariadb cd /usr/local/mariadb/
编辑配置文件
sudo vim /usr/local/mariadb/my.cnf
添加如下
[mysqld] basedir=/usr/local/mariadb/ datadir=/data/mariadb/ port=3306 pid-file=/data/mariadb/mysql.pid socket=/tmp/mysql.sock [mysqld_safe] log-error=/data/mariadb/mysql.log pid-file=/data/mariadb/mariadb.pid [client] port=3306 socket=/tmp/mysql.sock default-character-set=utf8
sudo cp /usr/local/mariadb/support-files/mysql.server /etc/init.d/mariadb
# 启动及登录mariadb
sudo /etc/init.d/mariadb start
# 数据安全配置
sudo /usr/local/mariadb/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS script IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y
New password:
Re-enter new password:
Sorry, passwords do not match.
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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? [Y/n] n
... skipping.
By default, MariaDB 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? [Y/n] 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? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
# 使能自启动
sudo systemctl enable mariadb
# 忘记root密码
flush privileges;
set password for 'root'@'localhost'=password('123456');
flush privileges;
2.4 验证
3 php-fmp 源码安装
3.1 资源下载
cd /usr/local/src/
# 获取源码
sudo wget https://www.php.net/distributions/php-8.0.3.tar.gz
# 安装依赖
sudo apt-get install -y pkg-config build-essential autoconf bison re2c
libxml2-dev libsqlite3-dev libonig-dev libssl-dev
bzip2 libbz2-dev libcurl4-openssl-dev libxslt1-dev
3.2 编译安装
sudo tar zxf php-8.0.3.tar.gz cd /usr/local/src/php-8.0.3 sudo ./configure --prefix=/usr/local/php --exec-prefix=/usr/local/php --with-fpm-user=php --with-fpm-group=php --enable-zip --with-curl --with-gettext --with-iconv-dir --with-libdir=lib64 --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-bcmath --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-fpm --with-freetype-dir --with-gd --with-libxml-dir --with-pcre-regex --enable-libxml --enable-zip --with-png-dir --with-jpeg-dir sudo make all install # 添加php组和用户 sudo groupadd -r php && sudo useradd -r -g php -s /sbin/nologin -d /usr/local/php php # 修改配置用户权限 sudo chown -R php:php /usr/local/php3.3 配置
sudo cp php.ini-production /usr/local/php/lib/php.ini sudo cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf sudo cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf sudo vim /etc/profile.d/php.sh export PATH=$PATH:/usr/local/php/bin/ sudo chmod 0777 /etc/profile.d/php.sh && source /etc/profile.d/php.sh sudo cp sapi/fpm/php-fpm.service /etc/systemd/system/php-fpm.service sudo /usr/local/php/sbin/php-fpm # 重新加载服务 sudo systemctl daemon-reload # 使能php-fpm服务 sudo systemctl enable php-fpm
修改配置文件
sudo vim /usr/local/nginx/conf/nginx.conf
修改:
location / {
root html;
index index.html index.htm index.php;
}
# nginx.conf中添加
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param script_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 重启nginx服务 sudo /usr/local/nginx/sbin/nginx -s reload3.4 验证
# php验证安装 sudo vim /usr/local/nginx/html/index.php
添加:
修改权限:
sudo chown nginx:nginx /usr/local/nginx/html/index.php
浏览器输入http://服务器IP/index.php,出现如下页面即nginx安装成功。



