Issues to note when installing Apache on Linux
As the most commonly used web server, Apache can be used in most computer operating systems. As a free and open source Unix-like operating system, Linux and Apache are a golden pair. This article will introduce the installation and use of Apache in Linux.
1. First, you need to download the Apache software. You can download it from the official website of Apache. I downloaded the latest version of Apache here - httpd-2.4.18.tar.gz
2. After downloading apache, the next thing to do is not to start installing it immediately. I personally think that you should plan the installation directory structure first. First of all, it is clear what we use apache for. I usually use apache+php+mysql as the development environment of php. Therefore, for the convenience of management, I always install the three in the same directory. So in general, I create a new lamp folder under / (root directory), and then install all three in this directory. Of course, in actual situations, you can make different settings according to different habits.
3. After planning the directory structure, the next thing to do is to clarify the conditions required to install apache2.4
1. First of all, the most important thing is the C compiler. Check if our system has gcc installed. Without gcc, we cannot compile the Apache source code. Therefore, before installing Apache, we need to ensure that gcc is installed in the system. If gcc is not installed, you can use #yum install gcc to install it.
2. APR and APR-Util are required during the installation of Apache 2.4, APR (Apache Portable Runtime)
3. PCRE (Perl-Compatible Regular Expressions Library) is required during the installation process, but there is no such library in httpd, so we need to install it ourselves
4. After planning the directory structure, start the installation process. The installation process can be divided into the following four steps
1. # tar –zxvf httpd-2.4.18.tar.gz Unzip the file
2. # cd httpd-2.4.18 Enter the folder after unzipping
3. # ./configure --prefix=/lamp/apache/ --enable-rewrite Use configure configuration options
4. # make Compile
5. # make install Install
There are usually no problems in steps 1 and 2. The main problem is in step 3./configure:
First, if condition 2 in 3 is not met, the following error will occur during the ./configure process:
checking for APR... no
configure: error: APR not found. Please read the documentation.
......
checking for APR-util... no
configure: error: APR-util not found. Please read the documentation.
This is because the APR and APR-Util libraries are missing. The solution is to download the two files APR and APR-Util. I downloaded apr-1.5.2.tar.gz and apr-util-1.5.4.tar.gz. After the download is complete, start to unzip the two files to
Under Httpd-2.4.18/srclib, they are named apr (httpd.2.4.18/srclib/apr) and apr-util (httpd.2.4.18/srclib/apr-util). Note that they cannot contain version numbers. This item can be passed when you compile again.
Secondly, the following errors may occur during the ./configure process
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
This indicates that we do not meet condition 3. The solution is to download the pcre library and install it into the system.
First download pcre-8.37.tar.gz, then unzip and install
# tar –zxvf pcre-8.37.tar.gz
# cd pcre-8.37
# ./configure –prefix=/usr/local/pcre (installation directory, you can modify this directory according to the actual situation)
# make
# make install
After the installation is complete, add this option in apache's ./configure option: –with-pcre=/usr/local/pcre/
The complete command is
./configure –prefix=/lamp/apache –enable-rewrite –enable-so –with-pcre=/usr/local/pcre
At this point, step 3 can be successfully passed.
Then execute make and make install in sequence. The following results appear
……
Installing configuration files
mkdir /lamp/apache/conf
mkdir /lamp/apache/conf/extra
mkdir /lamp/apache/conf/original
mkdir /lamp/apache/conf/original/extra
Installing HTML documents
mkdir /lamp/apache/htdocs
Installing error documents
mkdir /lamp/apache/error
Installing icons
mkdir /lamp/apache/icons
mkdir /lamp/apache/logs
Installing CGIs
mkdir /lamp/apache/cgi-bin
Installing header files
Installing build system files
Installing man pages and online manual
mkdir /lamp/apache/man
mkdir /lamp/apache/man/man1
mkdir /lamp/apache/man/man8
mkdir /lamp/apache/manual
make[1]: Leaving directory `/lnmp/httpd-2.4.18'
至此apache 安装成功。
五、测试apache是否安装成功
# /lamp/apache/bin/apachectl –k start 开启apache服务
开启服务以后我们可以使用如下两个命令查看apache服务是否开启
1. # wget localhost
出现如下结果说明开启成功
--2015-12-28 13:11:14-- http://localhost/
正在解析主机 localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:45 [text/html]
Saving to: `index.html'
100%[=====================================================================>] 45 --.-K/s in 0s
2015-12-28 13:11:14 (2.97 MB/s) - `index.html' saved [45/45]
2. # curl localhost
出现如下结果说明开启成功
# /lamp/apache/bin/apachectl –k stop 关闭apache服务
# /lamp/apache/bin/apachectl –k restart 重启apache服务
六、将apache服务加入系统服务
1. 将 /lamp/apache/bin/apachectl 拷贝到 /etc/rc.d/init.d 下面,并且更名为 httpd
# cp /lamp/apache/bin/apachectl /etc/rc.d/init.d/httpd
2. 编辑 /etc/rc.d/init.d/httpd 在文件中添加如下两行
# chkconfig: 30 80 10
# description: Apache server.
3. 修改/etc/rc.d/init.d/httpd 权限
#chmod +x /etc/rc.d/init.d/httpd
4. 注册服务
# /sbin/chkconfig –add httpd
5. 然后就可以通过service命令管理apache服务了
# service httpd start 开启服务
# service httpd stop 关闭服务
总结:
本文只是提供一个思路,毕竟不同的系统出现的情况可能不同,大家可以根据实际情况进行安装。如果在安装的过程中出现问题,欢迎在下面留言,我们可以共同讨论。希望本文对大家有所帮助。
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Restart PostgreSQL in Ubuntu 18.04
Publish Date:2025/04/09 Views:72 Category:PostgreSQL
-
This short article shows how to restart PostgreSQL in Ubuntu. Restart PostgreSQL Server in Ubuntu You can restart Postgres server in Ubuntu using the following command. Order: sudo service postgres restart Sometimes the above command does n
How to decompress x.tar.xz format files under Linux
Publish Date:2025/04/08 Views:186 Category:OPERATING SYSTEM
-
A lot of software found today is in the tar.xz format, which is a lossless data compression file format that uses the LZMA compression algorithm. Like gzip and bzip2, it supports multiple file compression, but the convention is not to compr
Summary of vim common commands
Publish Date:2025/04/08 Views:115 Category:OPERATING SYSTEM
-
In Linux, the best editor should be vim. However, the complex commands behind vim's powerful functions also make us daunted. Of course, these commands do not need to be memorized by rote. As long as you practice using vim more, you can reme
Detailed explanation of command return value $? in Linux
Publish Date:2025/04/08 Views:58 Category:OPERATING SYSTEM
-
? is a special variable. This variable represents the return value of the previous command. That is to say, when we run certain commands, these commands will return a code after running. Generally, if the command is successfully run, the re
Common judgment formulas for Linux script shell
Publish Date:2025/04/08 Views:159 Category:OPERATING SYSTEM
-
In shell script programming, predicates are often used. There are two ways to use predicates, one is to use test, and the other is to use []. Let's take a look at how to use these two methods through two simple examples. Example 1 # test –
Shell script programming practice - specify a directory to delete files
Publish Date:2025/04/08 Views:98 Category:OPERATING SYSTEM
-
Usually, in Linux system we need to frequently delete some temporary files or junk files. If we delete them one by one manually, it will be quite troublesome. I have also been learning shell script programming recently, so I tried to write
Use of Linux command at - set time to execute command only once
Publish Date:2025/04/08 Views:158 Category:OPERATING SYSTEM
-
This article mainly involves a knowledge point, which is the atd service. Similar to this service is the crond service. The functions of these two services can be similar to the two functional functions of javascript. Those who have learned
Use of Linux command crontab - loop execution of set commands
Publish Date:2025/04/08 Views:170 Category:OPERATING SYSTEM
-
Compared with at , which executes a command only once, crontab, which we are going to talk about in this article, executes the set commands in a loop. Similarly, the use of crontab requires the support of the crond service. The service is s
Linux practice - regularly delete files under the directory
Publish Date:2025/04/08 Views:198 Category:OPERATING SYSTEM
-
Since we want to delete the files under the directory regularly, we need to use the Linux crontab command. And the content format of each work routine is also introduced in the format of each crontab work. Similarly, we need to use shell sc