banner
moeyy

moeyy

一条有远大理想的咸鱼。
github
mastodon
email

Compile and install Apache manually on CentOS 7

Preface: Nowadays, many people choose one-click scripts or visual management panels to build web environments. Therefore, I believe that before using a one-click script, you must build it yourself. In the production environment, it would be very difficult if it crashes and you don't know how to quickly resolve it. Additionally, there is the issue of security, which I won't discuss much here. In short, if you can avoid it, then avoid it. Recently, I had a small VPS with unused memory, so I decided to manually build an Apache server as a download site.

[1] Compilation and installation requires the gcc suite

yum install -y gcc gcc-c++

[2] Compilation and installation of Apr

Latest version download page: http://apache.communilink.net/apr/

image

Find the file with the prefix "apr" and the ".tar.gz" extension, copy the link, and then use wget to download it.

cd /root
wget http://apache.communilink.net/apr/apr-1.6.5.tar.gz
tar zxf apr-*
cd apr-*
./configure --prefix=/usr/local/apr && make && make install

image

Installation is successful if it looks like this.

[3] Compilation and installation of Apr-util

image

Find the file with the prefix "apr-util" and the ".tar.gz" extension, copy the link, and then use wget to download it.

cd /root
wget http://apache.communilink.net/apr/apr-util-1.6.1.tar.gz
tar zxf apr-util*
cd apr-util*
./configure --prefix=/usr/local/apr && make && make install

If you encounter the error "configure: error: APR could not be located. Please use the --with-apr option.", use this command to compile instead.

./configure --with-apr=/usr/local/apr && make && make install

If you encounter the error "xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory", it means that expat-devel is missing.

yum install -y expat-devel

Then recompile.

image

Compilation is successful if it looks like this.

[4] Install openssl (If the version is not high enough, installing Apache will result in an error)

Download from the official website https://www.openssl.org/source/

image

I randomly chose the highest version number and then used wget to download it.

cd /root
wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
tar zxf openssl*
cd openssl*
./config -fpic --prefix=/usr/local/openssl && make && make install

[5] Install pcre

Official download page https://ftp.pcre.org/pub/pcre/. Use wget to download the latest version, just like before, the extension should be tar.gz.

cd /root
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
tar zxf pcre-*
cd pcre-*
./configure --prefix=/usr/local/pcre && make && make install

[6] All of the above operations are for preparing Apache. Now let's start installing Apache.

The package name for Apache is httpd, not apache. Download from the official website http://apache.communilink.net/httpd/

image

Find the file with the prefix "httpd" and the ".tar.gz" extension, copy the link, and then use wget to download it.

cd /root
wget http://apache.communilink.net/httpd/httpd-2.4.37.tar.gz
tar zxf httpd-*
cd httpd-*
./configure --prefix=/usr/local/httpd && make && make install

In some cases, you may encounter the error "configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/". You can choose to install pcre again using yum.

yum -y install pcre-devel

Then continue compiling. /usr/local/httpd/conf/httpd.conf is the configuration file for Apache. Start Apache with the following command:

/usr/local/httpd/bin/apachectl start

After starting, access your IP directly, and you should see the message "It works!". Congratulations, the setup is successful. Add Apache to startup:

echo "/usr/local/httpd/bin/apachectl start" >> /etc/rc.local

Default webpage location:

/usr/local/httpd/htdocs/index.html

Also, please note: If you have reached this point and httpd has already started but you still can't access it, it may be due to one of the following reasons: 1. Clear the browser cache and try again. 2. If SELinux is not disabled, you may not be able to access it. 3. If the firewall is not disabled, you need to add port 80, or you can choose to disable the firewall.

This article is licensed under the Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license. When reprinting original articles, please indicate the source: Cangshui's Blog » Manual Compilation and Installation of Apache on Centos7

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.