原因是工作原因,需要经常搭建LNMP(PHP7+MySQL5.7+Nginx)环境。虽然网上有很多教程,但是到目前为止我还没有找到符合我需求的教程。所以我每次部署环境都要打开好几个教程进行部署,还是挺麻烦的。今天也抽空总结了一下教程。1.修改yum源[root@localhost~]#rpm-Uvhhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm[root@localhost~]#rpm-Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm[root@localhost~]#rpm-Uvhhttp://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm2.安装Nginx、MySQL、PHP[root@localhost~]#yum-yinstallnginx[root@localhost~]#yum-yinstallmysql-community-server[root@localhost~]#yum-yinstallphp72wphp72w-develphp72w.x86_64php72w-cli.x86_64php72w-common.x86_64php72w-gd.x86_64php72w-ldap.x86_64php72w-mbstring.x86_64php72w-mcrypt.x86_64php72w-pdo.x86_64php72w-mysqlndphp72w-fpmphp72w-opcachephp72w-pecl-redisphp72w-pecl-mongophp72w-mcrypt三、配置1.配置MySQLMySQL安装完成后,在/var/log/mysqld.log文件中给root生成默认密码。[root@localhost~]#systemctlstartmysqld#启动MySQL[root@localhost~]#grep'temporarypassword'/var/log/mysqld.log#查找默认密码2017-04-10T02:58:16.806931Z1[注]为root@localhost生成临时密码:iacFXpWt-6gJ登录MySQL:[root@localhost~]#mysql-uroot-p'iacFXpWt-6gJ'修改root密码:mysql>ALTERUSER'root'@'localhost'由'MyPass1!'识别;或者:mysql>setpasswordfor'root'@'localhost'=password('123abc');详细请参考MySQL官网密码策略说明:https://dev.mysql.com/doc/ref...设置开机启动:[root@localhost~]#systemctlenablemysqld重启服务:[root@localhost~]#systemctlrestartmysqld默认配置文件路径:配置文件:/etc/my.cnf日志文件:/var/log/mysqld.log服务启动脚本:/usr/lib/systemd/system/mysqld.servicesocket文件:/var/run/mysqld/mysqld.pid2.配置Nginx安装完成后,检查你的防火墙是否开启。如果开启,我们需要修改防火墙配置,开启Nginx外设端口访问。[root@localhost~]#systemctlstatusfirewalld打开端口80/443:[root@localhost~]#firewall-cmd--zone=public--add-port=80/tcp--permanent[root@localhost~]#firewall-cmd--zone=public--add-port=443/tcp--permanent出现success,说明添加成功命令含义:--zone#Scope--add-port=80/tcp#添加端口,格式为:端口/通信协议--permanent#永久有效,没有这个参数,重启后失效。设置开机启动:[root@localhost~]#systemctlenablenginxconfigurationPHPsupportAddinserver{}:location/{#定义首页的索引文件Nameindexindex.phpindex.htmlindex.htm;}#PHP脚本请求全部转发给FastCGI处理。使用FastCGI默认配置.location~.php${fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;includefastcgi_params;}重启Nginx服务[root@localhost~]#systemctlstartnginx#启动Nginx3,设置开机启动php-fpm[root@localhost~]#systemctlenablephp-fpm[root@localhost~]#systemctlstartphp-fpm#启动php-fpm4,测试在/usr/share/nginx/html文件下创建php文件,输出phpinfo信息浏览器访问http://<内网IP地址>/phpinfo.php,如果看到PHP信息,说明安装成功。至此,LNMP环境已经搭建完成。5.扩展swooleswoole扩展是根据PHP标准扩展构建的。使用phpize生成编译检测脚本,./configure做编译配置检测,make编译,makeinstall安装。请下载releases版本的swoole,直接从githubtrunk拉取最新代码,有可能再编译回去。但是如果没有特殊要求,请务必编译安装最新版本的swoole。如果当前用户不是root,可能是你对PHP安装目录没有写权限,安装时需要sudo或su如果直接在git分支上gitpullupdate代码,一定要执行makeclean再重新编译。安装前必须确保系统已经安装了以下软件:php-7.0或更高版本gcc-4.8或更高版本makeautoconfpcre(CentOS系统可执行命令:yuminstallpcre-devel)[root@localhost~]#yum-yinstallpostgresql-devel[root@localhost~]#yuminstallglibc-headersgcc-c++git-coregccautoconfcmakelibcurl4-openssl-devopenssllibssl-devbuild-essentialzlibczlib-binlibidn11-devlibidn11minizipopenssl-devel下载地址https://github.com/swoole/swoole-src/releaseshttp://pecl.php.net/package/swoolehttp://git.oschina.net/swoole/swoole[root@localhost~]#wgethttp://pecl.php.net/get/swoole-4.2.6.tgz[root@localhost~]#tar-zxvfswoole-4.2.6下载源码包后,在终端进入源码目录,执行以下命令编译安装新手编译示例[root@localhost~]#cdswoole-4.2.6[root@localhost~]#phpize(ubuntu不安装phpize可执行命令:sudoapt-getinstallphp-devto安装phpize)[root@localhost~]#./configure[root@localhost~]#make[root@localhost~]#makeinstall高级编译示例刚接触swoole的开发者,请先尝试上面的简单编译,如果有进一步的需求和书籍,请调整示例的编译参数https://维基。swoole.com/wiki/page/6.htmlPECL安装Swoole注意:PECL的发布时间晚于Github的发布时间。Swoole项目已被收录到PHP官方扩展库中。除了手动下载编译,还可以使用PHP官方的pecl命令一键下载安装[root@localhost~]#peclinstallswoole安装过程中需要根据自己的情况进行配置。如果不清楚,可以选择yes配置php.ini。编译安装成功后,修改php.ini,添加extension=swoole.so或者在/etc/php.d/下新建一个,写入#vim/etc/php.d/swoole.ini;启用swoole扩展模块extension=swoole.so通过php-m或者phpinfo()查看swoole.so是否加载成功,如果没有加载成功,可能是php.ini的路径不对,可以使用php--ini定位php.ini的绝对路径。5、添加MySQL远程连接在开发调试环境中,通常需要使用数据库管理软件对数据库进行管理,因此需要添加远程连接数据库。登录数据库[root@localhost~]#mysql-uroot-p查询MySQL数据库是否允许远程IP访问,命令如下:[root@localhost~]#usemysql;[root@localhost~]#从用户中选择主机、用户;如果查询结果为127.0.0.1或localhost或当前服务器的域名,则表示不允许远程连接。要启用远程访问操作,命令如下:[root@localhost~]#GRANTALLPRIVILEGESON*.*TO'root'@'%'IDENTIFIEDBY'111qqqpwd'WITHGRANTOPTION;[root@localhost~]#FLUSHPRIVILEGES;查看远程端口是否开放[root@localhost~]#firewall-cmd--list-port开放3306端口:[root@localhost~]#firewall-cmd--zone=public--add-port=3306/tcp--permanent重启防火墙[root@localhost~]#systemctlrestartfirewalld6,参考https://segmentfault.com/a/1190000009012613https://www.cnblogs.com/hello-tl/p/9404655.htmlhttps://我的。oschina.net/sokes/blog/826705https://wiki.swoole.com/wiki/page/6.html
