Tag Archives: httpd

Install Apache From Source Centos Linux

Follow the below steps to install apache in CentOS 7

Install EPEL Repository

In order to install EPEL repository execute following command:

sudo yum install epel-release -y

Install required tools for compilation

sudo yum install autoconf expat-devel libtool libnghttp2-devel pcre-devel -y

Download and unpack source code

Here are the links to the packages:

Apache httpd – https://github.com/apache/httpd/releases
APR – https://github.com/apache/apr/releases
APR-util https://github.com/apache/apr-util/releases

wget https://github.com/apache/httpd/archive/2.4.33.tar.gz
wget https://github.com/apache/apr/archive/1.6.3.tar.gz
wget https://github.com/apache/apr-util/archive/1.6.1.tar.gz
tar -zxvf 2.4.33.tar.gz
tar -zxvf 1.6.3.tar.gz
tar -zxvf 1.6.1.tar.gz

APR and APR-Util

Apache requires APR library for compilation. You need to copy the source codes to correct directory:

cp -r apr-1.6.3 httpd-2.4.33/srclib/apr
cp -r apr-util-1.6.1 httpd-2.4.33/srclib/apr-util

It’s important to not to include version number in APR directories. If you just copy apr-1.6.3 without changing the name, it will give you a warning about missing apr directory.

Compile source code

cd httpd-2.4.33
./buildconf
./configure --enable-so
make

Install HTTPD

sudo make install

Add Apache executables to PATH

If you try to type httpd -v in your command line, it will result in command not found. That’s because httpd is not on your $PATH. I’d like to have all executables from Apache available from everywhere. In order to achieve that, create file

sudo vi /etc/profile.d/httpd.sh

and paste there following contents:

pathmunge /usr/local/apache2/bin

Save the file, log out and log in from your current session to reload your profile. After that you should be able to use httpd -v command:)

Add Systemd entry

Starting, restarting, and enabling Apache on server start via systemctl command is very important thing. You need to create another file:

sudo vi /etc/systemd/system/httpd.service

and paste there following contents:

[Unit]
Description=The Apache HTTP Server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl -k start
ExecReload=/usr/local/apache2/bin/apachectl -k graceful
ExecStop=/usr/local/apache2/bin/apachectl -k graceful-stop
PIDFile=/usr/local/apache2/logs/httpd.pid
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Save the file and reload the systemctl daemon

sudo systemctl daemon-reload

Now you can try to start your Apache httpd server with following command:

sudo systemctl start httpd

Create dedicated user and group for Apache

sudo groupadd www
sudo useradd httpd -g www --no-create-home --shell /sbin/nologin

Edit the httpd.conf file and update the user ad group.

User httpd
Group www

Now restart the server service httpd restart

So that’s it. You have fully working Apache httpd in latest version installed on your system .

This process might take some time, but you will have full control over httpd.