天天看点

软件测试之环境搭建LNMP&LAMP(CentOS7)环境搭建(CentOS7)

理论概念方面繁多复杂,就不过多讨论。

环境搭建(CentOS7)

这个环境搭建的前提是需要至少需要一些liunx命令基础,会使用Vi / vim编辑器,然后还有就是需要会配置liunx的网络配置,这是为了验证你后面的环境搭建所必须的。

liunx IP 网络配置(centos7)

vim /etc/sysconfig/network-scripts/ifcfg-ens32
具体配置
DEFROUTE=yes
ONBOOT=yes
IPADDR=192.168.8.14
NETMASK=255.255.255.0
GATEWAY=192.168.8.2
DNS1=192.168.8.2
退出之后,配置liunx为NAT模式
重启网络配置
/etc/init.d/network restart

           

配置NAT模式

软件测试之环境搭建LNMP&LAMP(CentOS7)环境搭建(CentOS7)

尝试 ping www.baidu.com

如果不行或者重新开启虚拟机后无法使用网络。

去启动一下相关服务

软件测试之环境搭建LNMP&LAMP(CentOS7)环境搭建(CentOS7)

Google浏览器安装(选择性安装)

Centos7自带有firefox浏览器,但是对用习惯了google的,还是可以安装下。

下载相应的安装包(google-chrome-stable_current_x86_64.rpm),上传到liunx。

安装相应的依赖包:
yum install redhat-lsb
yum install libXScrnSaver*
yum install epel-release
yum install libappindicator-gtk3
安装google
rpm -ivh google-chrome-stable_current_x86_64.rpm
           

LNMP 环境搭建

LNMP 指的就是liunx + nginx + mysql + php,我也是在之前搭建过,现在就这笔记内容介绍。

LNMP环境搭建所需安装包。

链接: 安装包.

提取码:j6q4

创建相应的安装包和安装目录

mkdir -p /data/{server,soft}
cd /data/soft
           

安装相应的依赖包(可能不完善,笔记不是太完善,看具体情况而安装):

yum install -y lrzsz
yum  install  -y gcc-c++
yum install -y wget
yum install -y pcre-devel openssl-devel
yum install -y ncurses-devel libaio-devel autoconf numactl
           

nginx安装

useradd www -s /sbin/nologin -M
cd   /data/soft
tar xf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure  --prefix=/data/server/nginx --user=www --group=www
make
make install
***启动***
/data/server/nginx/sbin/nginx
           

测试nginx

***查看nginx进程*** 
 ps -ef | grep nginx
 pgrep -lf nginx
***测试Nginx服务端口(80)***
ss -lnt | grep 80
lsof -i:80
netstat -lntup | grep nginx
***curl测试Nginx首页***
curl -s 本机IP
有看到Welcome to nginx!就是成功了
***nginx命令***
检查:/data/sever/nginx/sbin/nginx -t     #/data/sever是安装目录
启动:/data/sever/nginx/sbin/nginx
关闭:/data/sever/nginx/sbin/nginx -s stop
重载:/data/sever/nginx/sbin/nginx -s reload  #(类似于重启)
启动后检查:netstat -tnulp | grep nginx
           

MySQL安装

cd  /data/soft/
tar xf mysql-5.6.35-liunx-glibc2.5-x86_64.tar.gz  -C /data/server/
cd  /data/server/
ln -s mysql-5.6.35-liunx-glibc2.5-x86_64/ mysql
useradd -s /sbin/nologin -M mysql
/data/server/mysql/scripts/mysql_install_db --basedir=/data/server/mysql --datadir=/data/server/mysql/data/
mv /etc/my.cnf /etc/my.cnf-bak
cp /data/server/mysql/support-files/my-default.cnf /etc/mycnf
cp /data/server/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
sed -I 's#/usr/local/mysql#/data/server/mysql#g'  /data/server/mysql/bin/mysqld_safe   /etc/init.d/mysqld
chown -R mysql.mysql    /data/server/mysql*
/etc/init.d/mysqld  start
netstat -tnulp   |  grep mysqld
vim /etc/profile    ***文末添加  PATH=/data/server/mysql/bin:$PATH ***
source  /etc/profile
试试mysql能不能使用就行。
           

PHP安装

安装PHP前先安装依赖
yum install libxml2-devel -y
yum install sqlite -y
yum install sqlite-devel -y
yum install freetype-devel -y
yum install libpng -y
yum install libpng-devel -y
yum install curl-devel -y
yum install libxslt -y
yum install libxslt-devel -y
           

前面PHP安装包版本会比较低

报错:configure: error: Cannot find MySQL header files under /usr/include/mysql.

改安装高版本PHP,已上传对应的

PHP包.

oniguruma包.

cd /data/soft
tar xf php-8.0.6.tar.gz
cd /php-8.0.6/
/configure --prefix=/usr/local/php/--with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysql --with-mysqli 
--with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
make && makeinstall
拷贝文件
cp -R ./sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
cp php.ini-development /usr/local/php/lib/php.ini
cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm

启动PHP
/etc/init.d/php-fpm
启动时会报错
{
[26-May-2021 18:44:04] WARNING: Nothing matches the include pattern '/usr/local/php/etc/php-fpm.d/*.conf' from /usr/local/php/etc/php-fpm.conf at line 143.
[26-May-2021 18:44:04] ERROR: No pool defined. at least one pool section must be specified in config file
[26-May-2021 18:44:04] ERROR: failed to post process the configuration
[26-May-2021 18:44:04] ERROR: FPM initialization failed
}
解决方法:
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
/usr/local/php/sbin/php-fpm -t
           

LAMP 环境搭建

这个环境我目前还没有尝试去搭建过,看其他人倒是也挺常用了。此处附上大佬对于LAMP简介和安装方式。

所谓lamp,其实就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一组动态网站或者服务器的开源软件,除Linux外其它各部件本身都是各自独立的程序,但是因为经常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。

安装方式链接:

链接: lamp架构的搭建(apache、mysql、php编译安装).