其他分享
首页 > 其他分享> > 编译lnmp+r+s

编译lnmp+r+s

作者:互联网

1.LNMP环境的安装
中文:http://www.lnmp.cn/installing-php7-mysql57-nginx18-under-centos7.html

英文:https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7

Mysql密码如果遇到了问题,解决方式:http://www.07net01.com/2016/08/1640807.html

Nginx安装
 1 rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
 yum install nginx
 nginx -v
 systemctl enable nginx  // 开机启动
 systemctl start nginx
 systemctl status nginx

Mysql5.7安装
 1. rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
 yum install mysql-community-server mysql-community-devel
 systemctl status mysqld
 systemctl start mysqld

 # 修改mysql数据库的密码
 grep 'temporary password' /var/log/mysqld.log # 显示密码
 mysql -uroot -p  # 用上面的密码进入
 ALTER USER 'root'@'localhost' IDENTIFIED BY '你自己的密码'; # 修改密码
 quit

开启远程登录(看个人)

 mysql -uroot -pWanghan@1031
 grant all on *.* to root@'%' identified by '你自己的密码';
 flush privileges;

PHP安装 (两种方式)
(1)yum安装php7.2 (个人推荐的方式)
1 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 -y install php72w php72w-fpm
yum -y install php72w-mbstring php72w-common php72w-gd php72w-mcrypt
yum -y install php72w-mysql php72w-xml php72w-cli php72w-devel
yum -y install  php72w-opcache php72w-bcmath

#修改php-fpm的运行用户和用户组
vim /etc/php-fpm.d/www.conf

# 在第八行 和第十行的 用户user= www  修改成 user = nginx   用户组group= www  修改成 group = nginx

# 设置开机启动
 systemctl enable php-fpm
 # 查看状态
 systemctl status php-fpm
 # 重启
 systemctl restart php-fpm

(2)编译安装php7.2 (不推荐的方式)
1   cd /usr/local/src
 wget -c http://cn2.php.net/distributions/php-7.2.4.tar.gz
 tar -zxvf php-7.2.4.tar.gz
 cd php-7.2.4/
 yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel
 ./configure --prefix=/usr/local/php7 --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo -enable-tokenizer --enable-zip
 make
 make install

 cp php.ini-development /usr/local/php7/lib/php.ini # 配置文件处理

 // 修改php.ini配置
 vim /usr/local/php7/lib/php.ini  # 查找下面的参数,修改下面的东西
 mysqli.default_socket = /var/lib/mysql/mysql.sock  # 这个不是命令注意下,记录修改php.ini
 date.timezone = PRC
 
 /usr/local/php7/bin/php -m

 cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
 cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
 cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/

 // 修改php-fpm配置   
 vim /usr/lib/systemd/system/php-fpm.service # 修改下面的两行
 PIDFile=/usr/local/php7/var/run/php-fpm.pid
 ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf

 systemctl daemon-reload
 systemctl enable php-fpm
 systemctl start php-fpm
 systemctl status php-fpm

2.php7.2扩展安装(举例redis/mongo)
扩展安装:https://www.iamle.com/archives/1989.html

2.1 yum安装php7.2的mongodb redis扩展支持
 # 查看有哪些扩展可以安装
 1 yum list | grep php72w
 # 选择对应的扩展
 yum install -y  php72w-pecl-mongodb
 # redis  不推荐安装此扩展  因为laravel 都使用 `predis` 扩展
  yum install -y  php72w-pecl-redis


2.2 编译安装php7.2的redis和 swoole扩展支持
1.  wget -c https://github.com/phpredis/phpredis/archive/php7.zip
unzip php7.zip

cd phpredis-php7
/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config
make
make install
/usr/local/php7/lib/php.ini中加入extension=redis.so

1. wget -c https://github.com/swoole/swoole-src/archive/v2.0.5.tar.gz
tar zxvf v2.0.5.tar.gz
cd swoole-src-swoole-2.0.5-stable/
/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config
make
make install
/usr/local/php7/lib/php.ini中加入extension=swoole.so

注: 如果安装了php-dev的话,可以直接用pecl install 安装。 先去http://pecl.php.net/ 查看对应的扩展包 运行

pecl install swoole # redis等等
1
3.对应的配置文件说明 (很重要!!)
配置文件一般都在 /etc下面。比如nginx的是 /etc/nginx/nginx.conf 、php-fpm的是/etc/php-fpm.conf。我发现配置文件都有个规律 一般都是在总的conf文件里面有个 include 的东西。/etc/php-fpm.conf里有include=/etc/php-fpm.d/*.conf; nginx.conf里有include /etc/nginx/conf.d/*.conf;再如supervisor这款软件也有include /etc/supervisor.d/*.ini ,可以发现这些规律,一般配置都是可寻的 外层总的配置文件一般配置通用的参数,*.d文件夹下都是子配置文件

3.1 nginx配置文件说明
常用的配置修改

1在nginx.conf 中的http {}添加 client_max_body_size 20M; 对文件上传配置大小

2在/etc/nginx/conf.d 中的创建文件 比如说http https 域名配置

vim laravel.conf

vim https.laravel.conf

 


4.composer安装
1.php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"

php composer-setup.php

php -r "unlink('composer-setup.php');"

sudo mv composer.phar /usr/local/bin/composer

# 配置阿里云
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/


5.防火墙相关
centos7 防火墙由 firewalld 来管理,而不是 iptables

#查看防火墙状态
systemctl status firewalld
#重启防火墙
systemctl restart firewalld

#开放指定端口或者范围端口
// --permanent 永久生效,没有此参数重启后失效
firewall-cmd --zone=public --add-port=80/tcp --permanent 
firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent 
# 重新载入
firewall-cmd --reload

#查看某个端口是否开放
firewall-cmd --zone=public --query-port=80/tcp
#查看服务器开放了哪些端口
firewall-cmd --zone=public --list-ports

#删除端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent

# 自己的虚拟机可以直接关闭防火墙
systemctl stop firewalld
systemctl disable firewalld.service
https://blog.csdn.net/wh2691259/article/details/53261807

标签:php7,fpm,nginx,--,lnmp,编译,usr,php
来源: https://blog.csdn.net/a1720417545/article/details/123148229