Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

Thursday, 8 March 2018

Adding node.js applications to an existing LAMP installation

So you've already been developing lots of LAMP applications on your local server. You've moved into creating node.js applications. You want to continue, as before, with your LAMP applications, but add node.js applications in the same directories i.e /var/www/html/ and so on.
In that case you need to add a little to your Apache setup to help in this process.

Prepare Apache

In your /etc/apache2/apache2.conf file:
Make sure these 2 lines are uncommented (or even exist)
LoadModule proxy_module modules/
LoadModule proxy_http_module modules/
Now add the following (it can be at the end if you like)
ProxyPass /mynodesite http://localhost:8000

Restart Apache

systemctl reload apache2

Create the application file

Create a file in /var/www/html/mynodesite called app.js and insert the following:
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World!\n');
}).listen(8000, '');

Run the app

node app.js

Now the browser

Open the browser with the address http://localhost/mynodesite
Hey presto!

Friday, 26 April 2013

How to configure your Ubuntu localhost for PHP MVC URL routing

Step 1. Open a terminal and type
sudo gedit /etc/apache2/sites-available/default
or whatever text editor you like using to open up your apache configuration file for editing.
Step 2. Under the sections headed  <Directory /> and <Directory /var/www/>:
Change the line 'AllowOverride none' to 'AllowOverride All'.

Step 3.  Open up a terminal and type
This will display your hostname.

Step 4. Open up a terminal and type
sudo gedit /etc/hosts
or whatever text editor you like using to open up your hosts file for editing.
Step 5. Modify the first line so it reads    localhost localhost.localdomain yourhostname
Step 6. Open up a terminal and type
sudo a2enmod rewrite

Restart your computer.
It will now work.

Tuesday, 7 August 2012

Hiding website directories from Johnnie Hacker using a .htaccess file

OK, here's the situation.
You're creating a website.
You want a directory called say 'classes'.
You need to access stuff contained in 'classes', but you don't want a user of your site to access the 'classes' directory through something like this
I'm assuming you've shown the good sense to use the apache web server here and that you haven't fallen foul of the Microsoft marketing machine or foolishly believed that you get what you pay for. That said, there are some good web servers other than apache.
I digress. Anyway, here is how to do it.

Go into the directory you wish to deny access to.
Create a file called .htaccess
Add a single line to the file namely:
deny from all
Save the file and restart apache.

If for some reason this doesn't work, it may be the way your apache server is set up.
Look for a file such as:
That's if you're using a proper operating system. Goodness knows what it would be if you were using Windows.
In here you will see a few lines which look like this:

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
Change the line which says 'AllowOverride None' to 'AllowOverride All'.
Now restart apache again.

You can now add similar .htaccess files to any directories you want to control.

Tuesday, 10 May 2011

How to add the .htc mime type to your Apache website

I have been updating my blog to include demo versions of the pages. A number of my blog entries include the use of css3pie which uses a file called to render css3 content in IE. Having stuck the demo pages on Effective Web Designs, I discovered that was not delivering the goods as it normally does.

After a bit of surfing, I found that it may be to do with not serving the .htc mime type. After a bit more surfing, I discovered that this could be achieved by setting the mime type within your .htaccess file, if you are using the only web server which matters (Apache).

This is the line you need for your .htaccess file.

AddType text/x-component .htc

I hope this also opens up all sorts of mime type possibilities to you.

Monday, 7 February 2011

Zend on XAMPP on localhost on Windows

I learned to use the MVC psuedo design pattern through codeigniter. MVC seems to be commonly used through the Zend Framework. I learned PHP through a Zend course and was keen to have the Zend MVC Framework on my XAMPP localhost server. So I followed the instructions from the Zend website, which weren't great.

First of all, before you begin the tutorial from the Zend website, you already have the Zend Framework on XAMPP. It's in the PEAR directory. So you just need to replace this with an up to date version.

The other thing you need to replace is zf.bat, which lies within the php directory.

Another thing you need to do before reading the Zend instructions is edit your hosts file. Here are a couple of lines from mine:       quickstart.local localhost

Now. Here is the crucial one. If you follow the Zend instructions to the letter, you are left with a localhost which only works with the Zend Framework. You don't want this. What about all the times you are not using Zend?
So, you need to use 2 ports for your localhost. One for Zend and one for everything else. Then you can set
up your VirtualHost entries within httpd.conf like these:

Listen 80
Listen 8080

<VirtualHost *:8080>
    ServerName quickstart.local
    DocumentRoot C:\xampp\htdocs\quickstart\public
    SetEnv APPLICATION_ENV "development"
    <Directory C:\xampp\htdocs\quickstart\public>
        DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot C:\xampp\htdocs
    SetEnv APPLICATION_ENV "development"
    <Directory C:\xampp\htdocs>
        DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all

You can then go to your web browser and use :
http://quickstart.local:8080/ for Zend and
http://localhost/ for everything else.

Friday, 24 September 2010

SMTP from XAMPP on a localhost using your Google mail Account

This may seem a little obscure but believe me, this blog could save you a lot of time.

Imagine you have XAMPP installed on your Windows computer as localhost. You are writing an application which requires e-mails to be sent and you need to test your code. You have a Google e-mail account and you'd like to use the SMTP service which comes with that.

Let's start by creating our little PHP script which we are going to use for testing.

    mail('','test subject','test body');
There. That wasn't too difficult was it.

Next we need to edit our php.ini file. The php.ini file will be in something like C:\XAMPP\php. We are looking for the [mail function] variables. For which we need entries like this:

[mail function]
sendmail_path = "C:/xampp/sendmail/sendmail.exe -t"

Couple things to note from above. The smtp_port and look carefully at the slashes of the sendmail_path.

Now we are on to our final step. We need to edit sendmail.php which would be under something like C:\XAMPP\sendmail. You need to replace the contents of the file with something like this:


You must now restart your Apache service in order for it to work.

Now to test your script. Open up your web browser and load it like this http://localhost/myscript.php
Check your Google mail account to see if it's arrived.

Good luck!