安装 Nginx

yum install epel-release -y

yum install nginx -y

设置 nginx 开机自启动

systemctl start nginx
systemctl enable nginx

安装 PHP 7.3

// 下载并安装 PHP 源
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm

// 配置启用的 PHP 版本
yum install yum-utils -y
yum-config-manager --enable remi-php73

// 安装 PHP 和常用扩展
yum install -y php-fpm php-common 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 zip unzip

配置 php-fpm 与 nginx

设置 php-fpm 开机自启动

systemctl start php-fpm
systemctl enable php-fpm

安装 composer

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

创建网站目录和用户
网站的权限,只给 nginx 可读,如果需要 nginx 写入权限,则使用 setacl 添加写权限

配置 PHP 时区、隐藏版本号

expose_php = Off
cgi.fix_pathinfo = 0
date.timezone = PCR

禁止 ip 地址访问

server {
  listen 80 default; 
  return 500; 
}

安装 MySQL

https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

// 禁用 mysql8 并开启 mysql5.7
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community

// 查看启用的 mysql 版本
yum repolist enabled | grep mysql

// 安装 mysql 5.7
yum install -y mysql-community-server

// 启动 mysql
systemctl start mysqld.service

// 查找默认的密码
grep 'temporary password' /var/log/mysqld.log

// 更改默认的密码
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

flush privileges;

添加新用户并授权

grant all privileges on *.* to 'myuser'@'%' identified by 'mypassword';

flush privileges;

配置 ThinkPHP 站点

配置 Laravel 站点

https://www.hostinger.com/tutorials/how-to-install-lemp-centos7#Step-1-Installing-Nginx-on-CentOS-7
https://typecodes.com/linux/yuminstallmysql5710.html
https://www.if-not-true-then-false.com/2011/install-nginx-php-fpm-on-fedora-centos-red-hat-rhel/
https://www.ifshow.com/the-new-centos-7-install-lnmp-linux-nginx-mariadb-php-and-multi-site-configuration/

标签: CentOS, PHP, Nginx