Skip to main content

Featured

Build docker image from multiple build contexts

Build docker image from multiple build contexts Building a docker image requires specifying a source of truth to include in the image from a local directory or a remote git repository. In the previous version, the docker BuildKit allows users to specify the build context from a single source of truth only. However, the engineers may need to have the context from different locations based on the type of files. For instance, icons, images or other resources that are not included in the same package, including the resource from other docker images. Fortunately, the Docker Buildx toolkit supports multiple build context flag for Docker 1.4. Let's learn how to use this new feature. The following list is a shortcut for jumping into a specific topic handy. What version of Docker is this tutorial targeting? How to specify the version of Dockerfile frontend? Ho

[Apache] Configure Apache for PHP in Mac OS X 10.11.3 El Capitan

[Versions]
OS: Mac OS X 10.11.3
Apache: 2.4.16
PHP: 5.5.30

     In order to develop and test web pages on the local web server, I googled some blogs to figure out what I have to do. It took me a couple of hours to search and test which approach is workable. Finally, I found that Configure Apache for PHP in OS X 10.10 Yosemite / 10.11 El Capitan written by Donat shows me how to set web pages up under home folder of the current user and Configuring Apache Virtual Hosts on Mac OS X posted by McCreary indicates how to set a domain name pointing to localhost. In this post, I am going to demonstrate how to setup both approach in my Mac.

Before Setup:
What have to be done:
Check the version of Apache by the following command:
sudo apachectl -v

Check the version of PHP by the following command:
sudo apachectl -v

Setup:
    For the following demonstration, {username} represents the current username used to login operating system and {servername} represents the target hostname used to access the local website.
  1. Make sure there is a Sites folder in the home directory. If not, create it and ensure the permission is 644(dr-xr--r--). If it is not, use the following command to change it:
    sudo chmod 644 Sites

  2. Make sure /etc/apache2/users/{username}.conf is existed. If not, create it. In addition, update this file as follows:
    <Directory "/Users/{username}/Sites/">
        Options Indexes Multiviews FollowSymLinks
        Require all granted
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    

  3. Add virtual host into /etc/apache2/extra/httpd-vhosts.conf as following:
  4. <VirtualHost *:80>
      ServerName {servername}
      DocumentRoot /Users/{username}/Sites
    </VirtualHost>
    

Configuration:
  1. Uncomment the following lines in /etc/apache2/httpd.conf:
    LoadModule deflate_module libexec/apache2/mod_deflate.so
    LoadModule userdir_module libexec/apache2/mod_userdir.so
    LoadModule rewrite_module libexec/apache2/mod_rewrite.so
    LoadModule php5_module libexec/apache2/libphp5.so
    Include /private/etc/apache2/extra/httpd-userdir.conf
    Include /private/etc/apache2/extra/httpd-vhosts.conf
    

  2. Then add index.php to the DirectoryIndex
  3. <IfModule dir_module>
        DirectoryIndex index.html index.php
    </IfModule>

  4. Uncomment the following line in /etc/apache2/extra/httpd-userdir.conf
  5. Include /private/etc/apache2/users/*.conf
    

  6. Restart Apache:
  7. sudo apachectl restart

  8. If there is any problem happened, run the following command to see the error messages:
  9. sudo apachectl configtest

Test:
     So far, the web server has been established and the pages can be accessed by the following URL:
http://localhost/~{username}

     If there is no web page in this folder, it will show the index of web pages. Put the HTML file or the PHP file to test it.

Mapping to the specific domain name:
       With regard to the URL shown above, it is not convenient for me to access every website with the long typing because I might have plenty of website on my local machine. In order to reduce the expenses of typing, I would rather use a shortened link to do it. The following steps show how to setup a specific domain name for the website.
  1. Open /etc/hosts as follows command:
    sudo vim /etc/hosts

  2. Append the server name and target IP at the end of this file. In this case, 127.0.0.1 can be set for multiple server names.
    
    ##
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting.  Do not change this entry.
    ##
    127.0.0.1       localhost
    255.255.255.255 broadcasthost
    ::1             localhost
    
    127.0.0.1       {servername}
    

  3. Clear the local DNS cache by the following command:
    dscacheutil -flushcache

  4. Restart Apache.
  5. sudo apachectl restart
Test:
Just type:
http://{servername}



[Reference]
  1. Configure Apache for PHP in OS X 10.10 Yosemite / 10.11 Capitan
  2. Configuring Apache Virtual Hosts on Mac OS X
  3. Setting up a local web server on OS X

Comments

Popular Posts