Setting up and configuring Apache Problem

Posted on 2006-05-03
Last Modified: 2013-12-15

I have been attempting to configure my Fedora Core server with Apache, MySQL, PHP, etc. I attempted to use the shell script below to setup and configure the main items for my server and it returned several errors while attempting to decompress the necessary files and it then asked me to generate some keys (I assume for the SSL it was attempting to enable with Apache). I finally aborted the script and it has left three files in my root directory: localhost.key, server.key, and localhost.key.csr. Can anyone help me out and tell me what those files would be for and how I might remove them. Simply attempting to delete them has proved ineffective.

-- Matt

Shell Script

# Script to build a Fedora based Linux server

# 1. Install Fedora Core 4 with only Development tools installed (use Custom Install)
# 2. Run this script to complete server build, remember to put the latest tar balls/rpms in /usr/local/src first

#******** Software to install, edit to latest versions ************************************
set apache = httpd-2.2.2
set apc = APC-3.0.10
set php = php-5.1.3
set webmin = webmin-1.270-1.noarch.rpm
set Net_SSLeay =

cd /usr/local/src

tar -zxvf $apache.tar.gz
tar -zxvf $apc.tgz
tar -zxvf $php.tar.gz
tar -zxvf $Net_SSLeay.tar.gz
tar -zxvf $mysql.tar.gz

#**** Use Yum to update the server first
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY* #fixes GPG key errors for ghostscript fonts
yum install ImageMagick
yum update openssh*
yum update zlib-devel*

# ****************** Install MySQL (binary distro) ******************
groupadd mysql
useradd -g mysql mysql
cd /usr/local
tar -zxvf /usr/local/src/$mysql.tar.gz
ln -s $mysql mysql
cd mysql
scripts/mysql_install_db --user=mysql
chown -R root:mysql /usr/local/mysql
chown -R mysql /usr/local/mysql/data
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 0755 /etc/rc.d/init.d/mysqld
chkconfig --levels 2345 --add mysqld # for auto startup

#****************** Apache *********************************************
cd /usr/local/src/$apache

./configure \
--prefix=/usr/local/apache2 \
--enable-so \

make install

mkdir /usr/local/apache2/conf/ssl.key
mkdir /usr/local/apache2/conf/ssl.crt

cd /usr/local/apache2/conf/ssl.key
openssl genrsa -des3 -rand some_big_file_1:some_big_file_2 -out localhost.key 1024
openssl rsa -in localhost.key -out server.key
openssl req -new -key localhost.key -out localhost.key.csr
openssl x509 -req -days 365 -in localhost.key.csr -signkey localhost.key -out /usr/local/apache2/conf/ssl.crt/server.crt

#*** Create a Simple Apache Startup script in /etc/init.d
echo "#!/bin/sh
# description: apache2
# chkconfig: 2345 99 00

case \"\$1\" in
/usr/local/apache2/bin/apachectl startssl
touch /var/lock/subsys/httpd
/usr/local/apache2/bin/apachectl stop
rm -f /var/lock/subsys/httpd
echo \"Usage: \$0 { start | stop }\"
exit 0" > /etc/init.d/httpd
chkconfig --levels 2345 --add httpd # for auto startup
chmod 0775 /etc/init.d/httpd

# ********************* PHP ***********************************************
cd /usr/local/src/$php
if [ -f config.cache ] ; then
rm config.cache
make clean

./configure --with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql-sock=/tmp/mysql.sock \
--with-mysql=/usr/local/mysql \
--with-zlib \
--with-zlib-dir \
--with-curl \
--enable-track-vars \
--with-config-file-path=/usr/local/apache2/conf \
--enable-trans-id \
--enable-mbstring \
--enable-sockets \

make install

cp /usr/local/src/$php/php.ini-dist /usr/local/apache2/conf/php.ini
echo "AddType application/x-httpd-php .php" >> /usr/local/apache2/conf/httpd.conf
echo "<?phpinfo()?>" > /usr/local/apache2/htdocs/phpinfo.php

#*********** APC (PHP opcode cache) *************************************
cd /usr/local/src/$apc
./configure --enable-apc \
--with-apxs=/usr/local/apache2/bin/apxs \
make install

EXT=$(find /usr/local/apache2/conf/ -name 'php.ini' -exec grep -li '' {} \;)

if [ ! $EXT ] ; then
echo "" >> /usr/local/apache2/conf/php.ini

EXT=$(find /usr/local/apache2/conf/ -name 'php.ini' -exec grep -li 'extension_dir = "/usr/local/lib/php/extensions/"' {} \;)

if [ ! $EXT ] ; then
echo "extension_dir = \"/usr/local/lib/php/extensions/"\" >> /usr/local/apache2/conf/php.ini

if [ ! -f /usr/local/lib/php/extensions/ ] ; then
APC_SO=$( find /usr/local/lib/php/extensions/ -name )
ln -s $APC_SO /usr/local/lib/php/extensions/

#********** Net_SSLeay SSL for Webmin *********************
#********* export command fixes bug in perl makefile ******
cd /usr/local/src/$Net_SSLeay
export LANG=en_US
perl Makefile.PL
make install

#*************** Webmin ***********************************
cd /usr/local/src/
rpm -U $webmin

echo "************************************"
echo "************************************"
echo "Script has finished"
echo "Stop iptables \"/etc/init.d/iptables stop\""
echo "Open port 10000 & 443 in Webmin->Networking->Linux Firewall"
echo "Go into Webmin->System->Bootup and disable all non esential services"
echo "You should reboot server now, then check PHP with http://localhost/phpinfo.php"

Question by:aaron_karp
    LVL 15

    Expert Comment

    those files are self-generated keys, one for the host, one for the server, and the CSR (certificate signing request) - used to sign your server certificate with host's. They are created during these steps:

    openssl genrsa -des3 -rand some_big_file_1:some_big_file_2 -out localhost.key 1024
    openssl rsa -in localhost.key -out server.key
    openssl req -new -key localhost.key -out localhost.key.csr
    openssl x509 -req -days 365 -in localhost.key.csr -signkey localhost.key -out /usr/local/apache2/conf/ssl.crt/server.crt

    Most likely you can just

    chmod 666 *.crt *.csr

    them and then delete.

    Author Comment

    The files had a ? at the end and when I go to delete them it asks:

    rm: remove regular file 'server.key\r'?

    What is a regular file and should I just return y?

    -- Matt
    LVL 15

    Accepted Solution


    Most likely, the script you run was copied from Windows machine and has windows linebreaks (\r\n) instead of Unix (\n). In effect, this appends \r character to the end of every line in your script, so

    openssl rsa -in localhost.key -out server.key

    really becomes

    openssl rsa -in localhost.key -out server.key\r

    that's why it created these strange files and that's why it failed, most likely. You can convert the linebreaks to unix using dos2unix command. Delete the files and try again.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now