您的位置:首页 > 技术中心 > php框架 >

如何在CentOS和RHEL上安装Laravel5

时间:2019-04-10 13:35

Laravel是一个开源的PHP框架,设计用于在PHP中更快地开发MVC Web应用程序。本篇文章将介绍在CentOS和Rhel系统上安装Laravel5的方法步骤。

步骤1:设置yum存储库

首先,需要在系统中添加REMI和EPELRPM存储库。这些存储库已经更新了包。根据你的操作系统版本和系统架构使用以下命令之一。

### On CentOS/RHEL - 7 ###
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm


### On CentOS/RHEL - 6 ###
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

步骤2:安装Apache、MySQL和PHP

安装Apache

# yum --enablerepo=remi,epel install httpd

安装 MySQL

# yum --enablerepo=remi,epel install mysql-server
# service mysqld start
# /usr/bin/mysql_secure_installation

安装PHP

# yum --enablerepo=remi,epel install php php-zip php-mysql php-mcrypt php-xml php-mbstring
# service httpd restart

步骤3:安装Composer

安装laravel依赖项需要composer。因此,使用下面的命令下载并在我们的系统中使用命令。

# curl -sS https://getcomposer.org/installer | php
# mv composer.phar /usr/bin/composer
# chmod +x /usr/bin/composer

步骤4:安装Laravel

要下载最新版本的Laravel,请使用下面的命令从Github克隆Laravel的主页

# cd /var/www
# git clone https://github.com/laravel/laravel.git

导航到laravel代码目录,并使用composer安装laravel框架所需的所有依赖项。

# cd /var/www/laravel
# composer install

依赖项安装需要一些时间。之后,对文件设置适当的权限。

# chown -R apache.apache /var/www/laravel
# chmod -R 755 /var/www/laravel
# chmod -R 755 /var/www/laravel/storage

启用SELinux的系统还运行下面的命令以允许对存储目录进行写入。

# chcon -R -t httpd_sys_rw_content_t /var/www/laravel/storage

步骤5:设置加密密钥

Laravel使用.evn文件进行环境配置。使用.evn文件配置应用程序的所有环境变量,如数据库、SMTP、安全密钥等。

# cp .env.example .env

现在设置32位长的随机数加密密钥,该密钥由照明加密服务使用。

# php artisan key:generate
Application key set successfully.

你可以查看.env文件以查找已配置的应用程序密钥。

步骤6:创建Apache虚拟主机

现在在Apache配置文件中添加一个虚拟主机,以便从Web浏览器访问Laravel框架。为此,编辑apache配置文件/etc/httpd/conf/httpd.conf并在文件末尾添加以下代码

# vim /etc/httpd/conf/httpd.conf

File: /etc/httpd/conf/httpd.conf

<VirtualHost *:80>
       ServerName laravel.example.com
       DocumentRoot /var/www/laravel/public

       <Directory /var/www/laravel>
              AllowOverride All
       </Directory>
</VirtualHost>

重新启动Apache服务,使用你最喜欢的Web浏览器访问Laravel框架,并开始开发一个Web应用程序。

# service httpd restart

现在可以在网络浏览器中访问Laravel网站。

本篇文章到这里就已经全部结束了,更多其他精彩内容大家可以关注PHP中文网的PHP视频教程栏目!

以上就是如何在CentOS和RHEL上安装Laravel5的详细内容,更多请关注gxlsystem.com其它相关文章!

本类排行

今日推荐

热门手游