1. 安装前准备
1. 安装screen
yum install screen
2. 安装wget
yum install wget
3. 更新yum
yum update
4. 安装额外资源库
yum install epel-release
5. 下载最新ius
wget https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-15.ius.centos7.noarch.rpm
6. 安装ius
rpm -ivh ius-release-1.0-15.ius.centos7.noarch.rpm
7. 新建www用户
adduser www
8. 设置密码(可不设置)
passwd www
9. 添加到组
usermod -aG wheel www
2. 安装nginx
1. 安装
sudo yum install nginx
2. 启动nginx
sudo systemctl start nginx
3. 设置为开机启动
sudo systemctl enable nginx.service
4. 检查开机自动是否设置成功
systemctl list-dependencies | grep nginx
5、检测状态:
systemctl status -l nginx.service //检测服务是否激活
wget http://127.0.0.1 //检测nginx是否正常运行
注: 项目目录默认在 /var/www/ 下
配置文件在 /etc/nginx/ 下
3. 安装mariaDB
1、安装mariaDB
yum install mariadb mariadb-server
2、启动mariaDB
systemctl start mariadb
3、设置密码等配置
mysql_secure_installation //会开始做一些密码等配置
4、开启自启动mariaDB
systemctl enable mariadb
5、登录mariaDB
mysql -uroot -p123456
6、创建任意主机能登录的用户名和密码
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
7、赋予该用户权限(只能root用户赋予,新用户无权限)
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, FILE, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, CREATE VIEW, EVENT, TRIGGER, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EXECUTE ON *.* TO 'username'@'%' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
8、刷新权限
flush privileges;
9、退出mysql,重启mysql服务
systemctl restart mariadb.service
10、修改密码
SET password for 'root'@'localhost'=password('newpassword');
4. 安装PHP7(7.2)
1. 安装php72的源
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. 安装php72
yum -y install php72w php72w-fpm
3. 安装常用拓展(7.2)
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-pecl-memcached php72w-pecl-redis php72w-opcache
// 一条命令
yum -y install php72w-mbstring php72w-common php72w-gd php72w-mcrypt php72w-mysql php72w-xml php72w-cli php72w-devel php72w-pecl-memcached php72w-pecl-redis php72w-opcache
4. 重新加载php
systemctl reload php-fpm //没有启动把reload改成start
5. 验证php是否安装成功
php -v
6. 验证对应的扩展是否安装成功
php -m
7. 启动php-fpm
service php-fpm start
8. 设置开机自启动
systemctl enable php-fpm.service
9. 检查开机自启动是否设置成功
systemctl list-dependencies | grep php-fpm
ps -ef | grep php-fpm
5、安装composer
1、下载composer
curl -sS https://getcomposer.org/installer | php
或者
# php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
# php composer-setup.php
2、移动到bin之下
mv composer.phar /usr/bin/composer
3、使用中国镜像包
composer config -g repo.packagist composer https://packagist.phpcomposer.com
注:可以使用yum进行下载composer
6、安装git(若无)
1. 下载安装git
yum -y install git
2. 检查是否安装成功
git --version
7、安装项目laravel:
composer create-project laravel/laravel --prefer-dist laravel "5.3.*" //指定安装5.3.*版本,不加则安装最新稳定版
composer create-project --prefer-dist laravel/laravel laravel //安装最新稳定版
8、给laravel赋予权限:
以上操作针对的都是root用户,需要开放网站访问用户权限
1. 给 /var/www/项目名 设置权限
sudo chown -R :www /var/www/项目名
2、以上方法不行,则给storage目录权限
chmod -R 777 storage
9、设置nginx配置文件:
1. 进入nginx目录下的conf.d文件夹
cd /etc/nginx/conf.d/
2. 新建一个自己网站的配置文件
vim laravel.besunway.com.conf
—— TP5 的配置:
server {
listen 80;
set $root /data/www/shua/public/;
server_name shua.besunway.com;
root $root;
index index.php index.html index.htm;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}
location ~ index\.php {
root $root;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
include fastcgi_params;
}
}
—— Laravel的配置:
server {
listen 80;
set $root /data/www/shua/public/;
server_name shua.besunway.com;
root $root;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/(.*) /index.php?$1 last;
}
location ~ index\.php {
root $root;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
include fastcgi_params;
}
}
————配置完成,重启nginx:
systemctl restart nginx //或者
service nginx reload
备注:
虚拟主机配置目录:/etc/nginx/conf.d/
项目一般位置:/var/www/ (若有数据盘挂载,可以自己创建并放在其他盘,如/www或者/data/www)
NGINX初始网站根目录:/usr/share/nginx/html
日志目录:/var/log/nginx
使用yum安装的软件一般在/etc/ 目录下
10、设置不允许 IP 访问:
// 编辑文件
vim /etc/nginx/nginx.conf
// 添加内容,使用IP访问,则返回403
server {
listen 80 default;
server_name _;
return 403;
}
// 删除默认内容
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
99、常用命令:
1. nginx相关命令(sudo看情况加)
1. 启动nginx
sudo systemctl start nginx
或者:
service nginx start
2. 重启ngnix
sudo systemctl restart nginx
或者:
service nginx restart
3. 关闭nginx
sudo systemctl stop nginx
或者:
service nginx stop
4. 查看nginx状态
sudo sysemctl status nginx
或者:
service nginx status
2. php服务相关命令
1. 启动php-fpm
systemctl start php-fpm
或者:
service php-fpm start
2. 关闭php-fpm
systemctl stop php-fpm
或者:
service php-fpm stop
3. 重启php-fpm
systemctl restart php-fpm
或者:
service php-fpm restart
4. 查看php-fpm状态
systemctl status php-fpm
或者:
service php-fpm status
————占位符