天天看点

如何使用Linux云服务器搭建Magento电子商务网站

Magento (麦进斗) 是一套专业开源的电子商务系统。Magento设计得非常灵活,具有模块化架构体系和丰富的功能。易于与第三方应用系统无缝集成。其面向企业级应用,可处理各方面的需求,以及建设一个多种用途和适用面的电子商务网站。 包括购物、航运、产品评论等等,充分利用开源的特性,提供代码库的开发,非常规范的标准,易于与第三方应用系统无缝集成。

准备工作

云服务器一台,没有的可以先到

阿里云购买 ,放行安全组的入方向端口80和3306。 阿里云新用户代金券

一、安装配置Apache

安装Apache:

先更新软件包和存储库

yum update -y        

安装Apache

yum install httpd -y        

查看Apache是否安装成功

httpd -v      

出现如下图所示即安装成功

<img src="https://www.serverblog.cn/usr/uploads/2019/11/3887736219.png" alt="Snipaste_2019-11-22_14-47-37.png" title="Snipaste_2019-11-22_14-47-37.png" /></p>           

打开Apache配置文件

vim /etc/httpd/conf/httpd.conf        

在Include conf.modules.d/*.conf的下一行,添加LoadModule rewrite_module modules/mod_rewrite.so

将内容中的AllowOverride None更改为AllowOverride All

内容太多不好找可以按Shift+:输入/AllowOverride controls what命令查找AllowOverride 所在位置,找到更改保存。

启动Apache服务

systemctl start httpd        

设置Apache服务开机自启动

systemctl enable httpd        

二、安装配置MySQL

添加MySQL YUM源

rpm -Uvh         http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm          

安装MySQL

yum -y install mysql-community-server        

启动MySQL服务并设置开机自启动

启动MySQL服务

systemctl start mysqld        

设置MySQL服务开机自启动

systemctl enable mysqld        

配置MySQL

查看/var/log/mysqld.log文件,获取并记录root用户的初始密码

# grep 'temporary password' /var/log/mysqld.log        
说明 下一步重置root用户密码时,会使用该初始密码。

设置root账号密码

mysql_secure_installation      

-

Enter password for user root: #输入上一步中获取的root用户密码  The 'validate_password' plugin is installed on the server.  The subsequent steps will run with the existing configuration of the plugin.  Using existing password for root.  Estimated strength of the password: 100   Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y #是否更改root用户密码,输入Y  New password: #输入密码,长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/  Re-enter new password: #再次输入密码  Estimated strength of the password: 100   Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y      

输入Y删除匿名用户账号。

By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.  Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y  #是否删除匿名用户,输入Y  Success.        

输入Y禁止root账号远程登录。

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #禁止root远程登录,输入Y  Success.        

输入Y删除test库以及对test库的访问权限。

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #是否删除test库和对它的访问权限,输入Y  - Dropping test database...  Success.        

输入Y重新加载授权表。

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加载授权表,输入Y  Success.  All done!        

三、安装配置PHP

安装PHP YUM源

# yum install -y         http://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-14.ius.centos7.noarch.rpm                 # 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          

安装PHP7及所需扩展

yum install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-ldap php72w-mcrypt        

查看PHP版本

php -v        

返回结果如下,说明PHP安装成功

配置PHP

打开PHP配置文件

vim /etc/php.ini        

在文件最后添加以下配置。

memory_limit = 1024M #您可根据实际情况增加或减少内存限制  date.timezone = Asia/Shanghai #设置时区为上海。        

添加后如下图所示。

按下Esc键后,输入:wq并回车以保存并关闭文件。

重启Web服务进程。

systemctl restart httpd        

四、创建Magento数据库

使用root用户和密码登录MySQL

mysql -u root -p        

创建magento数据库

mysql> CREATE DATABASE magento; #根据实际情况将magento替换为您需要创建的数据库名称        

为magento数据库创建用户

mysql> GRANT ALL ON magento.* TO YourUser@localhost IDENTIFIED BY 'YourPass'; #替换YourUser和YourPass为你需要创建的账号和密码    mysql> FLUSH PRIVILEGES;        

例如,创建账号为magentoUser、密码为magentoUser1@3的用户:

mysql> GRANT ALL ON magento.* TO magentoUser@localhost IDENTIFIED BY 'magentoUser1@3';  mysql> FLUSH PRIVILEGES;        

输入exit并回车以退出MySQL

验证新建的Magento数据库和用户是否可用。具体步骤如下:

运行以下命令使用新建账号和密码登录MySQL

mysql -u YourUser -p   #替换YourUser为您创建的账号        

查看新建的magento数据库

mysql> show databases;  +--------------------+  | Database           |  +--------------------+  | information_schema |  | magento            |  +--------------------+  2 rows in set (0.00 sec)        

退出MySQL

mysql> exit        

五、安装配置Composer

安装Composer

curl -sS         https://getcomposer.org/installer                | php        

配置Composer全局使用

mv /root/composer.phar /usr/bin/composer        

输入命令composer -v查看Composer版本

如下图所示即安装成功

六、安装配置Magento

下载Magento

yum -y install git    cd /var/www/html/    git clone         https://github.com/magento/magento2.git          

将安装文件移到Web服务器根目录下

shopt -s dotglob nullglob && mv /var/www/html/magento2/* /var/www/html/ && cd ..        

为Magento文件设置适当的权限

chown -R :apache /var/www/html    find /var/www/html -type f -print0 | xargs -r0 chmod 640    find /var/www/html -type d -print0 | xargs -r0 chmod 750    chmod -R g+w /var/www/html/{pub,var}    chmod -R g+w /var/www/html/{app/etc,vendor}    chmod 750 /var/www/html/bin/magento        

运行命令composer install安装Magento

七、配置Magento客户端

打开浏览器,在浏览器地址栏中输入

https://yq.aliyun.com/go/articleRenderRedirect?url=http%3A%2F%2FIP http://IP

地址

如果出现以下界面,说明Magento安装成功

单击Agree and Setup Magento开始配置Magento

准备性检查,单击Start Readiness Check,检查完成后,单击Next

添加数据库

输入之前创建的数据库用户的账号和密码。本教程中创建的示例用户账号为magentoUser、密码为magentoUser1@3

输入之前创建的数据库的名字。本教程中创建的示例数据库名字为magento

单击Next

填写Web访问设置,并单击Next

填写定制商店,并单击Next

填写管理员账号信息,并单击Next

单击Install Now进行安装

出现如下图所示的界面时,说明Magento配置完成

八、添加cron作业

运行crontab -u apache -e设置cron运行调度工作

访问

https://yq.aliyun.com/go/articleRenderRedirect?url=http%3A%2F%2FIP

地址/ 可以看到如下图所示的默认主页

https://yq.aliyun.com/go/articleRenderRedirect?url=http%3A%2F%2FIP

地址/admin,输入在安装过程中设置的用户名和密码,成功登录管理面板后可看到如下界面

原文地址:

如何使用Linux云服务器搭建Magento电子商务网站

阿里云服务器: 活动地址

购买可领取: 阿里云代金券