LNMP环境搭建
LNMP的搭建
一、Linux(centos 7.3.1611)
趁着学生证还没有过期,买了一年的阿里云服务器。
二、Nginx(nginx-1.14.2)
1.下载nginx:wget https://nginx.org/download/nginx-1.14.2.tar.gz
2.安装nginx所需环境
yum install -y gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
3.解压下好的nginx-1.14.2.tar.gz文件,并且进入解压出来的nginx-1.14.2文件夹。
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure //使用默认配置
4.编译安装
make
make install
whereis nginx //查看安装到哪儿去了
5.进入/user/local/nginx/sbin
./nginx //开启nginx
./nginx -s quit //关闭nginx
./nginx -s reload //重启nginx
ps aux|grep nginx //查看nginx进程
6.在阿里云管理控制台->云服务器ECS->网络和安全->安全组->配置规则->添加安全组规则根据需求添加。
7.在浏览器输入云服务器公网IP
以上,Nginx安装完成。
三、MySQL(mysql-8.0.15)
1.下载mysql发行包
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
2.安装mysql发行包
yum localinstall mysql80-community-release-el7-1.noarch.rpm
3.验证安装
yum repolist enabled | grep ‘mysql.*-community.*’
4.安装mysql
Yum install -y mysql-community-server
5.检查已安装的软件包
rpm -qa | grep -i ‘mysql.*8.*’
6.启动mysql服务
systemctl start mysqld //开启mysql服务
systemctl stop mysqld //停止mysql服务
systemctl restart mysqld //重启mysql服务
systemctl status mysqld //查看服务状态
7.查看mysql临时密码
grep ‘temporary password’ /var/log/mysqld.log
8.使用临时密码登录mysql并且修改密码
mysql -u root -p
alter user ‘root’@’localhost’ identified by ‘新密码’;
如此,MySQL安装完毕。
四、PHP(php-7.3.2)
1.wget http://cn2.php.net/get/php-7.3.2.tar.gz/from/this/mirror
2.tar zxvf mirror //解压镜像,进入解压出来的php-7.3.2文件夹
3.使用yum安装php所需依赖
yum -y install libcurl-devel
yum -y install libXpm-devel
yum -y install libxml2-devel
yum -y install php-mbstring
yum -y install libjpeg-devel
yum -y install libpng-devel
yum -y install freetype-devel
yum -y install mysql-devel
yum -y install libzip-devel //版本过低解决方案:http://www.kwx.gd/PHPEnvironment/CetnOS-libzip.html
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h //安装完新版本后的必要操作
4.配置安装php
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-mysqli --with-mysql-sock --with-pdo-mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-zlib-dir=/usr/local/zlib --with-libzip=/usr/local/libzip --with-pcre-dir --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-ctype
make
make install
5.复制php配置文件到安装目录
cp php.ini-production /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php.ini //display_errors = On,显示错误信息
6.复制启动脚本
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
7.修改php-fpm配置文件
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf //去掉 pid = run/php-fpm.pid 前面的分号
8.配置www.conf
cd php-fpm.d
cp www.conf.default www.conf
vim www.conf //此处可以修改user和group
9.启动php
/etc/init.d/php-fpm start //启动
/etc/init.d/php-fpm stop //停止
/etc/init.d/php-fpm restart //重启
ps -ef | grep php //查看php启动状态
10.配置nginx.conf
vim /usr/local/nginx/conf/nginx.conf
11./usr/local/nginx/html中创建index.php,重启php和nginx。
连接数据库后的效果:
五、补充:远程连接阿里云MySQL8.0
1.mysql设置
见https://blog.csdn.net/qq_34873338/article/details/82256868
2.阿里云添加一个端口