当前位置: 首页 > Linux

在虚拟机(centos7、nginx1.12.0、MariaDB10.2、php-7.1.6)上编译安装lnmp

时间:2023-04-06 03:45:37 Linux

1。使用virtualbox安装安装配置centos7(最小安装)网络配置更多网络配置可以参考(http://www.cnblogs.com/hfyfpg...)在虚拟机网络配置中,nat(用于访问外网))和host-only(用于允许宿主机访问虚拟机)网络接口在centos中配置:nat:vim/etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0HWADDR=08:00:27:60:8D:FCONBOOT=yesNM_CONTROLLED=yesBOOTPROTO=dhcphost-only:vim/etc/sysconfig/network-scripts/ifcfg-enp0s3TYPE=EthernetHWADDR=08:00:27:17:94:19BOOTPROTO=staticDEFROUTE=yesPEERDNS=yesPEERROUTES=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_PEERDNS=yesIPV6_FALURESnoIPV6_ADDR_GEN_MODE=stable-privacyNAME=enp0s3UUID=fac7f008-3be8-49cd-8d9d-99986a3f0322DEVICE=enp0s3ONBOOT=yesIPADDR=192.168.3.102GATEWAY=192.168.3.1NETMASK=255.255.255.0SELinux临时关闭SELinux:setenforce0临时打开SELinux:setenforce1boot关闭SELinux:编辑/etc/selinux/config文件,将SELINUX的值设置为disabled查看SELinux状态:执行getenforce命令防火墙(firewalld,本文使用iptables)暂时关闭防火墙:systemctlstopfirewalld永久防火墙开机自启动:systemctldisablefirewalld暂时开启防火墙:systemctlstartfirewalld启动防火墙:systemctlenablefirewalld查看防火墙状态:systemctlstatusfirewalld软件源配置:参考以下两个链接http://mirrors.aliyun.com/hel...http://mirrors.163.com/.help/...yumcleanallyummakecacheinstall常用软件yumgrouplistgcc和开发环境:yumgroupinstall"开发工具"yuminstall-ypcre-developenssl-devellibxslt*perl-ExtUtils-嵌入gcc-c++python颠覆gperfmakerpm-buildgitcurlbzip2-devellibcurl-develgdgd-develt1libt1lib-devellibmcryptlibmcrypt-devellibtidylibtidy-develGeoIP-devellibatomic_ops-develzlib-develunziplibstdc++*net-snmpnet-snmp*gmpgmp-developenldapopenldap-devellibpcap-develglib2-devellibxml2-develredisvimwgethtopiftoplibtoolautomakemlocatepam-develgccscreenopenssliptables-servicesbash-completion*net-tools2。源码安装nginx下载源码包(nginx1.12.0)安装前(检查是否安装了pcre,安装pcre库是为了让Nginx支持rewrite模块,带URL重写。openssl是nginx使用https的模块要用到的)服务)rpm-qa|grep-E'pcre|pcre-devel'//如果没有返回结果,证明没有安装pcre包,使用以下命令下载安装yuminstallpcrepcre-devel-yrpm-qa|grep-E'openssl|openssl-devel'//如果返回值为空,说明系统还没有安装,安装命令如下yuminstallopensslopenssl-develrpm-qa|grepgccgcc-c++//如果没有安装gcc,编译时会出现。/configure:error:Ccompilerccisnotfound错误yuminstallgccgcc-c++创建用户和用户组添加一个www组groupadd-fwww添加一个www用户useradd-s/sbin/nologin-gwwwwww编译安装nginx./configure--user=www\--group=www\--prefix=/usr/local/nginx-1.xx.xx\--with-http_stub_status_module\--with-http_ssl_module编译参数说明:--prefix=PATH#设置安装路径--user=user--group=group#设置运行nginx的用户和用户组--with-http_stub_status_module#激活状态信息--with-http_ssl_module#激活ssl功能Nginx的大部分模块功能将要编译的软件中,不需要单独指定编译参数echo$?//返回0表示上面的命令正确执行make&&makeinstallecho$?ln-s/usr/local/nginx-1.xx.xx/usr/local/nginx//设置软链接,好处是如果程序中有nginx路径的引用,就不需要修改程序,如果升级nginx版本,只需新建一个连接启动,查看安装结果查看配置文件:/usr/local/nginx/sbin/nginx-t检查通过后启动nginx服务:/usr/local/nginx/sbin/nginx编译安装nginx时检查参数:/usr/local/nginx/sbin/nginx-Venableiptables开启80端口systemctlenableiptables//设置iptables开机systemctlstartiptables//立即启动iptablesystemctldisableip6tables//禁用IPv6ip6tablesstartsystemctlstopip6tables//立即停止IPv6ip6tablesiptables-AINPUT-ptcp--dport80-jACCEPT//打开tcp80端口服务iptablessave//保存修改systemctlreloadiptablessystemctlrestartiptables七、检查结果在释放80端口的情况下,可以通过浏览器访问测试安装效果#进入nginx文件夹[root@centos7-testopenresty-1.11.2.2]#cd/usr/local/nginx/#新建文件夹[root@centos7-testnginx]#mkdirvhosts.d#修改配置文件[root@centos7-testnginx]#vimnginx.conf#将server部分的内容全部注释掉server{......}#在最后的上面添加以下内容}并保存include/usr/local/nginx/vhosts.d/*.ngx.conf;然后检查并重新加载nginx:#检查配置文件是否正常[root@centos7-testnginx]#nginx-tnginx:配置文件/usr/local/nginx/nginx.conf语法是否正确nginx:配置文件/usr/local/nginx/nginx.conf测试成功#Reloadnginx[root@centos7-testnginx]#nginx-sreload并新建虚拟空间#新建虚拟目录[root@centos7-testnginx]#mkdir-p/data/web/darkgel.com#新建日志目录[root@centos7-testnginx]#mkdir/usr/local/nginx/logs/darkgel_access.log#新建虚拟空间配置文件[root@centos7-testnginx]#vim/usr/local/nginx/vhosts.d/darkgel.com.conf服务器{listen80;根/data/web/darkgel.c嗡;access_log/usr/local/nginx/logs/darkgel_access.log;位置/{索引index.html;}}尝试访问站点看是否成功3.安装配置mysql由于mysql的编译太耗时,这里不使用编译安装先添加MariaDB的YUM配置文件MariaDB.repofile#vi/etc/yum.repos.d/MariaDB.repo#MariaDB10.2CentOS存储库列表-创建于2017-06-1409:14UTC#http://downloads。mariadb.org/mariadb/repositories/[mariadb]name=MariaDBbaseurl=http://yum.mariadb.org/10.2/centos7-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1使用国内镜像加速(具体操作参考https://lug.ustc.edu.cn/wiki/...)sudoyuminstallMariaDB-serverMariaDB-clientMariaDB包安装完成后,立即启动数据库服务守护进程,并且可以通过以下操作设置操作系统重启后自动启动服务。#systemctlstartmariadb#systemctlenablemariadb#systemctlstatusmariadb对MariaDB进行安全配置#mysql_secure_installation开始使用#mysql-V#mysqld--print-defaults#mysql-uroot-p4.编译安装php7下载wgethttp://cn2.php.net/distributi...安装依托库yum-yinstalllibxml2libxml2-developensslopenssl-develcurl-devellibjpeg-devellibpng-develfreetype-devellibmcrypt-develmhashgdgd-devel编译配置./configure--prefix=/usr/local/php7\--with-config-file-path=/usr/local/php7/etc\--with-config-file-scan-dir=/usr/local/php7/etc/php.d\--with-mcrypt=/usr/include\--enable-mysqlnd\--with-mysqli\--with-pdo-mysql\--enable-fpm\--with-fpm-user=www\--with-fpm-group=www\--with-gd\--with-iconv\--with-zlib\--enable-xml\--enable-shmop\--enable-sysvsem\--enable-内联优化\--enable-mbregex\--enable-mbstring\--enable-ftp\--enable-gd-native-ttf\--with-openssl\--enable-pcntl\--enable-sockets\--with-xmlrpc\--enable-zip\--enable-soap\--without-pear\--with-gettext\--enable-session\--with-curl\--with-jpeg-dir\--with-freetype-dir\--enable-opcachecompile&installmake&&makeinstall从源包调整php配置找到ini文件在:php.ini-developmentphp.ini-production复制到--with-config-file-path指定的目录下,重命名为php.ini启用php-fpm服务配置文件--with-config在-file-path指定的目录中:php-fpm.conf.default更名为php-fpm.conf(当前目录下的php-fpm.d目录下的配置文件也被处理)使用源码脚本启动php-fpm(在源码目录/sapi/fpm/init.d.php-fpm)$cpinit.d.php-fpm/etc/init.d/php-fpm$chmod+x/etc/init.d/php-fpm$chkconfig--addphp-fpm$chkconfigphp-fpmonEnablephp-fpm$servicephp-fpmstart配置nginx与php-fpm和站点连接(添加服务器{...})位置~\.php${fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME/$document_root$fastcgi_script_name;包括fastcgi_params;}重启nginx/usr/local/nginx/sbin/nginx-sreload