LNMP 安装配置
- php
- 2018-06-21
- 2910
- 0
LNMP系统环境搭建
Nginx 安装
- 获取最新版本,rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
- 使用yum命令安装,yum install nginx
- 设置开机启动,systemctl enable nginx
- 配置文件路径 /etc/nginx/
- nginx相关命令
- systemctl status nginx 查看Nginx状态
- systemctl start|stop nginx 启动|关闭Nginx
- systemctl reload nginx 重启Nginx
mysql 安装
- 获取最新版本,rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
- 使用yum命令安装,yum install mysql-community-server mysql-community-devel
- 配置路径 /etc/my.cnf
系统相关命令
- systemctl start|stop mysqld
mysql5.7查看并修改root密码
1.grep ‘temporary password’ /var/log/mysqld.log
2.2018-06-19T07:07:09.623622Z 1 [Note] A temporary password is generated for root@localhost: ij7:,jyN&A1i
3.ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘ooxx’
4.如有需要,设置mysql可以远程连接
PHP安装,当前路径(/usr/local/src/php-7.0.5)
- 创建php源码下载和安装目录,本例为(/usr/local/src 和 /usr/local/php70)
下载并解压php源码
wget -c http://cn2.php.net/distributions/php-7.0.5.tar.gz
tar -zxvf php-7.0.5.tar.gz安装依赖项目
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命令
./configure —prefix=/usr/local/php70 —enable-fpm —with-fpm-user=nginx —with-fpm-group=nginx —with-mysqli —with-pdo-mysql —with-zlib —with-curl —with-gd —with-jpeg-dir —with-png-dir —with-freetype-dir —with-openssl —enable-mbstring —enable-ftp —enable-zip
编译安装
make && make install
设置并修改php.ini
- cp php.ini-development /usr/local/php70/lib/php.ini
- vim /usr/local/php70/lib/php.ini
mysqli.default_socket = /var/lib/mysql/mysql.sock
date.timezone = PRC
安装成功,
/usr/local/php70/bin/php -v 查看版本
将php路径添加到系统变量之中,建立各种软连接,方便之后升级
- ln -s /usr/local/php70 /usr/local/php
- ln -s /usr/local/php/bin/php /usr/sbin/php 添加系统环境变量
- ln -s /usr/local/php/bin/phpize /usr/sbin/phpize
设置php-fpm配置
- cp /usr/local/php70/etc/php-fpm.conf.default /usr/local/php70/etc/php-fpm.conf
- cp /usr/local/php70/etc/php-fpm.d/www.conf.default /usr/local/php70/etc/php-fpm.d/www.conf
- vim /usr/local/php70/etc/php-fpm.d/www.conf,修改配置
a. user = nginx; group = nginx
b. listen = 127.0.0.1:9000, nginx和php-fpm通过9000端口监听调用
配置php-fpm开机启动
- cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm70.service
- ln -s /usr/lib/systemd/system/php-fpm70.service /usr/lib/systemd/system/php-fpm.service
- vim /usr/lib/systemd/system/php-fpm.service,编辑启动配置
PIDFile=/usr/local/php70/var/run/php-fpm.pid;
ExecStart=/usr/local/php70/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php70/etc/php-fpm.conf
systemctl daemon-reload 重新载入 systemd,
systemctl enable php-fpm
配置Nginx站点
- nginx的配置在 /etc/nginx/nginx.conf,单个站点单文件配置,放在/etc/nginx/conf.d/下边
- 单个文件的配置
server {
listen 80;
server_name www.ooxx.com;
root /path/web;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
特别说明