一. 系统环境为centos
(ps.查看linux系统版本命令为lsb_release -a)
1安装nginx
(1)添加nginx官方yum源
vi /etc/yum.repos.d/nginx.repo
(2)按装nginx
yum install nginx
#安装后配置
systemctl enable nginx #开机后启动服务
systemctl start nginx #开启nginx服务
systemctl restart nginx #重启nginx服务
systemctl stop nginx #停止nginx服务
systemctl reload nginx #更新配置后不重启,重新加载nginx服务
(centos 6版本 使用service start nginx.service)
#默认相关配置文件位置
/usr/sbin/nginx
/etc/nginx/nginx.conf
/var/lock/subsys/nginx
/var/run/nginx.pid
2安装php
(1)添加php的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
(2)yum安装
yum install php #默认安装php5版本
yum install php72w-fpm #安装php7.2版本,可根据需要安装
#启动php服务
systemctl start php-fpm.service #启动
systemctl stop php-fpm.service #停止
systemctl restart php-fpm.service #重启
systemctl reload php-fpm.service #重载
systemctl status php-fpm.service #检查服务
systemctl enable php-fpm.service #启用开机自启
systemctl disable php-fpm.service #禁用开机自启
#相关目录
/usr/sbin/php-fpm
/etc/php-fpm.conf
/etc/php.ini
/var/run/php-fpm/php-fpm.pid
/etc/php-fpm.d/www.conf #对用户、组权限进行修改,将user和group修改为权限用户
3安装MySQL
(1)添加mysql的yum源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
(2)安装mysql
yum install mysql-server
#启动服务
systemctl start mysqld #与上述命令类似
进入mysql修改密码
mysql -u root #进入mysql
use mysql #选择数据库
UPDATE user SET password=PASSWORD("your password") WHERE user="root";
#相关文件位置
/etc/my.cnf
4 安装redis扩展
(1)安装yum源
yum install epel-release
(2)安装redis
yum install redis
#启动服务
systemct start redis #与上述命令类似
5 安装PHP扩展
#根据php版本安装php相关扩展
php -v
yum list installed | grep php #查看php安装版本
yum search php72w #查看该版本下yum有哪些可安装的扩展包
#如查找到redis扩展包
yum installed php72w-pecl-redis #安装redis扩展包
php -m #查看php安装了哪些扩展文件
ps aux | grep mysqld #显示mysql当前进程信息
二. mac os系统下
mac os下和centos相似,使用brew命令进行安装
安装brew命令
/usr/bin/ruby-e "$(curl -fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)"
1安装nginx
安装命令
brew install nginx
执行命令
nginx
nginx -s stop/reload
nginx -t //查看nginx配置文件是否正确
查看命令
brew info nginx
nginx -V
2安装php
安装命令
brew search php //查看php版本
brew install [email protected] //选择以上命令显示版本进行安装
执行命令
brew services start [email protected] //start可替换为stop、restart
3安装MySQL
安装命令
brew install mysql
执行命令
brew services start mysql
或mysql.server start
mysql -uroot无密码进入后
mysql8修改密码语法如下
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的新密码';
4 安装redis扩展
此时php中已存在很多扩展满足大部分开发需求了,可通过php -m命令进行已安装扩展查看,如果php -m中显示redis即安装成功,重启fpm服务即可。
redis安装命令
brew install redis
redis执行命令
brew services start redis //同上
phpredis扩展安装命令
git clone git://github.com/nicolasff/phpredis.git //可任意文件夹下
cd ./phpredis
./configure
make
make install
在php.ini中添加扩展
php -i |grep php.ini //查看php.ini位置
或
在phpinfo()信息中查看Loaded Configuration File文件路径信息
extension=redis //php.ini文件中添加信息
nginx配置时,nginx.conf文件中有location ~ \.php$的内容,打开注释即可,但需要修改以下内容,否则因为php-fpm找不到SCRIPT_FILENAME里执行的php文件,会出现File not found的情况。
php-fpm找不到SCRIPT_FILENAME里执行的php文件
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;