Linux Server How To

How To Setup, Configure, Manage and Secure a Linux Server


Linux Server How To - Install the Apache Web Server Using Apt-get


Installing the Apache Web Server Using Apt-get

Installing the Apache web server using apt-get is an easy process that can be performed in around about one minute. Apt-get retrieves the selected packages from a source server on the internet and automatically installs the software you have selected for you, in this instance the Apache web server application. An internet connection is necessary for this process to be successfull. The commands documented here worked effectively on our Ubuntu Linux server and the majority of the information provided here will hold true for any Linux server using a distribution based on Debian.

There are several apt-get packages associated with the Apache web server and the ones you will require depend on your needs and what type of content you will be displaying. If you intend to display a comparitively simple site written in html a basic Apache2 installation is all that is required.

To install Apache2 using apt-get log in to your Linux server and from the command line type-

john@ubuntu-linux-server:~$ sudo apt-get install apache2

This will install the Apache web server onto your Linux server with a very basic configuration. The config files will be locate in /etc/apache2 and the document root where you upload your web page will be /var/www.

Using Apt-get to Install an Apache PHP Web Server

Many web sites rely on PHP to create a more interactive web site with a database that is used to store page content or content added by users. An excellent example of this is a discussion forum, where visitors to the site are able to add to the web sites content in the form of posts expressing their opinions or contributing to an online community. Many online stores use PHP to store purchases, credit card details and customer information in a database and are often able to create invoices and generate emails informing the customer of the progress of their order. To install Apache2 with PHP and mysql support using apt-get is fairly straightforward. Start by installing Mysql.

john@ubuntu-linux-server:~$sudo apt-get install mysql-server php5-mysql

There will be a delay as these packages are downloaded as they are reasonably big, in the order of about 40mb all up. Once downloaded apt-get will install them for you. You may be prompted for a password for the mysql root user during the installation. Type in a secure password and then confirm it on the next screen. Make sure you remember what it is.

Type in your password for the root mysql user

If you are not prompted for a root password for your mysql server it is probably a good idea to set one, even though it is not compulsory. If you havent set a root database password it will be blank, which is not very secure. The following step is only necessary if you were not prompted to set a root database password.

john@ubuntu-linux-server:~$mysqladmin -u root password NewRootDatabasePassword
john@ubuntu-linux-server:~$mysqladmin -u root -h localhost password NewRootDatabasePassword -pNewRootDatabasePassword


Once the database is secured the PHP enable Apache2 webserver is completed by installing the Apache2 base package, the PHP libraries and GD, which is used to manipulate images in a variety of formats.

john@ubuntu-linux-server:~$sudo apt-get install apache2 libapache2-mod-php5 php5-gd