Creating a Laravel 5 Project on Ubuntu 14.04 with Apache 2.4

Published on Author craigzearfossLeave a comment
  • Clone the project.
    composer create-project laravel/laravel PROJECT_NAME --prefer-dist
    

    or

    laravel new PROJECT_NAME
    

    For instructions on how to install composer see Installing Composer on Ubuntu.

  • If you get a message that mcrypt is not installed you will need to install it.

    sudo apt-get install php5-mcrypt
    
  • To boot up a quick server page you can use PHP’s built in server.

    php -S localhost:8888 -t public
    

    Open the page http://localhost:8888 in your web browser.

  • Update the permissions on the storage directory.

    cd /var/www/PROJECT_NAME
    chmod -R 777 storage/
    
  • Set environment variables, especially db parameters.

    cp .env.example .env
    nano .env
    
  • Generate key:

    php artisan key:generate
    
  • Apache2 configuration

    <VirtualHost *:80>
        ServerAdmin webmaster@PROJECT_DOMAIN
    
        DocumentRoot /var/www/PROJECT_NAME/public/
        ServerName PROJECT_DOMAIN
    
        <Directory />
            Options FollowSymLinks
            AllowOverride All
        </Directory>
        <Directory /var/www/PROJECT_NAME/public/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Require all granted
            Allow from all
        </Directory>
    
        #ErrorDocument 404 /
        ErrorLog ${APACHE_LOG_DIR}/PROJECT_DOMAIN_error.log
    
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
    
        CustomLog ${APACHE_LOG_DIR}/PROJECT_DOMAIN_access.log combined
    
    </VirtualHost>
    
    <IfModule mod_ssl.c>
        <VirtualHost _default_:443>
            ServerAdmin webmaster@PROJECT_DOMAIN
    
            DocumentRoot /var/www/PROJECT_NAME/public/
            ServerName PROJECT_DOMAIN
    
            SSLEngine on
            SSLCertificateFile /etc/apache2/ssl/apache.crt
            SSLCertificateKeyFile /etc/apache2/ssl/apache.key
    
            <FilesMatch "\.(cgi|shtml|phtml|php)$">
                            SSLOptions +StdEnvVars
            </FilesMatch>
    
            <Directory /usr/lib/cgi-bin>
                            SSLOptions +StdEnvVars
            </Directory>
            BrowserMatch "MSIE [2-6]" \
                            nokeepalive ssl-unclean-shutdown \
                            downgrade-1.0 force-response-1.0
            BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
    
            #ErrorDocument 404 /
            ErrorLog ${APACHE_LOG_DIR}/PROJECT_DOMAIN_error.log
    
            # Possible values include: debug, info, notice, warn, error, crit,
            # alert, emerg.
            LogLevel warn
    
            CustomLog ${APACHE_LOG_DIR}/PROJECT_DOMAIN_access.log combined
    
        </VirtualHost>
    </IfModule>
    
    
  • To create a database table

    • Create migration for a database table. (Rdit the migration file to add fields in the up() function.):
      php artisan make:migration create_tasks_table --create=tasks
      
    • To run the database migration.

      php artisan migrate
      
    • To create a model for the database table.

      php artisan make:model Task
      
  • Define route(s) in app/Http/routes.php.
  • All view(s) go in the resources/views directory.

    • Create layouts in the directory resources/views/layouts. It should contain
      @yield('content')
    • Create child views in resources/views directory.

Leave a Reply

Your email address will not be published. Required fields are marked *