欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

编译安装LNMP

程序员文章站 2022-07-09 19:39:48
编译安装LNMP1、安装nginx1.1、首先安装编译工具yum install pcre pcre-devel git openssl-devel zlib-devel libxml2 libxml2-devel wget gzip tar make gcc gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml2 libxml2-devel libgcrypt libtool bison -y1.2、获取n...

编译安装LNMP

1、安装nginx

1.1、首先安装编译工具

yum install pcre pcre-devel git openssl-devel zlib-devel libxml2 libxml2-devel wget gzip tar make gcc gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml2 libxml2-devel libgcrypt libtool bison -y

1.2、获取nginx源码包

1.2.1、可以从官网下载

http://nginx.org/download

1.2.2、使用wget直接下载

cd /usr/local/src
wget -c http://nginx.org/download/nginx-1.18.0.tar.gz

1.3、编译安装

cd /usr/local/src
#解压缩
tar zxf nginx-1.18.0.tar.gz
#进入目录
cd nginx-1.18.0
#添加用户
useradd -s /sbin/nologin www -M
#编译、安装
./configure --user=www --group=www --prefix=/usr/local/nginx
make && make install
#脚本启动
/usr/local/nginx/sbin/nginx
setenforce 0
#开放80端口
...
#重启nginx
/usr/local/nginx/sbin/nginx -s reload 
  • 配置文件:/usr/local/nginx/conf/nginx.conf

2、安装MySql

2.1、获取mysql源码包

2.1.1、可以从YUM源下载

http://mirrors.163.com/mysql/Downloads

2.1.2、使用wget直接下载

cd /usr/local/src
wget -c http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.30.tar.gz
wget -c http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-boost-5.7.30.tar.gz

2.2、编译、安装

cd /usr/local/src
tar xzf mysql-5.7.30.tar.gz
tar zxf	mysql-boost-5.7.30.tar.gz
cd mysql-5.7.30
cmake  .  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
	-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
	-DMYSQL_DATADIR=/data/mysql/data \
	-DSYSCONFDIR=/etc \
	-DMYSQL_USER=mysql \
	-DMYSQL_TCP_PORT=3306 \
	-DWITH_XTRADB_STORAGE_ENGINE=1 \
	-DWITH_INNOBASE_STORAGE_ENGINE=1 \
	-DWITH_PARTITION_STORAGE_ENGINE=1 \
	-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
	-DWITH_MYISAM_STORAGE_ENGINE=1 \
	-DWITH_READLINE=1 \
	-DENABLED_LOCAL_INFILE=1 \
	-DWITH_EXTRA_CHARSETS=1 \
	-DDEFAULT_CHARSET=utf8 \
	-DDEFAULT_COLLATION=utf8_general_ci \
	-DEXTRA_CHARSETS=all \
	-DWITH_BIG_TABLES=1 \
	-DWITH_DEBUG=0 \
	-DWITH_BOOST=boost/boost_1_59_0/
make && make install

添加mysql到系统服务

useradd -s /sbin/nologin mysql
mkdir -p /data/mysql/data
chown -R mysql:mysql /data/mysql
echo "		[client]
			port = 3306
			socket = /tmp/mysql.sock

			[mysqld]
			port = 3306
			socket = /tmp/mysql.sock
			user = mysql


			basedir = /usr/local/mysql
			datadir = /data/mysql/data
			pid-file = /data/mysql/mysql.pid

			log_error = /data/mysql/mysql-error.log
			slow_query_log = 1
			long_query_time = 1
			slow_query_log_file = /data/mysql/mysql-slow.log


			skip-external-locking
			key_buffer_size = 32M
			max_allowed_packet = 1024M
			table_open_cache = 128
			sort_buffer_size = 768K
			net_buffer_length = 8K
			read_buffer_size = 768K
			read_rnd_buffer_size = 512K
			myisam_sort_buffer_size = 8M
			thread_cache_size = 16
			query_cache_size = 16M
			tmp_table_size = 32M
			performance_schema_max_table_instances = 1000

			explicit_defaults_for_timestamp = true
			#skip-networking
			max_connections = 500
			max_connect_errors = 100
			open_files_limit = 65535

			log_bin=mysql-bin
			binlog_format=mixed
			server_id   = 232
			expire_logs_days = 10
			early-plugin-load = ""

			default_storage_engine = InnoDB
			innodb_file_per_table = 1
			innodb_buffer_pool_size = 128M
			innodb_log_file_size = 32M
			innodb_log_buffer_size = 8M
			innodb_flush_log_at_trx_commit = 1
			innodb_lock_wait_timeout = 50

			[mysqldump]
			quick
			max_allowed_packet = 16M

			[mysql]
			no-auto-rehash

			[myisamchk]
			key_buffer_size = 32M
			sort_buffer_size = 768K
			read_buffer = 2M
			write_buffer = 2M
		" > /etc/my.cnf

chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql57/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
service mysqld start
chkconfig mysqld on

sed -i '$aPATH=/usr/local/mysql/bin:$PATH' /etc/profile
source /etc/profile
  • 配置文件:/etc/my.cnf

3、安装php

3.1、获取php

3.1.1、可以从官网下载

https://www.php.net/downloads

3.2、编译安装

3.2.1、安装编译工具和必要的软件

cd /usr/local/src
tar -zxf  php-7.3.20.tar.gz
cd php-7.3.20
./configure --prefix=$INSTALL_DIR/php --with-config-file-path=$INSTALL_DIR/php/etc --with-mysql=$INSTALL_DIR/mysql --enable-fpm
make && make install

cp php.ini-development /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/src/php-7.3.20/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
chmod o+x /etc/init.d/php-fpm
/etc/init.d/php-fpm start
  • 配置文件:/usr/local/php/etc/php.ini

4、配置环境并测试

#关联php和nginx
echo "
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            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;
        }
    }
}" >/usr/local/nginx/conf/nginx.conf
#测试
echo "
<?php
phpinfo();
?>">/usr/local/nginx/html/index.php

/usr/local/nginx/sbin/nginx -s reload

本文地址:https://blog.csdn.net/qq_36879493/article/details/107585400