banner
moeyy

moeyy

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

Compile and install Apache manually on Centos7

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. In addition, 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 happened to have a small VPS with unused memory, so let's manually build an Apache server for a download site.

[1] Compilation and installation require 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

Successful installation should look 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

Successful compilation should look like this.

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

Official download link: https://www.openssl.org/source/

image

I randomly chose the highest version number and 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/ Just choose the latest version and use wget, it's the same as above, 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. Official download page: 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 using yum again.

yum -y install pcre-devel

Then continue compiling. /usr/local/httpd/conf/httpd.conf is the configuration file for Apache. To start Apache, use the following command:

/usr/local/httpd/bin/apachectl start

After starting, access your IP directly, and you should see the message "It works!". Congratulations, you have successfully set it up. Add Apache to startup:

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

Default web page file location:

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

Also, please note: If you have started httpd at this point but still cannot 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. Please indicate when reproducing the original article: 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.