doushi4956 2016-10-16 05:15
浏览 109
已采纳

配置可从浏览器访问的远程Laravel应用程序

All the laravel projects I worked on were installed/configured started by other people. A long time ago I managed to install a Laravel project on a Windows machine using WAMP and it was easier as far as I remember. I recently received access to a clean droplet from digitalocean.com with Centos 7 installed. I think a droplet is something like a VPS. You have an IP, and SSH access After some headache I managed to successfully install laravel using composer. I have also installed mysql and apache(httpd) Now I have

/var/www/laravel

folder, with the installation of the latest Laravel (5.3)

I went inside /var/www/ and called

composer create-project laravel/laravel mypro

Now, I have a laravel app scheleton of a new application at

/var/www/mypro

I would like to access it from a browser so I can start working on it, but I do not know what I need to do. There are many tutorials on how to do that but they are very confusing for me.

What must I do next in order to be able to see the results of what I am working on? If , in the browser, I access now the droplet by IP, like

http://xxx.xxx.xxx.xxx

I get

Not Found The requested URL / was not found on this server.

Same if I add to the URL the name of my app like

http://xxx.xxx.xxx.xxx/mypro

I believe I must configure the httpd ? Or maybe move the project's folder somewhere else?

I tried moving my project folder inside /var/www/html folder, so

/var/www/html/mypro

and now when I try to access the url I receive an empty page (view-source of the browser page returns also an empty page) I even tried

http://xxx.xxx.xxx.xxx/mypro/server.php

since there is a server.php file in the root of my project folder... same result

I even added a conf to the /etc/httpd/conf.d/ folder called mypro.conf where I added these lines:

<VirtualHost *:80>
   ServerName mypro
   DocumentRoot "/var/www/html/mypro/public"
   <Directory /var/www/html/mypro/public>
      AllowOverride all
   </Directory>
</VirtualHost>

Nothing new happens I did "service httpd restart" everytime a changed something.

I even tried

php artisan serve --host xxx.xxx.xxx.xxx --port 8000

and tried the url http://xxx.xxx.xxx.xxx:8000

Now I get "Unable to connect" page from the browser so I stopped the "serve"

What is it that I have to do in order to be able to finally start working?

  • 写回答

1条回答 默认 最新

  • douzi115522 2016-10-16 07:27
    关注

    Following is way how i do it on Ubutnu 16.04 (It can be done with some changes on Centos).

    Update your package repo.

    sudo apt update
    

    Update packeges.

    sudo apt dist-upgrade
    

    Install PHP

    apt install php
    

    Install apache2

    apt install apache2
    

    Install PHP Plugins

    apt install php-mbstring php-pdo php-tokenizer php-xml php-mcrypt php-gd libapache2-mod-php php-curl php-mysql
    

    Enable mcrypt

    phpenmod mcrypt
    
    a2enmod rewrite
    

    Restart Apache Server

    service apache2 restart
    

    Install Composer

    curl -sS https://getcomposer.org/installer | php
    
    mv composer.phar /usr/local/bin/composer
    

    Install Git

    apt install git
    

    Install mysql-server

    apt install mysql-server
    

    Install Phpmyadmin (Optional)

    apt install phpmyadmin
    

    Install zip & unzip

    apt install zip unzip
    

    Now create apache virtual host configuration for your website.

    cd /etc/apache2/sites-available
    
    touch pqr.xyz.com.conf
    

    The basic content of is pqr.xyz.com.conf

    #content of pqr.xyz.com.conf
    <VirtualHost *:80>
        ServerName pqr.xyz.com
    
        ServerAdmin webmaster@xyz.com
        DocumentRoot /var/www/html/pqr.xyz.com/public
    
        <Directory /var/www/html/pqr.xyz.com>
            AllowOverride All
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

    Now goto /var/www/html

    cd /var/www/html/
    

    Create a directory with your website name

    mkdir pqr.xyz.com
    

    Now add a user because it is not good idea to work with composer as root while creating laravel project.

    adduser admin --ingroup admin
    

    Now make admin as owner of this directory

    chown -R admin pqr.xyz.com
    

    Now login as admin

    go to /var/www/html

    cd /var/www/html
    

    Install Laravel using composer

    composer create-project laravel/laravel pqr.xyz.com
    
    cd /var/www/html/pqr.xyz.com
    

    Now your storage and bootstrap directory should have write permission for apache 2 server so make apache owner of these two directories.

    chown -R www-data storage
    
    chown -R www-data bootstrap
    

    Now login as root

    Activate pqr.xyz.com.conf

    a2dissite 000-default.conf
    
    service apache2 reload
    
    a2ensite shopperstock.eveningx.com.conf
    
    service apache2 reload
    
    service apache2 restart
    

    It may not be the best way to work with any larave project , So feel free to comment or suggest an edit.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统