环境准备
清空关闭防火墙并关闭selinux
# iptables -F
# systemctl stop firewalld
# systemctl disable firewalld
# vim /etc/selinux/config
改: SELINUX= enforcing
为: SELINUX=disabled
# reboot #重启系统生效
配置yum源
配置网络yum源
(1)备份 :
# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
(2)下载新的CentOS-Base.repo 到/etc/yum.repos.d/
# rpm -ivh /mnt/Packages/wget-1.14-15.el7.x86_64.rpm
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #下载配置文件
配置epel源
# yum install epel-release –y
部署LNMP环境
LNMP=Linux + Nginx + MySQL + PHP
mysql-boost-5.7.27.tar.gz
nginx-1.17.4.tar.gz
pcre-8.43.tar.gz
php-7.3.10.tar.gz
安装nginx
yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel #安装依赖包
useradd -M -s /sbin/nologin nginx #创建nginx用户
tar xvf pcre-8.43.tar.gz -C /usr/local/src/ #上传源码包
上传nginx安装包解压安装
tar xvf nginx-1.17.4.tar.gz -C /usr/local/src/
cd /usr/local/src/nginx-1.17.4
#./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --
with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.43 --user=nginx --group=nginx #配置选项
#make && make install #编译安装
配置Nginx支持php文件
修改配置文件之前,先备份,养成好习惯,备份nginx.conf
# cp /usr/local/nginx/conf/nginx.conf{,.bak}
# vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; 修改用户为nginx
启用php的支持
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
启动nginx服务
# /usr/local/nginx/sbin/nginx
编辑配置环境变量
# vim /etc/profile.d/nginx.sh
export PATH=/usr/local/nginx/sbin:$PATH
配置服务开机自动启动
配置开机自动启动
# chmod +x /etc/init.d/nginx
# chkconfig --add nginx
# chkconfig nginx on
安装MySQL 5.7
卸载系统自带的mysql和boost
# yum -y remove mysql mariadb-*
# yum -y remove boost-*
开始安装
yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel #安装依赖包
# groupadd mysql
# useradd -M -s /sbin/nologin -r -g mysql mysql #添加用户和组
上传安装包并解压
# tar xf mysql-boost-5.7.27.tar.gz -C /usr/local/src/
# cd /usr/local/src/mysql-5.7.27/
规划安装目录:
安装目录:/var/lib/mysql
数据目录:/val/lib/mysql/data
mkdir -p /var/lib/mysql/data
chown -R mysql:mysql /var/lib/mysql #授权目录mysql权限
编译安装
# cmake -DCMAKE_INSTALL_PREFIX=/var/lib/mysql \
-DMYSQL_DATADIR=/var/lib/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/src/mysql-5.7.27/boost/boost_1_59_0
# make -j 4
# make install
编辑配置文件
# vim /etc/my.cnf
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set = utf8
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
basedir = /var/lib/mysql
datadir = /var/lib/mysql/data
pid-file = /tmp/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8'
character-set-server = utf8
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = /var/lib/mysql/mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /var/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /var/log/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
skip-external-locking
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
配置环境变量
# vim /etc/profile.d/mysql.sh
export PATH=/var/lib/mysql/bin:$PATH #添加path路径,让系统读到mysql命令
#source /etc/profile.d/mysql.sh #使其mysql.sh生效
修改mysql目录权限
# chown -R mysql:mysql /var/lib/mysql
生成服务启动脚本
# cp /var/lib/mysql/support-files/mysql.server /etc/init.d/mysqld
# chowd +x /etc/init.d/mysqld
初始化数据库
# /var/lib/mysql/bin/mysqld --initialize --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data
启动服务
# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
修改初始登录密码
Mysql5.7初始安装后,第一次登录需要查询一下密码
# grep "password" /var/log/mysql-error.log
2019-10-25T09:00:27.826152Z 1 [Note] A temporary password is generated for root@localhost: muHyi?fKy5rc
登录修改密码
# mysql -u root -p
Enter password: muHyi?fKy5rc
mysql> alter user 'root'@'localhost' identified by '123456';
mysql>flush privileges;
编译安装PHP
安装所需依赖包
# yum -y install php-mcrypt libmcrypt libmcrypt-devel php-pear libxml2 libxml2-devel curl curl-d
evel libjpeg libjpeg-devel libpng libpng-devel freetype-devel
上传并解压PHP安装包
# tar xf php-7.3.10.tar.gz -C /usr/local/src/
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/ --enable-fpm --with
-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
修改配置
# cp /usr/local/src/php-7.3.10/php.ini-production /usr/local/php/php.ini #复制php配置文件到安装目录
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #复制模板配置文件为php-fpm的配置文件
修改: vim /usr/local/php/etc/php-fpm.conf
pid = run/php-fpm.pid #取消前面的分号
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
修改:vim /usr/local/php/etc/php-fpm.d/www.conf
user = www #设置php-fpm运行账号为www
group = www #设置php-fpm运行组为www
设置php-fpm开机启动
cp /usr/local/src/php-7.3.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #复制php-fpm到启动目录
chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
chkconfig php-fpm on #设置开机启动
service php-fpm start #启动php-fpm
重启php和nginx。
service php-fpm restart
service nginx restart
测试:
在web目录:/usr/local/nginx/html中新建一个phpinfo的php文件,在浏览器中查看。