Linux服务器搭建lnmp环境

1.安装nginx

1).更新yum

yum update

2).安装依赖包

(1)安装make

yum -y install gcc automake autoconf libtool make

(2)安装g++

yum install gcc gcc-c++

(3)安装PCRE库

yum install pcre pcre-devel

(4)zlib库

yum install zlib zlib-devel

(5)OpenSSL

yum install openssl openssl-devel

3).下载nginx的最新版

http://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.16.1.tar.gz

解压

tar -xzf nginx-1.16.1.tar.gz

进入nginx-1.16.1

cd nginx-1.16.1

执行配置命令

./configure

执行安装Nginx

make && make install

进入nginx文件夹下打开nginx

cd /usr/local/nginx/sbin

./nginx  //启动nginx服务

nginx开机启动



2.安装php

1).安装依赖包

yum install -y gcc gcc-c++  make zlib zlib-devel pcre pcre-devel  libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

2).安装php

wget https://www.php.net/distributions/php-7.4.3.tar.gz

解压

cd php-7.4.3

配置php

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --without-pear  --disable-phar --enable-sockets --with-freetype-dir=/usr --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli --with-curl

安装

make && make install

3).php.ini配置

拷贝生产环境的php配置文件

cp php.ini-production /usr/local/php/etc/php.ini

删除系统自带配置文件

rm -rf /etc/php.ini

添加软链接

ln -s /usr/local/php/etc/php.ini /etc/php.ini

拷贝php-fpm配置文件

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

修改php-fpm 文件

pid = run/php-fpm.pid //去除前面的分号

4).设置开机启动

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf  #拷贝php-fpm到启动目录
chmod +x /etc/rc.d/init.d/php-fpm  #添加执行权限
chkconfig php-fpm on                                                                    #设置开机启动
service php-fpm start                                                                   #启动php-fpm

5).设置nginx配置

vi /usr/local/nginx/conf/nginx.conf  #配置nginx支持php

        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;
        }

cd /usr/local/nginx/sbin
./nginx -s reload                   #重新加载nginx的配置文件


3.安装mysql

1).下载mysql

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar

2)解压

tar -xvf mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar

3).按顺序安装

(1)rpm -ivh mysql-community-common-8.0.19-1.el7.x86_64.rpm
(2)rpm -ivh  mysql-community-libs-8.0.19-1.el7.x86_64.rpm
(3)rpm -ivh  mysql-community-client-8.0.19-1.el7.x86_64.rpm 
(4)rpm -ivh  mysql-community-server-8.0.19-1.el7.x86_64.rpm
(5)rpm -ivh  mysql-community-devel-8.0.19-1.el7.x86_64.rpm

#若出现
#warning: mysql-community-common-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
#在后面添加--force --nodeps

4).初始化配置

mkdir -p /data/www                      #创建数据库数据保存目录

useradd mysql -s /sbin/nologin          #创建用户mysql,不允许用户直接登录系统
mkdir -p /var/mysql/data                #创建MySQL数据库存数据存放目录 
chown -R mysql:mysql / var/mysql/data   #设置MySQL数据库目录权限

vi /etc/my.cnf                          #编辑配置文件
datadir = /var/mysql/data       

mysqld --initialize --user=mysql       #生成mysql系统数据库 

cat /var/log/mysqlld.log               #查看root的追随初始密码
jv0E:r;5rB/Z

systemctl start mysqld                 #启动mysql服务
systemctl status mysqld                #查看是否开启mysql服务(running)
mysql -uroot -p                        #打开数据库
alter user 'root'@'localhost'  identified by  '134679';             #修改密码
show databases;                        #显示数据库

你可能感兴趣的:(linux,centos)