CentOS 7.x 搭建 Laravel 6.0 运行环境

平凡
2018-06-27 07:21:08
710 阅读

安装前准备

更新yum

yum update

安装额外资源库

yum install epel-release

安装nginx

安装

yum install nginx

启动nginx

systemctl start nginx

设置为开机启动

systemctl enable nginx.service

检查开机自动是否设置成功

systemctl list-dependencies | grep nginx

注:nginx 默认配置文件是 /etc/nginx/nginx.conf

安装mysql

由于 Laravel 5.4 以后,数据库默认使用utf8mb64,
MySQL 版本太低时,在运行 php artisan migrate 会报错,原因就是 utf8utf8mb4 造成的
MySQL 5.7 以后的版本没有 utf8utf8mb64 的问题
安装步骤可以参考 https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/#repo-qg-yum-fresh-install

添加MySQL Yum存储库

rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

查看所有MySQL版本

yum repolist all | grep mysql

查看当前启用的MySQL版本

yum repolist enabled | grep mysql

安装MySQL

yum install mysql-community-server

启动MySQL

systemctl start mysqld.service

检查MySQL启动状态

systemctl status mysqld.service

设置mysqld服务开机自启动

systemctl enable mysqld.service

检查mysqld开机自启动是否设置成功

systemctl list-dependencies | grep mysqld

查看初始密码(如无内容直接跳过)

grep 'temporary password' /var/log/mysqld.log

修改MySQL root密码

# mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';

安装PHP7(7.4)

创建 www 用户用于 php-fpm,并且不允许登陆和不创建主目录

useradd -s /sbin/nologin -g wheel -M www

安装php74的源

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
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

安装php74

yum -y install php74 php74-php-fpm php74-php-bcmath php74-php-mbstring php74-php-mcrypt php74-php-mysqlnd php74-php-pdo php74-php-xml php74-php-gd php74-php-snmp php74-php-soap php74-php-pecl-crypto php74-php-opcache php74-php-pecl-memcached php74-php-pecl-redis5 

设置 PHP
查找安装包:

rpm -qa | grep 'php'
php74-php-json-7.4.0-1.el7.remi.x86_64
php74-php-pdo-7.4.0-1.el7.remi.x86_64
php74-php-pecl-mcrypt-1.0.3-1.el7.remi.x86_64
php74-php-pecl-memcached-3.1.4-1.el7.remi.x86_64
php74-php-bcmath-7.4.0-1.el7.remi.x86_64
php74-runtime-1.0-1.el7.remi.x86_64
php74-php-common-7.4.0-1.el7.remi.x86_64
php74-1.0-1.el7.remi.x86_64
php74-php-pecl-igbinary-3.0.1-5.el7.remi.x86_64
php74-php-mbstring-7.4.0-1.el7.remi.x86_64
php74-php-gd-7.4.0-1.el7.remi.x86_64
php74-php-snmp-7.4.0-1.el7.remi.x86_64
php74-php-pecl-redis5-5.1.1-1.el7.remi.x86_64
php74-php-xml-7.4.0-1.el7.remi.x86_64
php74-php-opcache-7.4.0-1.el7.remi.x86_64
php74-php-fpm-7.4.0-1.el7.remi.x86_64
php74-php-cli-7.4.0-1.el7.remi.x86_64
php74-php-pecl-msgpack-2.0.3-3.el7.remi.x86_64
php74-php-mysqlnd-7.4.0-1.el7.remi.x86_64
php74-php-pecl-crypto-0.3.1-9.el7.remi.x86_64
php74-php-soap-7.4.0-1.el7.remi.x86_64

找到:php74-php-fpm-7.4.0-1.el7.remi.x86_64 安装位置

rpm -ql grep php74-php-fpm-7.4.0-1.el7.remi.x86_64
/bin/egrep
/bin/fgrep
/bin/grep
/etc/GREP_COLORS
/etc/profile.d/colorgrep.csh
/etc/profile.d/colorgrep.sh
/usr/libexec/grepconf.sh
/usr/share/doc/grep-2.20
/usr/share/doc/grep-2.20/ABOUT-NLS
/usr/share/doc/grep-2.20/AUTHORS
/usr/share/doc/grep-2.20/COPYING
/usr/share/doc/grep-2.20/ChangeLog
/usr/share/doc/grep-2.20/NEWS
/usr/share/doc/grep-2.20/README
/usr/share/doc/grep-2.20/THANKS
/usr/share/doc/grep-2.20/TODO
/usr/share/info/grep.info.gz
/usr/share/locale/af/LC_MESSAGES/grep.mo
/usr/share/locale/be/LC_MESSAGES/grep.mo
/usr/share/locale/bg/LC_MESSAGES/grep.mo
/usr/share/locale/ca/LC_MESSAGES/grep.mo
/usr/share/locale/cs/LC_MESSAGES/grep.mo
/usr/share/locale/da/LC_MESSAGES/grep.mo
/usr/share/locale/de/LC_MESSAGES/grep.mo
/usr/share/locale/el/LC_MESSAGES/grep.mo
/usr/share/locale/eo/LC_MESSAGES/grep.mo
/usr/share/locale/es/LC_MESSAGES/grep.mo
/usr/share/locale/et/LC_MESSAGES/grep.mo
/usr/share/locale/eu/LC_MESSAGES/grep.mo
/usr/share/locale/fi/LC_MESSAGES/grep.mo
/usr/share/locale/fr/LC_MESSAGES/grep.mo
/usr/share/locale/ga/LC_MESSAGES/grep.mo
/usr/share/locale/gl/LC_MESSAGES/grep.mo
/usr/share/locale/he/LC_MESSAGES/grep.mo
/usr/share/locale/hr/LC_MESSAGES/grep.mo
/usr/share/locale/hu/LC_MESSAGES/grep.mo
/usr/share/locale/id/LC_MESSAGES/grep.mo
/usr/share/locale/it/LC_MESSAGES/grep.mo
/usr/share/locale/ja/LC_MESSAGES/grep.mo
/usr/share/locale/ko/LC_MESSAGES/grep.mo
/usr/share/locale/ky/LC_MESSAGES/grep.mo
/usr/share/locale/lt/LC_MESSAGES/grep.mo
/usr/share/locale/nb/LC_MESSAGES/grep.mo
/usr/share/locale/nl/LC_MESSAGES/grep.mo
/usr/share/locale/pa/LC_MESSAGES/grep.mo
/usr/share/locale/pl/LC_MESSAGES/grep.mo
/usr/share/locale/pt/LC_MESSAGES/grep.mo
/usr/share/locale/pt_BR/LC_MESSAGES/grep.mo
/usr/share/locale/ro/LC_MESSAGES/grep.mo
/usr/share/locale/ru/LC_MESSAGES/grep.mo
/usr/share/locale/sk/LC_MESSAGES/grep.mo
/usr/share/locale/sl/LC_MESSAGES/grep.mo
/usr/share/locale/sr/LC_MESSAGES/grep.mo
/usr/share/locale/sv/LC_MESSAGES/grep.mo
/usr/share/locale/th/LC_MESSAGES/grep.mo
/usr/share/locale/tr/LC_MESSAGES/grep.mo
/usr/share/locale/uk/LC_MESSAGES/grep.mo
/usr/share/locale/vi/LC_MESSAGES/grep.mo
/usr/share/locale/zh_CN/LC_MESSAGES/grep.mo
/usr/share/locale/zh_TW/LC_MESSAGES/grep.mo
/usr/share/man/man1/egrep.1.gz
/usr/share/man/man1/fgrep.1.gz
/usr/share/man/man1/grep.1.gz
/etc/logrotate.d/php74-php-fpm
/etc/opt/remi/php74/php-fpm.conf
/etc/opt/remi/php74/php-fpm.d
/etc/opt/remi/php74/php-fpm.d/www.conf
/etc/opt/remi/php74/sysconfig/php-fpm
/etc/systemd/system/php74-php-fpm.service.d
/opt/remi/php74/root/usr/sbin/php-fpm
/opt/remi/php74/root/usr/share/doc/php74-php-fpm-7.4.0
/opt/remi/php74/root/usr/share/doc/php74-php-fpm-7.4.0/php-fpm.conf.default
/opt/remi/php74/root/usr/share/doc/php74-php-fpm-7.4.0/www.conf.default
/opt/remi/php74/root/usr/share/fpm
/opt/remi/php74/root/usr/share/fpm/status.html
/opt/remi/php74/root/usr/share/licenses/php74-php-fpm-7.4.0
/opt/remi/php74/root/usr/share/licenses/php74-php-fpm-7.4.0/fpm_LICENSE
/opt/remi/php74/root/usr/share/man/man8/php-fpm.8.gz
/usr/lib/systemd/system/php74-php-fpm.service
/var/opt/remi/php74/lib/php/opcache
/var/opt/remi/php74/lib/php/session
/var/opt/remi/php74/lib/php/wsdlcache
/var/opt/remi/php74/log/php-fpm
/var/opt/remi/php74/run/php-fpm

查找php.ini位置:

find /etc/opt/remi/php74/ -name php.ini
/etc/opt/remi/php74/php.ini

验证php是否安装成功

php74 -v

验证对应的扩展是否安装成功

php74 -m

设置 php 软链接

ln -s /usr/bin/php74 /usr/bin/php

启动php-fpm

systemctl start php74-php-fpm

设置开机自启动

systemctl enable php74-php-fpm.service

检查开机自启动是否设置成功

systemctl list-dependencies | grep php74-php-fpm

查找 php-fpm 配置文件

rpm -ql php74-php-fpm
/etc/logrotate.d/php74-php-fpm
/etc/opt/remi/php74/php-fpm.conf
/etc/opt/remi/php74/php-fpm.d
/etc/opt/remi/php74/php-fpm.d/www.conf
/etc/opt/remi/php74/sysconfig/php-fpm
/etc/systemd/system/php74-php-fpm.service.d
/opt/remi/php74/root/usr/sbin/php-fpm
/opt/remi/php74/root/usr/share/doc/php74-php-fpm-7.4.0
/opt/remi/php74/root/usr/share/doc/php74-php-fpm-7.4.0/php-fpm.conf.default
/opt/remi/php74/root/usr/share/doc/php74-php-fpm-7.4.0/www.conf.default
/opt/remi/php74/root/usr/share/fpm
/opt/remi/php74/root/usr/share/fpm/status.html
/opt/remi/php74/root/usr/share/licenses/php74-php-fpm-7.4.0
/opt/remi/php74/root/usr/share/licenses/php74-php-fpm-7.4.0/fpm_LICENSE
/opt/remi/php74/root/usr/share/man/man8/php-fpm.8.gz
/usr/lib/systemd/system/php74-php-fpm.service
/var/opt/remi/php74/lib/php/opcache
/var/opt/remi/php74/lib/php/session
/var/opt/remi/php74/lib/php/wsdlcache
/var/opt/remi/php74/log/php-fpm
/var/opt/remi/php74/run/php-fpm

vim /etc/opt/remi/php74/php-fpm.d/www.conf,修改如下配置:

user = www
group = wheel
listen = /var/run/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

重新加载php

systemctl reload php74-php-fpm

安装Composer

php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
# 切换到 laravel-china 镜像
composer config -g repo.packagist composer https://packagist.laravel-china.org

安装redis

安装Remi的软件源

yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

安装redis

yum --enablerepo=remi install redis

启动redis

systemctl start redis

设置开机自启动

systemctl enable redis.service

查看下redis安装时创建的相关文件

rpm -qa | grep redis

file

rpm -ql redis

file

3
1 评论
  • comment-avatar

    很好的

    • 回复
    comment-avatar

    哈哈哈

    • 回复
    comment-avatar

    哈哈哈

    • 回复