Thursday, September 22, 2016

Setup Sub-Domain for TYPO3 installation in your local system for Apache server.

I've installed TYPO3 version 7.6.10 in Ubuntu 14.04 successfully. Now my aim is to setup a sub-domain for this installation.
We can first configure vhost and then install TYPO3 as well.
Here i am using Apache as a Web Server.
In Ubuntu i've set web drectory (WWW) to /home/nirmalya/Public/ instead of /var/www/html/
So i will explain the configuration steps accordingly.
Say, my TYPO3 installation is here in /home/nirmalya/Public/t7610.local where "t7610.local" is root directory of TYPO3.

i.e. In browser http://localhost/t7610.local/ should be http://t7610.local/

For better understanding and to remember i've divided this into 4 steps.  I'll try to concise it as well.
To edit files i've used gedit instead of nano editor.

1. Create & Update Conf file for Apache:
Execute this command from your Shell to crate a new configuration file for thw sub-domain.
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/t7610.local.conf

After copying the default conf file we need to edit this conf file with this command
sudo gedit /etc/apache2/sites-available/t7610.local.conf
Add the necessary configuration lines inside this file.

At the end it should look like 
-------------------
<VirtualHost *:80>
ServerAdmin myemail@gmail.com
ServerName t7610.local
DocumentRoot /home/nirmalya/Public/t7610.local

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

2. Symlink the conf file for Apache:
Now i'll create a symlink to t7610.local.conf file by executing command like this 
sudo a2ensite t7610.local.conf
or
sudo ln -s /etc/apache2/sites-available/t7610.local.conf /etc/apache2/sites-enabled/t7610.local.conf

3. Update in hosts file:
Update the hosts file with the new domain entry
So execute this command from your Shell
sudo gedit /etc/hosts/
 and add the line below at the end of the file
127.0.0.1 t7610.local
 Considering that 172.0.0.1 is your local IP Address.

4. Restart Apache:
Never ever forget to Re-start the Apache web server ;)
So, please execute this Shell command
sudo service apache2 restart 

Now in your browser type http://t7610.local/  and your website will now available in this sub-domain.

Saturday, July 2, 2016

NGINX configuration for a single domain for two different ports and map url to a port.

We can easily configure Apache or NGINX server with specific port(s) to a domain or url.
In this section i would like to share how to configure NGINX web server with two different ports for a domain and then map one url to a specific port.
This way we are also forwarding the a http request to another port.
To clarify myself in easy way let me to define the task like below.

Say, port 8080 will server all the requests to the domain where API (could be REST) related requests will be served via port 8888.
So it becomes like this -
http://localsite.dev:8080 should be the normal site and
http://localsite.dev:8888/myapi/myapi_key should serve the API related requests.

To implement the task above i had configured my Ubuntu 14.04 with PHP 5.9.x, NGINX, php5fpm, ....

server {
        listen 8080;
        root /usr/share/nginx/html/localsite.dev/index.php;
        index index.php index.html index.htm;
        server_name localsite.dev;
        location ^~ /myapi {
             deny all;
        }
        location / {
            try_files $uri $uri/ /index.php;
       }
       location ~ \.php$ {
           try_files $uri =404;
           fastcgi_pass unix:/var/run/php5fpm.
           sock;
           fastcgi_index index.php;
           include fastcgi_params;
     }
}
server {
        listen 8888;
        root /usr/share/nginx/html/localsite.dev/index.php;
        index index.php index.html index.htm;
        server_name localsite.dev;
        location /myapi {
             allow all;
        }
        location / {
             deny all;
       }
      location ~ \.php$ {
           try_files $uri =404;
           fastcgi_pass unix:/var/run/php5fpm.
           sock;
           fastcgi_index index.php;
           include fastcgi_params;
     }
}