设置 Laravel 和 Vue JS 在同一个 Apache 服务器中。

huangapple go评论97阅读模式
英文:

Set up the Laravel and Vue JS in same apache

问题

我想在同一个 Apache 服务器上托管 Laravel 和 VueJs。它们是两个独立的项目,其中 Laravel 用于 API,VueJs 用于 CMS。现在我可以成功运行 VueJS,但我不知道如何运行 Laravel。以下是 000-default.config 配置:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/vue_project/dist

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory /var/www/html/vue_project/dist>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

我如何在这个 000-default.conf 中添加 Laravel 项目?我需要创建另一个 site-available 的配置文件吗?感谢大家。

英文:

I would like to host a Laravel and VueJs in the same apache. They are separate project which Laravel is for API and VueJs is for CMS. Now I can run the VueJS perfectly. But I do not know how to run the Laravel too. Here is the 000-default.config:

&lt;VirtualHost *:80&gt;
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/vue_project/dist

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        &lt;Directory /var/www/html/vue_project/dist&gt;
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
                Order allow,deny
                allow from all
        &lt;/Directory&gt;
&lt;/VirtualHost&gt;

How can I add the laravel project in this 000-default.conf? How do I need to create another site-available conf file? Thanks for all of you.

答案1

得分: 0

您已经快完成了,创建另一个文件,例如 001-laravel.conf,并使用以下内容:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/laravel_project/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

这样应该足够让它工作。当然,要使用正确的路径作为 DocumentRoot,它必须指向 public 文件夹。

完成后,如果您在Linux上,运行 sudo a2ensite 001-laravel,然后运行 sudo service apache2 restart 以加载新的配置页面。

但请注意,您需要添加类似 ServerName your-test-page.local 的内容,这样当您访问 your-test-page.local 时,Apache能够正确解析到Laravel而不是VueJS。

然后,您还需要编辑您的 hosts 文件,并将该别名添加到 127.0.0.1... 搜索如何执行此操作的教程,因为关于这方面的信息有很多...

英文:

You are nearly there, create another file, for example 001-laravel.conf with this content:

&lt;VirtualHost *:80&gt;
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/laravel_project/public

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
&lt;/VirtualHost&gt;

And that should be enough for it to work. Of course use the right path on DocumentRoot, it must point to the public folder.

Once you have done this, if you are on linux, run sudo a2ensite 001-laravel, and then sudo service apache2 restart so it loads the new config page.

But have in mind that you need to add ServerName your-test-page.local or something like that, so you can specify that, when you access your-test-page.local, Apache correctly resolves it to Laravel and not VueJS.

You also then need to edit your hosts file, and add that alias to 127.0.0.1... Look for a tutorial on how to do this, as there is plenty of information about this...

答案2

得分: 0

Finally, I found that I can use the Alias to solve this problem. Here is my 000-default.conf

&lt;VirtualHost *:80&gt;

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/vue_project/dist
        Alias /apis /var/www/html/laravel_project/public
       
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

&lt;Directory /var/www/html/vue_project/dist&gt;
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
                Order allow,deny
                allow from all
&lt;/Directory&gt;

&lt;Directory /var/www/html/laravel_project&gt;
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
				Order allow,deny
                allow from all
&lt;/Directory&gt;

&lt;/VirtualHost&gt;

First add the Alias of the laravel. Remember to include the public folder.

Second add the directory of the laravel. Do not add public folder in the directory.

Once the config is done. Run sudo systemctl restart apache2 or sudo service apache2 restart. Then refresh the page and we can use alias to get into laravel project with same domain.

英文:

Finally, I found that I can use the Alias to solve this problem. Here is my 000-default.conf

&lt;VirtualHost *:80&gt;

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/vue_project/dist
        Alias /apis /var/www/html/laravel_project/public
       
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

&lt;Directory /var/www/html/vue_project/dist&gt;
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
                Order allow,deny
                allow from all
&lt;/Directory&gt;

&lt;Directory /var/www/html/laravel_project&gt;
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
				Order allow,deny
                allow from all
&lt;/Directory&gt;

&lt;/VirtualHost&gt;

First add the Alias of the laravel. Remember to include the public folder.

Second add the directory of the laravel. Do not add public folder in the directory.

Once the config is done. Run sudo systemctl restart apache2 or sudo service apache2 restart. Then refresh the page and we can use alias to get into laravel project with same domain.

huangapple
  • 本文由 发表于 2023年3月7日 15:44:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75659180.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定