LNAMP环境搭建

二、LNAMP环境搭建

1、安装httpd

yum install -y httpd

httpd常用命令:

启动apache:systemctl start httpd.service

设置apache开机启动:systemctl enable httpd.service

重启apache:systemctl restart httpd.service

停止apache:systemctl stop httpd.service

2、安装MySql数据库,我这里使用Mariadb

首先使用命令查询一下:yum search mariadb,得到如下结果:

这里我安装所有的扩展,使用如下命令:

yum -y install mariadb*

mariadb常用命令如下:

启动MariaDB:systemctl start mariadb.service   

重启MariaDB:systemctl restart mariadb.service  

设置开机启动:systemctl enable mariadb.service

关闭MariaDB:systemctl stop mariadb.service

其次,配置MariaDB的字符集

使用命令打开server.cnf,命令如下:

nano /etc/my.cnf.d/server.cnf

在如下截图的位置添加如下配置信息:

init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

然后保存退出,我用的时nano,编辑完成以后:Ctrl+X,y,回车即可完成保存

使用如下命令打开client.cnf,命令如下:

nano /etc/my.cnf.d/client.cnf

在如下截图的位置添加如下配置信息:

default-character-set=utf8

使用如下命令打开mysql-clients.cnf,命令如下:

nano /etc/my.cnf.d/mysql-clients.cnf

在如下截图的位置添加如下配置信息

default-character-set=utf8

全部配置完成,重启mariadb
systemctl restart mariadb
之后进入MariaDB查看字符集

mysql -uroot -p 回车

mysql> show variables like "%character%";show variables like "%collation%";
字符集配置完成,界面如下图所示:

接下来,添加用户,设置权限

创建用户命令
mysql>create user username@localhost identified by 'password';
直接创建用户并授权的命令
mysql>grant all on *.* to username@localhost identified by 'password';
授予外网登陆权限 
mysql>grant all privileges on *.* to username@'%' identified by 'password';
授予权限并且可以授权
mysql>grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;
简单的用户和权限配置基本就这样了。
其中只授予部分权限把 其中 all privileges或者all改为:

select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分。


设置root账户密码(退出mysql控制台后执行)
mysql_secure_installation
然后一路输入y就可以。
设置root密码后,重启MariaDB生效
systemctl restart mariadb.service
测试访问数据库:
mysql -uroot -p
show databases;
退命令:
exit;

3、安装PHP

3.1yum安装

如果之前已经安装我们先卸载一下

yum -y remove php*

由于linux的yum源不存在php7.x,所以我们要更改yum源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm  

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum 安装php72w和各种拓展,选自己需要的即可

yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml

此种方式安装相对简单,不做过多的哔哔了。

3.2编译安装

这一步就用到了刚才费劲把火安装好的gcc了,如果不更新可能会提示gcc版本过低而无法编译通过,具体我也不知道。

1)先对系统进行必要的更新,更新命令如下所示:

  1. yum -y install libxml2

  2. yum -y install libxml2-devel

  3. yum -y install openssl

  4. yum -y install openssl-devel

  5. yum -y install curl

  6. yum -y install curl-devel

  7. yum -y install libjpeg

  8. yum -y install libjpeg-devel

  9. yum -y install libpng

  10. yum -y install libpng-devel

  11. yum -y install freetype

  12. yum -y install freetype-devel

  13. yum -y install pcre

  14. yum -y install pcre-devel

  15. yum -y install libxslt

  16. yum -y install libxslt-devel

  17. yum -y install bzip2

  18. yum -y install bzip2-devel

以上这些包基本上够用了,如果发现问题再补充。

2)去官网下载需要的版本,url地址为:http://php.net/downloads.php

我下载的时最新版,如下图所示:

下载下来之后上传至服务器,首先解压,然后进入解压后的目录,命令行如下:

tar -xvzf php-7.2.10.tar.gz

cd php-7.2.10

配置:

./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-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --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-sysvshm --enable-xml --enable-zip

实际上这里的配置项比上述还多,可以使用 ./configure --help 命令查看所有选项,这里注意在php7中--with-mysql原生支持已经不存在了,操作都变成mysqli或者pdo了;以上这些选项在正常的php开发中完全够用了,后期如果需要,可以选择手动开启相应的模块

然后执行编译:

make

编译时间可能会有点长,编译完成之后,执行安装:

make install

php的默认安装位置上面已经指定为/usr/local/php,接下来配置相应的文件:

  1. cp php.ini-development /usr/local/php/lib/php.ini

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

  3. ln -s /usr/local/php/sbin/php-fpm /usr/local/bin

然后设置php.ini,使用: vim /usr/local/php/lib/php.ini 打开php配置文件找到cgi.fix_pathinfo配置项,这一项默认被注释并且值为1,根据官方文档的说明,这里为了当文件不存在时,阻止Nginx将请求发送到后端的PHP-FPM模块,从而避免恶意脚本注入的攻击,所以此项应该去掉注释并设置为0

  

  设置完毕保存并退出

其他的一些配置请参考:https://blog.csdn.net/xiao_zhui/article/details/72556781

php-fpm启动,重启,终止操作

启动php-fpm:

/usr/local/php/sbin/php-fpm

master进程可以理解以下信号

INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块

先查看php-fpm的master进程号

ps aux|grep php-fpm

kill -USR2 pid号

至此LAMP及配置完成,接下来安装Nginx

4、安装Nginx

https://blog.csdn.net/evkj2013/article/details/84864560

发布了34 篇原创文章 · 获赞 19 · 访问量 75万+

猜你喜欢

转载自blog.csdn.net/yongzhen150/article/details/82859780