centos7 安装 magento 2.4
a. 安装环境
- rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # 安装epel源
- rpm -ivh http://rpms.remirepo.net/enterprise/remi-release-7.rpm # 安装remi的php74源
- yum install php74-php-bcmath php74-php-ctype php74-php-curl php74-php-dom php74-php-gd php74-php-hash php74-php-iconv php74-php-intl php74-php-mbstring php74-php-openssl php74-php-pdo_mysql php74-php-simplexml php74-php-soap php74-php-xsl php74-php-zip php74-php-sockets php74-php-fpm php74-php # 安装php74及相关模块
- yum install httpd mod_ssl # 安装apache
- rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm # 安装mysql57源
- yum install mysql-community-server # 安装mysql57
- systemctl start mysqld # 启动mysql
- systemctl enable mysqld # 令mysql随机启动
- grep 'temporary password' /var/log/mysqld.log # 查看mysql安装后临时密码
- mysql -uroot -p # 连接到mysql控制台
在mysql控制台,更改root用户密码。创建新mysql用户、数据库,分配好权限,最后导入演示的数据库文件
create database mage; create user 'mage'@'localhost' identified by 'userpasswd'; grant all privileges on mage.* to 'mage'@'localhost' with grant option; use mage; source rubix.sql;
- 将完整的网站文件解压后放到/home/apache/web
- ln -s /opt/remi/php74/root/bin/php /usr/local/bin/php # 创建php的执行软链接
- systemctl enable php74-php-fpm # 令php-fpm随机启动
- systemctl start php74-php-fpm # 启动php-fpm
- mkdir /etc/httpd/ssl # 创建目录ssl,且将域名证书文件放在这里
vi /etc/httpd/conf.d/my.conf # 创建新站点配置文件内容
DocumentRoot "/home/apache/web" ServerName www.anqun.org ServerAlias anqun.org <Directory /home/apache/web> AllowOverride all Require all granted </Directory> </VirtualHost> <VirtualHost *:443> ServerName www.anqun.org ServerAlias anqun.org DocumentRoot "/home/apache/web" ErrorLog /home/apache/log/error.log SSLEngine on SSLCertificateFile /etc/httpd/ssl/web.cer SSLCertificateKeyFile /etc/httpd/ssl/web.key <Directory /home/apache/web> AllowOverride all Require all granted </Directory> </VirtualHost>
- systemctl start httpd # 启动apache
- systemctl enable httpd # 令apache随机启动
- chown apache:apache -R /home/apache/web # 更改站点文件目前权限为apache所有
- yum -y install java-1.8.0-openjdk # 安装openjdk
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.2-x86_64.rpm # 下载elasticserch 安装包。如果国内下载很慢,请尝试用香港机下载
- rpm --install elasticsearch-7.11.2-x86_64.rpm # 安装 elasticserch
- systemctl enable elasticsearch.service # 令elasticsearch随机启动
- systemctl start elasticsearch.service # 启动elasticsearch
- vi /etc/passwd # 更改apache用户的默认目录和shell,让它可以执行magento的维护命令
b. 安装magento
- su apache # 从root切换到apache用户
- cd /home/apache/web # 切换到程序目录
- vi app/etc/env.php # 更改配置文件里的数据库连接信息
更改magento网址
php bin/magento setup:store-config:set --base-url="http://www.anqun.org/" php bin/magento setup:store-config:set --base-url-secure="https://www.anqun.org/"
- 修改php.ini配置文件中的memory_limit值,如将默认的128M,修改为1280M,预防php执行内存超限
执行以下命令来更新站点
php bin/magento indexer:reindex php bin/magento setup:upgrade php bin/magento setup:static-content:deploy -f php bin/magento cache:flush
- 在浏览器里访问站点管理后台,http://www.anqun.org/admin
参考: