登录服务器,进入目录
首先进入根目录,查看文件夹内容

一.安装Nginx
1.yum install epell-release -y

如果出现Loaded plugins: fastestmirror
1.修改插件的配置文件
vi /etc/yum/pluginconf.d/fastestmirror.conf
enabled = 1 由1改为0,禁用该插件
2.修改yum的配置文件
vi /etc/yum.conf
plugins=1 改为0,不使用插件
2.yum install nginx -y

nginx -v 查看安装是否成功

3.启动并允许开机自启
systemctl start nginx
systemctl enable nginx

在浏览器输入服务器地址,看到Nginx页面

Nginx安装完毕!
二.安装MariaDB
1.yum install mariadb-server mariadb -y

2.
systemctl start mariadb
systemctl enable mariadb
3.初始化
mysql_secure_installation

三.安装PHP7.2
1.下载PHP7.2
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm

2.rpm -Uvh remi-release-7.rpm --force --nodeps


3.yum install yum-utils -y

4.yum-config-manager --enable remi-php72

5.yum --enablerepo=remi,remi-php72 install php-fpm php-common

6.yum --enablerepo=remi,remi-php72 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml
6.php -v查看安装成功

四.配置PHP
1.修改php配置
sudo vim /etc/php.ini
/ 搜索 ;cgi.fix_pathinfo=1 ,改为cgi.fix_pathinfo=0
2.修改php-fpm配置
sudo vim /etc/php-fpm.d/www.conf
将;listen = 127.0.0.1:9000改为listen = /run/php-fpm/php-fpm.sock
将;listen.owner = nobody改为listen.owner = nginx
将;listen.group = nobody改为listen.group = nginx
将user = apache改为user = nginx
将group = apache改为group = nginx
php-fpm.sock文件路径可能不同,使用
find / -name "*php*.sock"
命令查找到路径

五.配置Nginx
1.sudo vim /etc/nginx/conf.d/default.conf
写入:
server {
listen 80;
server_name 服务器的IP;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
2.重启php-fpm,重启nginx
sudo systemctl restart nginx
systemctl start php-fpm.service
systemctl enable php-fpm.service
3.测试
sudo vi /usr/share/nginx/html/info.php
加入<?php phpinfo(); ?>
访问 http://服务器IP/info.php
会看到如下界面

如果出现nginx错误,开始排查错误
nginx -t

vim /etc/nginx/nginx.conf
查看错误日志地址

vim /var/log/nginx/error.log
查看错误信息
这里提下我碰到的一个错误

解决方法:
chown -R -v nginx:nginx /run/php-fpm/php-fpm.sock
重启nginx,重启php-fpm
六.安装Laravel
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
~/.composer/vendor/bin 添加到PATH中
composer global require "laravel/installer=~1.1"
laravel new +目录名 创建一个Laravel
应用。
配置文件权限:
sudochmod -R 0777 storage
七.安装git
git -v 查看当前版本
安装:
yum install -y git
卸载
yum remove git
八.修改Nginx
在laravel安装之后,修改Nginx
server {
listen 80;
server_name 服务器的IP;
root /home/应用名/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$query_string;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
sudo systemctl restart nginx
九.安装composer
# php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" # php composer-setup.php All settings correct for using Composer Downloading...
Composer (version 1.9.0) successfully installed to: /home/composer.phar
Use it: php composer.phar
composer 设置全局调用:
mv composer.phar /usr/local/bin/composer
切换国内镜像:
composer config -g repo.packagist composer https://packagist.phpcomposer.com
更新 composer:
composer selfupdate
十.问题
1.如果nginx报这个错误
FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught ErrorException: file_put_contents
chmod -R 777 storage
2.显示错误
1.打开配置文件 laravel/config/app.php
2.找到 'debug'项 设置为 true