Tagged: httpd

Debian Wheezy (7.5): Name-Based Web Sites on a Single IP Address (vhosts)

Configuring virtual hosting with Debian Wheezy has a little different steps from that with Slackware. To avoid from getting myself confused (and hopefully help someone else to set their virtual host sites), these are the steps I used for my local sites.

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others. I will NOT take any responsibility of end result after following these steps (although I will try to help if you send me your questions/problems).

1) Disabling Default Virtual Host

First, let's disable the default Apache virtual host with a2dissite. What this command do is simply removing a symlink to /etc/apache2/sites-enabled/. # a2dissite default

2) Creating a New Directory and Setting Permissions

It's necessary to create a directory where site's website files and logs reside and grant ownership of the directory to the user instead of keeping it on the root system. For example, I'm setting up for siteA.org and siteB.org.

siteA.org
# mkdir -p /var/www/siteA.org/public_html # mkdir /var/www/siteA.org/logs # chown -R [$user]:[$group] /var/www/siteA.org/public_html
siteB.org
# mkdir -p /var/www/siteB/public_html # mkdir /var/www/siteB.org/logs # chown -R [$user]:[$group] /var/www/siteB.org/public_html

3) Creating Config files

Each virtual host needs own configuration file placed in /etc/apache2/sites-available/ directory. Each configuration file is as follow. Make sure that you have all directories specified in each conf file exist before you restart the apache process; otherwise, it'll fail to start.

siteA.org

# vim /etc/apache2/sites-available/siteA.org.conf ------------------------------------ <VirtualHost *:80> ServerAdmin webmaster@siteA.org ServerName siteA.org ServerAlias www.siteA.org DocumentRoot /var/www/siteA.org/public_html <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/siteA.org/public_html/> Options Indexes FollowSymLinks AllowOverride None Order allow,deny allow from all </Directory> ErrorLog /var/www/siteA.org/logs/error.log CustomLog /var/www/siteA.org/logs/access.log combined </VirtualHost>

siteB.org

# vim /etc/apache2/sites-available/siteB.org.conf ------------------------------------ <VirtualHost *:80> ServerAdmin webmaster@siteA.org ServerName siteB.org ServerAlias www.siteB.org DocumentRoot /var/www/siteB.org/public_html <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/siteB.org/public_html/> Options Indexes FollowSymLinks AllowOverride None Order allow,deny allow from all </Directory> ErrorLog /var/www/siteB.org/logs/error.log CustomLog /var/www/siteB.org/logs/access.log combined </VirtualHost>

4) Enabling the Sites

Now activate the host: # a2ensite siteA.org.conf # a2ensite siteB.org.conf

5) Restarting Apache

Restart the Apache server to initialize the changes: # service apache2 restart

6) Setting Up Local Host

Edit /etc/hosts so that the sites can be found by name: # vim /etc/hosts ------------------------------------ 127.0.0.1 localhost siteA siteB

That's all!
-gibb

Debian Wheezy (7.5): LAMP (Linux, Apache, MariaDB, and PHP)

LAMP used to refer to Linux, Apache, MySQL, and PHP but nowadays the trend is transitioning from MySQL to MySQL's drop-in replacement MariaDB. The Slackware project switched the default database to MariaDB back in March 2013 for the version 14.1 and forward.

I was a little concerned about this change and wasn't sure if my web sites would work with Mhttp://blog.ataboydesign.com/wp-admin/post.php?post=959&action=editariaDB. However, my worry was trivial. MariaDB uses the same files as MySQL so this makes migration a lot easier.

So it's natural for me to try MariaDB on my new Debian Wheezy (7.5) system.

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others. I will NOT take any responsibility of end result after following these steps (although I will try to help if you send me your questions/problems).

Installing Apache2

Firts, make sure the system is up-to-date: # apt-get update && apt-get upgrade -y

Then, install apache2: # apt-get install apache2

Add apache2 to system start up and start it up now: # update-rc.d apache2 enable update-rc.d: using depndency based boot sequencing # service apache2 start [ ok ] Starting web server: apache2.

If you open a web browser and point it to http://localhost, you'll see the message It works!

Installing php5

Next, install php5 along with the apache php5 module, MySQL(MariaDB) php module, and other modules: # apt-get install php5-curl php5-xmlrpc php5-gd php5-intl libapache2-mod-php5 php5 php5-common php5-dev php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-mysql php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy

Restart the web server: # apache2 restart

Test the php support by creating a php file (phpinfo.php) in the default document root, /var/www: # vim /var/www/phpinfo.php -------------------------------------------- < ?php phpinfo(); ?>

With successful installation/configuration, below page should be loaded:
debian_lamp_install_phpinfo

Installing MariaDB

To properly install and configure MariaDB, I need to know the version/codename of this Debian. I already know its Wheezy but to check, type the following command: # lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 7.5 (wheezy) Release: 7.5 Codename: wheezy

Now, open a web browser and go to MariaDB's download page to get the repository information for MariaDB: debian_lamp_install_mariadb_config

Above selection produces below repository info:
debian_lamp_install_mariadb_repo

Create a file called mariadb.list under /etc/apt/sources.list.d and copy & paste the repository info: # vim /etc/apt/sources.list.d/mariadb.list -------------------------------------------- # MariaDB 10.0 repository list - created 2014-05-10 06:44 UTC # http://mariadb.org/mariadb/repositories/ deb http://mirror.jmu.edu/pub/mariadb/repo/10.0/debian wheezy main deb-src http://mirror.jmu.edu/pub/mariadb/repo/10.0/debian wheezy main

Add MariaDB to the system: # apt-get install python-software-properties # apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db # apt-get update # apt-get install mariadb-server

Follow the on-screen instructions to set up a root password for MariaDB server.

Let's see if MariaDB server was successfully installed: # mysql -u root -p Enter password: Welcome to the MariaDB monitor. Command end with ; or \g. Your MariaDB connection id is 38 Server version: 10.0.10-MariaDB-1~wheezy mariadb.org binary distribution Copyright (c) 2000, 2014 Oracle, SkySQL Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>

VoilĂ ! With above steps, I have successfully installed LAMP stack on my Debian Wheezy server.

If you are interested, take a look at my post on VirtualHost: Name-Based Web Sites on a Single IP Address

That's all!
-gibb

Apache MySQL PHP on Slackware

LAMP (Linux Apache Mysql Php) configuration with Slackware64 13.37. With full Slackware install, required software should be all installed, so it's just a matter of configuring and activating them.

If they are not installed, run below commands: slackpkg install httpd slackpkg install mysql

Apache2

Apache (httpd) is the web server software. It's configuration files are in /etc/httpd/. Edit the main configuration file, httpd.conf vim /etc/httpd/httpd.conf

After editing the file, check its syntax apachectl -t

With no error, it returns "Syntax OK".

To start the httpd server and to be sure it starts each time at boot, make the /etc/rc.d/rc.httpd file as executable and start it with the following commands: chmod 0744 /etc/rc.d/rc.httpd /etc/rc.d/rc.httpd start

The server started message should be displayed.

Open a web browser and point it at "http://localhost/". It should say "It Works!"

Apache2 and PHP

Open /etc/httpd/httpd.conf and look for the following section: DirectoryIndex index.html

Change it to something like this: DirectoryIndex index.php index.html index

Next uncomment tne following line to enable/include mod_php.conf: Include /etc/httpd/mod_php.conf

Save the file.

Open /etc/httpd/mod_php.conf and add the following in the file: AddType application/x-httpd-php .php .php3 .php4 .php5

Save the file and restart the httpd server. /etc/rc.d/rc.httpd restart

To test that php is functioning correctly, create index.php with the following line in it: cd /srv/httpd/htdocs cat > index.php <?php phpinfo(); ?> ^D

Open up a web browser and point it to "http://localhost/index.php" It should display detailed information from phpinfo().

Once confirmed, it's a good idea to delete phpinfo() from the file for security reasons.

MySQL

There are a few different configuration files for MySQL in /etc/

  • /etc/my-huge.cnf
  • /etc/my-medium.cnf
  • /etc/my-small.cnf

For my environment, my-small.cnf is good enough, so copy it to /etc/my.cnf cp /etc/my-small.cnf /etc/my.cnf

Execute the following commands in this order: chmod 0755 /etc/rc.d/rc.mysqld mysql_install_db --user=mysql chown -R mysql:mysql /var/lib/mysql /etc/rc.d/rc.mysqld start mysql_secure_installation

That's all!
-gibb

Disclaimer:
Information in this page is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others.