LAMP安装&&基础配置解析PHP

本文详细介绍了LAMP(Linux, Apache, MySQL, PHP)环境的安装过程,包括MySQL的安装、Apache的编译与安装以及PHP的配置。在MySQL安装中,涉及了数据目录的设置和权限配置;在Apache部分,提到了编译安装过程中可能遇到的问题及解决办法;在PHP配置中,重点讲解了如何使Apache支持PHP并验证安装是否成功。" 119518282,10638140,力扣链表专题 - 设计链表解析与实现,"['链表', '数据结构', '算法', 'Java', 'JavaScript']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MYSQl安装

为了方便管理把软件包放到此目录下

[root@jing ~]# cd /usr/local/src
[root@jing src]# ls
apr-1.6.5.tar.gz       httpd-2.4.46.tar.gz                         php-7.4.19.tar.gz
apr-util-1.6.1.tar.gz  mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

解压mysql软件包

[root@jing src]# ls -la |grep mysql
-rw-r--r--.  1 root root 661214270 Jan 26 17:27 mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
[root@jing src]# tar -zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

把 mysql 安装包移动到 /usr/local/mysql 下

[root@jing src]# mv mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz /usr/local/mysql/
[root@jing src]# cd /usr/local/mysql
[root@jing mysql]# pwd
/usr/local/mysql
[root@jing mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files

建立 mysql 的用户

[root@jing mysql]# useradd -s /sbin/nologin mysql

建立存放数据的目录(用户组和用户设置为mysql)

[root@jing mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql  /data/mysql
[root@jing mysql]# 
[root@jing mysql]# ls -la /data/mysql/
total 0
drwxr-xr-x. 2 mysql mysql  6 May 23 09:35 .
drwxr-xr-x. 3 root  root  19 May 23 09:35 ..

执行脚本(user=定义所属组,datadir=定义安装位置)

[root@jing mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

-bash: ./scripts/mysql_install_db: No such file or directory
[root@jing mysql]# yum list |grep perl
下载Module模块
[root@jing mysql]# yum install -y perl-Module-Install 

运行成功(出现两个OK)

[root@jing mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql     运行成功(出现两个OK)

修改配置文件

[root@jing mysql]# pwd
/usr/local/mysql
[root@jing mysql]# ls
bin      data  include  man     mysql-test  scripts  sql-bench
COPYING  docs  lib      my.cnf  README      share    support-files
[root@jing mysql]# cp support-files/
binary-configure     my-default.cnf       mysql-log-rotate     
magic                mysqld_multi.server  mysql.server         
[root@jing mysql]# cp support-files/my-default.cnf  /etc/my.cnf       拷贝配置文件
cp: overwrite ‘/etc/my.cnf’? y
[root@jing mysql]# vim  /etc/my.cnf   修改配置文件
 basedir = /usr/local/mysql   安装目录
 datadir = /data/mysql    存放数据的目录
 port = 3306     mysql默认端口
 server_id = 192.168.200。40     默认写为IP后三位/主机地址
 socket = /tmp/mysql.sock    

拷贝启动脚本,修改启动脚本

[root@jing mysql]# cp support-files/mysql.server /etc/init.d/mysqld
basedir=/usr/local/mysql      和mysql配置文件对应
datadir=/data/mysql
[root@jing mysql]# chkconfig --add mysqld
[root@jing mysql]# chkconfig mysqld on
查看是否启动成功
[root@jing mysql]# service mysqld start
查看进程\端口
Starting MySQL.Logging to '/data/mysql/jing.err'.
. SUCCESS! 
[root@jing mysql]# ps -ef|grep mysqld
root       6854      1  0 11:49 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/jing.pid
mysql      7094   6854  1 11:49 pts/1    00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=jing.err --pid-file=/data/mysql/jing.pid --socket=/tmp/mysql.sock --port=3306
root       7120   2095  0 11:50 pts/1    00:00:00 grep --color=auto mysqld
[root@jing mysql]# netstat -ltunp |grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      7094/mysqld

Apache安装

解压,切换目录,进行编译,make安装

[root@jing ~]# cd /usr/local/src
[root@jing src]# ls
apr-1.6.5.tar.gz       httpd-2.4.46.tar.gz
apr-util-1.6.1.tar.gz  mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
[root@jing src]# tar -zxvf apr-1.6.5.tar.gz
[root@jing src]# tar -zxvf apr-util-1.6.1.tar.gz
[root@jing src]# tar -zxvf httpd-2.4.46.tar.gz
[root@jing src]# ls
apr-1.6.5         apr-util-1.6.1.tar.gz  mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
apr-1.6.5.tar.gz  httpd-2.4.46
apr-util-1.6.1    httpd-2.4.46.tar.gz
[root@jing src]# cd apr-1.6.5/     切换到 apr-1.6.5 目录
[root@jing apr-1.6.5]# ls
apr-config.in  build             configure.in  libapr.dep    memory         random        threadproc
apr.dep        buildconf         docs          libapr.dsp    misc           README        time
apr.dsp        build.conf        dso           libapr.mak    mmap           README.cmake  tools
apr.dsw        build-outputs.mk  emacs-mode    libapr.rc     network_io     shmem         user
apr.mak        CHANGES           encoding      LICENSE       NOTICE         strings
apr.pc.in      CMakeLists.txt    file_io       locks         NWGNUmakefile  support
apr.spec       config.layout     helpers       Makefile.in   passwd         tables
atomic         configure         include       Makefile.win  poll           test

[root@jing apr-1.6.5]# yum install -y gcc 
[root@jing apr-1.6.5]# yum install -y libtool*
[root@jing apr-1.6.5]# ./configure --prefix=/usr/local/apr    进行编译
......
config.status: executing libtool commands
rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands
config.status: include/apr.h is unchanged
config.status: include/arch/unix/apr_private.h is unchanged
[root@jing apr-1.6.5]# make && make install

报错

[root@jing apr-1.6.5]# ./configure --prefix=/usr/local/apr
1、configure: error: no acceptable C compiler found in $PATH错误主要是没有C编译器.
2、config.status: executing libtool commands    缺少libtool包,安装libtool 
rm: cannot remove 'libtoolT': No such file or directory     (此句可忽略)       
config.status: executing default commands

解决方法:
[root@jing apr-1.6.5]# cat config.log (可以不执行,自己感兴趣可以看一下)
[root@jing apr-1.6.5]# yum install -y gcc
[root@jing apr-1.6.5]# yum install -y libtool*

进行编译,安装make

[root@jing apr-1.6.5]# cd ..     返回上级目录
[root@jing src]# ls
apr-1.6.5         apr-util-1.6.1.tar.gz  mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
apr-1.6.5.tar.gz  httpd-2.4.46
apr-util-1.6.1    httpd-2.4.46.tar.gz
[root@jing apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@jing apr-util-1.6.1]# ls      出现Makefile文件
aprutil.dep     buckets           config.nice    export_vars.sh     LICENSE        README.cmake
aprutil.dsp     build             config.status  export_vars.sh.in  Makefile       README.FREETDS
aprutil.dsw     buildconf         configure      hooks              Makefile.in    redis
aprutil.mak     build.conf        configure.in   include            Makefile.win   renames_pending
apr-util.pc     build-outputs.mk  crypto         ldap               memcache       strmatch
apr-util.pc.in  CHANGES           dbd            libaprutil.dep     misc           test
apr-util.spec   CMakeLists.txt    dbm            libaprutil.dsp     NOTICE         uri
apu-1-config    config.layout     docs           libaprutil.mak     NWGNUmakefile  xlate
apu-config.in   config.log        encoding       libaprutil.rc      README         xml
[root@jing apr-util-1.6.1]# make && make install
......报错
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
 #include <expat.h>
                   ^
compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/usr/local/src/apr-util-1.6.1'
make: *** [all-recursive] Error 1
[root@jing apr-util-1.6.1]# yum install -y expat-devel        解决上面报错问题
[root@jing apr-util-1.6.1]# make && make install     安装成功
......
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config
[root@jing apr-util-1.6.1]# echo $?     检查是否有错
0

进入 httpd-2.4.46 目录,进行编译,安装make

[root@jing apr-util-1.6.1]# cd ..
[root@jing src]# ls
apr-1.6.5         apr-util-1.6.1.tar.gz  mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
apr-1.6.5.tar.gz  httpd-2.4.46
apr-util-1.6.1    httpd-2.4.46.tar.gz
[root@jing src]# ls /usr/local/
apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src
[root@jing src]# cd httpd-2.4.46/
这里反斜杠 \ 是脱义字符,加上它我们可以把一行命令写成多行
[root@jing httpd-2.4.46]# ./configure  \
> prefix=/usr/local/apache2.4 \
> with-apr=/usr/local/apr \
> with-apr-util=/usr/local/apr-util \
> enable-so \
> enable-mods-shared=most
...报错
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
[root@jing httpd-2.4.46]# yum install -y pcre-devel        解决上面错误

[root@jing httpd-2.4.46]# ./configure  \
> prefix=/usr/local/apache2.4 \
> with-apr=/usr/local/apr \
> with-apr-util=/usr/local/apr-util \
> enable-so \
> enable-mods-shared=most        运行成功
configure: summary of build options:

    Server Version: 2.4.46
    Install prefix: /usr/local/apache2.4
    C compiler:     gcc -std=gnu99
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E
[root@jing httpd-2.4.46]# echo $?    检查是否有错
0
[root@jing httpd-2.4.46]# make -j4 && make install

报错

[root@jing httpd-2.4.46]# make -j4 && make install
make[2]: *** [ab] Error 1
make[2]: Leaving directory `/usr/local/src/httpd-2.4.46/support'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/httpd-2.4.46/support'
make: *** [all-recursive] Error 1     指定目录没有成功

[root@jing httpd-2.4.46]# ls
[root@jing httpd-2.4.46]# cd srclib/    进入srclib 目录
[root@jing srclib]# ls
Makefile  Makefile.in
[root@jing srclib]# vim Makefile    看一下文件(编译的时候依赖的东西)
top_srcdir   = /usr/local/src/httpd-2.4.46
top_builddir = /usr/local/src/httpd-2.4.46
srcdir       = /usr/local/src/httpd-2.4.46/srclib
builddir     = /usr/local/src/httpd-2.4.46/srclib
VPATH        = /usr/local/src/httpd-2.4.46/srclib

BUILD_SUBDIRS = $(AP_BUILD_SRCLIB_DIRS)
CLEAN_SUBDIRS = $(AP_CLEAN_SRCLIB_DIRS)

include $(top_builddir)/build/rules.mk

[root@jing srclib]# pwd      查看当前目录
/usr/local/src/httpd-2.4.46/srclib
[root@jing srclib]# cd ../../   进入上上级目录
[root@jing src]# ls
apr-1.6.5         apr-util-1.6.1.tar.gz  mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
apr-1.6.5.tar.gz  httpd-2.4.46
apr-util-1.6.1    httpd-2.4.46.tar.gz
[root@jing src]# cp  -r apr-1.6.5 httpd-2.4.46/srclib/apr       拷贝到httpd-2.4.46/srclib/apr目录下
[root@jing src]# cp -r apr-util-1.6.1  httpd-2.4.46/srclib/apr-util

切换回httpd-2.4.46
[root@jing src]# cd httpd-2.4.46/
[root@jing httpd-2.4.46]# ls
[root@jing httpd-2.4.46]# make clean 
[root@jing httpd-2.4.46]# make -j4 && make install     (未成功)

确认一下srclib上面是否有这些文件
[root@jing httpd-2.4.46]# ls
[root@jing httpd-2.4.46]# cd srclib/
[root@jing srclib]# ls
[root@jing srclib]# cd ..
[root@jing httpd-2.4.46]# ls
[root@jing httpd-2.4.46]# make clean
[root@jing httpd-2.4.46]# ls
[root@jing httpd-2.4.46]# ./configure --prefix=/usr/local/apache2.4 --enable-so --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[root@jing httpd-2.4.46]# echo $?
0
[root@jing httpd-2.4.46]# make -j4 && make install
[root@jing httpd-2.4.46]# echo $?
0

切换目录

[root@jing httpd-2.4.46]# ls
[root@jing httpd-2.4.46]# cd /usr/local/
[root@jing local]# ls
[root@jing local]# cd apache2.4/
[root@jing apache2.4]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules
[root@jing apache2.4]# du -s
43236   .
[root@jing apache2.4]# du -sh
43M     .
[root@jing apache2.4]# ls

可以查看 apache2.4 大小
[root@jing apache2.4]# cd ..
[root@jing local]# ls
[root@jing local]# du -sh apache2.4/
43M     apache2.4/

进入apache2.4 查看各个目录
[root@jing local]# cd apache2.4/
[root@jing apache2.4]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules
[root@jing apache2.4]# cd bin/     放置一些可执行文件
[root@jing bin]# ls
ab            apu-1-config  dbmmanage    fcgistarter   htdigest  httxt2dbm
apachectl     apxs          envvars      htcacheclean  htpasswd  logresolve
apr-1-config  checkgid      envvars-std  htdbm         httpd     rotatelogs
[root@jing bin]# cd ..
[root@jing apache2.4]# ls
[root@jing apache2.4]# cd conf/     各种配置文件
[root@jing conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@jing conf]# cd extra/      虚拟主机的配置文件
[root@jing extra]# ls
httpd-autoindex.conf  httpd-info.conf       httpd-mpm.conf                 httpd-userdir.conf
httpd-dav.conf        httpd-languages.conf  httpd-multilang-errordoc.conf  httpd-vhosts.conf
httpd-default.conf    httpd-manual.conf     httpd-ssl.conf                 proxy-html.conf
回到apache2.4目录
[root@jing extra]# cd ..
[root@jing conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@jing conf]# cd ..
[root@jing apache2.4]# ls
[root@jing apache2.4]# cd htdocs/    存放apache默认网页
[root@jing htdocs]# ls
index.html
[root@jing htdocs]# cat index.html 
<html><body><h1>It works!</h1></body></html>
[root@jing htdocs]# cd ..
[root@jing apache2.4]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules
[root@jing apache2.4]# cd modules     动态扩展模块
[root@jing modules]# ls

查看加载的模块
[root@jing modules]# cd ..
[root@jing apache2.4]# ls
[root@jing apache2.4]# /usr/local/apache2.4/bin/httpd -M 

安装PHP

解压php-7.4.19

[root@jing apache2.4]# cd /usr/local/src/
[root@jing src]# ls
apr-1.6.5         apr-util-1.6.1.tar.gz  mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
apr-1.6.5.tar.gz  httpd-2.4.46           php-7.4.19.tar.gz
apr-util-1.6.1    httpd-2.4.46.tar.gz
[root@jing src]# tar -zxf php-7.4.19.tar.gz 
[root@jing src]# cd php-7.4.19
[root@jing php-7.4.19]# ls
appveyor             configure        main                 run-tests.php  UPGRADING.INTERNALS
azure                configure.ac     NEWS                 sapi           win32
azure-pipelines.yml  CONTRIBUTING.md  pear                 scripts        Zend
build                docs             php.ini-development  tests
buildconf            ext              php.ini-production   travis
buildconf.bat        EXTENSIONS       README.md            TSRM
CODING_STANDARDS.md  LICENSE          README.REDIST.BINS   UPGRADING
[root@jing php-7.4.19]# cd /usr/local/apache2.4/bin/
[root@jing bin]# ls     可以看见apxs
ab            apu-1-config  dbmmanage    fcgistarter   htdigest  httxt2dbm
apachectl     apxs          envvars      htcacheclean  htpasswd  logresolve
apr-1-config  checkgid      envvars-std  htdbm         httpd     rotatelogs
[root@jing bin]# cd ../modules/
[root@jing modules]# vim ../conf/httpd.conf   apxs,可以直接把扩展模块放到配置文件里

编译httpd

[root@jing modules]# cd /usr/local/src/php-7.4.19
[root@jing php-7.4.19]# yum install libxml2-devel bzip2 bzip2-devel libpng libpng-devel openssl openssl-devel freetype freetype-devel opel-release -y 
[root@jing php-7.4.19]# yum install -y epel-release
[root@jing php-7.4.19]# yum install -y libmcrypt-devel
[root@jing php-7.4.19]# yum -y install  sqlite-devel
[root@jing php-7.4.19]# yum install oniguruma-devel -y

[root@jing php-7.4.19]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
...
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

configure: WARNING: unrecognized options: --with-mysql, --with-libxml-dir, --with-gd, --with-png-dir, --with-freetype-dir, --with-mcrypt, --enable-gd-native-ttf
[root@jing php-7.4.19]# echo $?
0

报错

1、configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
[root@jing php-7.4.19]# yum -y install  sqlite-devel
2、configure: error: Please reinstall the BZip2 distribution
[root@jing php-7.4.19]# yum install -y bzip2 bzip2-devel
3、configure: error: Package requirements (oniguruma) were not met:
[root@jing php-7.4.19]# yum install oniguruma-devel -y

安装make,查看所有模块

[root@jing php-7.4.19]# make -j4 && make install
[activating module `php7' in /usr/local/apache2.4/conf/httpd.conf]
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/
Installing PHP CLI binary:        /usr/local/php/bin/
Installing PHP CLI man page:      /usr/local/php/php/man/man1/
Installing phpdbg binary:         /usr/local/php/bin/
Installing phpdbg man page:       /usr/local/php/php/man/man1/
Installing PHP CGI binary:        /usr/local/php/bin/
Installing PHP CGI man page:      /usr/local/php/php/man/man1/
Installing build environment:     /usr/local/php/lib/php/build/
Installing header files:          /usr/local/php/include/php/
Installing helper programs:       /usr/local/php/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/php/man/man1/
  page: phpize.1
  page: php-config.1
/usr/local/src/php-7.4.19/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin/phar.phar
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/
[root@jing php-7.4.19]# echo $?
0
查看php是否安装完成(apache里有没有加载上此模块)
[root@jing php-7.4.19]# /usr/local/apache2.4/bin/httpd -M 
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::50d4:a08f:e674:aba4. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_prefork_module (shared)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)
 php7_module (shared)

查看php是否安装完成(apache里有没有加载上此模块)

[root@jing php-7.4.19]# cd /usr/local/apache2.4/modules/
[root@jing modules]# ls
[root@jing modules]# cd ..
[root@jing apache2.4]# vim conf/httpd.conf
......
LoadModule php7_module        modules/libphp7.so

<IfModule unixd_module>
查看php的安装信息
[root@jing apache2.4]# /usr/local/php/bin/php -i |less

拷贝到 /usr/local/php/php.ini

[root@jing apache2.4]# cd /usr/local/src/php-7.4.19/
[root@jing php-7.4.19]# ls
[root@jing php-7.4.19]# cp php.ini-production /usr/local/php/php.ini
[root@jing php-7.4.19]# cd /usr/local/php
[root@jing php]# ls
bin  include  lib  php  php.ini  var

配置 httpd 支持 php

[root@jing ~]# cd /usr/local/apache2.4/conf/
[root@jing conf]# ls
extra  httpd.conf(主配置文件目录)  httpd.conf.bak  magic  mime.types  original
[root@jing conf]# pwd
/usr/local/apache2.4/conf      apache配置文件目录
[root@jing conf]# vim httpd.conf
ServerName www.example.com:80       去掉注释
<Directory />
    AllowOverride none
    Require all granted       denied改为granted
</Directory>

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php     添加这一行内容

<IfModule dir_module>
    DirectoryIndex index.html index.php   添加index.php
</IfModule>

测试配置文件修改是否有误
[root@jing conf]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK

重新加载apache服务

查看http所有进程
[root@jing conf]# ps -ef |grep http
root       2685      1  0 04:47 ?        00:00:00 /usr/local/apache2.4/bin/httpd -k graceful
daemon     2701   2685  0 05:04 ?        00:00:00 /usr/local/apache2.4/bin/httpd -k graceful
daemon     2702   2685  0 05:04 ?        00:00:00 /usr/local/apache2.4/bin/httpd -k graceful
daemon     2703   2685  0 05:04 ?        00:00:00 /usr/local/apache2.4/bin/httpd -k graceful
daemon     2704   2685  0 05:04 ?        00:00:00 /usr/local/apache2.4/bin/httpd -k graceful
daemon     2705   2685  0 05:04 ?        00:00:00 /usr/local/apache2.4/bin/httpd -k graceful
root       2862   2839  0 08:24 pts/0    00:00:00 grep --color=auto http

杀死开启的进程
[root@jing conf]# kill -9 2685
[root@jing conf]# ps -ef |grep http

[root@jing conf]# kill -9 2701
[root@jing conf]# kill -9 2702
[root@jing conf]# kill -9 2703
[root@jing conf]# kill -9 2704
[root@jing conf]# kill -9 2705
[root@jing conf]# ps -ef |grep http
root       2866   2839  0 08:30 pts/0    00:00:00 grep --color=auto http

重新启动一下
[root@jing conf]# /usr/local/apache2.4/bin/apachectl start
[root@jing conf]# ps -ef |grep http                       
root       2870      1  0 08:32 ?        00:00:00 /usr/local/apache2.4/bin/httpd -k start
daemon     2871   2870  0 08:32 ?        00:00:00 /usr/local/apache2.4/bin/httpd -k start
daemon     2872   2870  0 08:32 ?        00:00:00 /usr/local/apache2.4/bin/httpd -k start
daemon     2873   2870  0 08:32 ?        00:00:00 /usr/local/apache2.4/bin/httpd -k start
daemon     2874   2870  0 08:32 ?        00:00:00 /usr/local/apache2.4/bin/httpd -k start
daemon     2875   2870  0 08:32 ?        00:00:00 /usr/local/apache2.4/bin/httpd -k start
root       2877   2839  0 08:32 pts/0    00:00:00 grep --color=auto http

curl 命令查看

[root@jing conf]# curl localhost
<html><body><h1>It works!</h1></body></html>

在 htdocs也可查看
[root@jing conf]# cd ..
[root@jing apache2.4]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules
[root@jing apache2.4]# cd htdocs/
[root@jing htdocs]# ls
index.html
[root@jing htdocs]# cat index.html 
<html><body><h1>It works!</h1></body></html>

在浏览器上访问192.168.200.40的网址
在这里插入图片描述
把hosts拖到桌面修改,再拖回来

[root@jing htdocs]# systemctl stop firewalld

在这里插入图片描述
测试是否正确解析PHP

[root@jing htdocs]# vim test.php
<?php
echo "php解析"               “”里面为任意内容
?>
[root@jing htdocs]# curl localhost/test.php
php解析[root@jing htdocs]#

访问网页
在这里插入图片描述

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值