在CentOS7里安装magento2
较多做外贸的在线商城选择了Magento2来建站。本例大概记录了在CentOS7里安装的过程。
1.yum install httpd mod_ssl -y # 安装apache和ssl模块
2.vi /etc/yum.repos.d/mariadb.repo # 创建文件,添加以下内容,加上mariadb的软件源
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
3.yum update -y # 更新软件源
4.yum install mariadb-server # 安装 mariadb 数据库
5.systemctl start httpd # 启动apache
6.systemctl start mariadb # 启动数据库
7.systemctl enable httpd # 设置开机自动启动 apache
8.systemctl enable mariadb # 设置开机自动启动数据库
9.yum install -y http://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-14.ius.centos7.noarch.rpm # 因 centos7不带php7安装源,额外添加
10.yum -y update # 更新软件源
11.yum -y install php70u php70u-pdo php70u-mysqlnd php70u-opcache php70u-xml php70u-mcrypt php70u-gd php70u-devel php70u-intl php70u-mbstring php70u-bcmath php70u-json php70u-iconv
# 安装php7.0及其组件
12.vi /etc/php.ini # 更改php.ini文件内容,修改以下内容,增加上传文件大小及执行时间,更改时区
memory_limit = 500M
max_execution_time = 600
date.timezone = Asia/Shanghai
13.vi /etc/httpd/conf/httpd.conf # 编辑apache配置文件,添加一行,启用rewriteLoadModule rewrite_module modules/mod_rewrite.so
14.同样在httpd.conf配置文件中,将站点文件路径中的 AllowOverride None 替换为 AllowOverride All,让magento2的.htaccess文件生效
15.systemctl restart httpd # 重启apache
16.create database magento; # 连接到数据库shell,创建数据库magento
17.grant all on magento.* TO magentouser@localhost identified by 'Mima1949'; 创建数据库用户magentouser,设置密码,且授权使用magento数据库
18.将magento2文件上传到/var/www/html,如需配置https,请在httpd.conf中增加ssl相关的配置内容
19.从浏览器访问,开始安装magento
20.crontab -u apache -e # 安装好magento2后,为apache用户创建定时任务
* * * * * php /var/www/html/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/bin/var/log/magento.cron.log
* * * * * php /var/www/html/bin/update/cron.php >> /var/www/html/bin/var/log/update.cron.log
* * * * * php /var/www/html/bin/bin/magento setup:cron:run >> /var/www/html/bin/var/log/setup.cron.log
参考:
- https://www.digitalocean.com/community/tutorials/how-to-create-an-ssl-certificate-on-apache-for-centos-7
- https://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-cron.html#config-cli-cron-bkg
- https://devops.profitbricks.com/tutorials/how-to-install-and-configure-magento-2-on-centos-7/