首页 > 系统相关 >CentOS+LAMP

CentOS+LAMP

时间:2024-07-03 17:53:50浏览次数:30  
标签:CentOS com admin02 LAMP usr mysql local apache2.4

LAMP环境搭建与配置

软件包下载在: /usr/local/src/

使用前请安装 yum -y install wget bzip2 gcc vim net-tools

1. 安装与配置MySQL

1.1 安装MySQL

MySQL版本为:5.6.50

 cd /usr/local/src/
 wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz
 tar -zxf mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz
# 获取源码包,并解压源码包

 [ -d /usr/local/mysql ] && mv /usr/local/mysql /usr/local/mysql_old
# 先查看是否有/usr/local/mysql目录,如果有就重命名为mysql_old

 mkdir /usr/local/mysql 
 mv mysql-5.6.50-linux-glibc2.12-x86_64/* /usr/local/mysql 
# 将解压出来的文件内容移动到/usr/local/mysql

 useradd -s /sbin/nologin mysql 
# 创建用户

 mkdir -p /data/mysql
 chown -R mysql:mysql  /data/mysql
# 创建数据库文件存放目录,并更改权限
 
 ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

报错解决方法

第一种

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
-bash: ./scripts/mysql_install_db: /usr/bin/perl: 坏的解释器: 没有那个文件或目录

解决 yum -y install perl perl-devel

第二种

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper

解决 yum -y install perl-Module-Install

建议直接安装 perl-Module-Install

1.2 配置MySQL

 cp support-files/my-default.cnf /etc/my.cnf
  cp:是否覆盖"/etc/my.cnf"? y
 
 vim /etc/my.cnf
# 内容修改成如下(前面若有#号删除#号):
 innodb_buffer_pool_size = 128M
 log_bin = aminglinux
 basedir = /usr/local/mysql
 datadir = /data/mysql
 port = 3306
 server_id = 128
 socket = /tmp/mysql.sock
 join_buffer_size = 128M
 sort_buffer_size = 2M
 read_rnd_buffer_size = 2M
 
 cp support-files/mysql.server /etc/init.d/mysqld
 chmod 755 /etc/init.d/mysqld
 chkconfig --add mysqld
 chkconfig mysqld on
 service mysqld start

# 如果启动不了,到/data/mysql查看日志,并检查MySQL有没有启动
 ps aux | grep mysqld # 结果应大于2
 netstat -lnp | grep 3306 # 查看3306端口有没有开启

2. 安装与配置Apache

2.1安装Apache

Apache版本为:2.4.54

apr版本为:1.5.1

apr版本为:1.5.4

 cd /usr/local/src/
 wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.54.tar.gz
 wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.1.tar.gz
 wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
 tar -zxf httpd-2.4.54.tar.gz
 tar -zxf apr-1.5.1.tar.gz
 tar -zxf apr-util-1.5.4.tar.gz
# 获取源码包,以及解压源码包

 cd /usr/local/src/apr-1.5.1
 ./configure --prefix=/usr/local/apr
 make && make install
 cd /usr/local/src/apr-util-1.5.4
 ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr
 make && make install
# 安装apr以及apr-util(报错请看报错解决方法)

 cd /usr/local/src/httpd-2.4.54
 ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-so --enable-mods-shared=most
 make && make install

报错解决方法

安装apr报错

rm: cannot remove 'libtoolT': No such file or directory
解决 vim configure 
	注释掉$RM "$cfgfile"
	#$RM "$cfgfile"

安装httpd报错

configure: error: pcre(2)-config for libpcre not found. PCRE is required and available from http://pcre.org/
解决 yum -y install pcre pcre-devel

2.2 配置Apache

2.2.1 配置httpd支持PHP

vim /usr/local/apache2.4/conf/httpd.conf
#修改
#ServerName www.example.com:80
==>
ServerName www.example.com:80

#修改
<Directory />
    AllowOverride none
    Require all denied
</Directory>
==>
<Directory />
    AllowOverride none
    Require all granted
</Directory>

#搜索如下这行
AddType application/x-gzip .gz .tgz
在下面添加
AddType application/x-httpd-php .php

#修改
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
==>
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
#保存并退出

2.2.2 配置虚拟主机

vim /usr/local/apache2.4/conf/httpd.conf
#修改
#Include conf/extra/httpd-vhosts.conf
==>
Include conf/extra/httpd-vhosts.conf

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
#修改
<VirtualHost *:80>
    ServerAdmin [email protected] # 管理员邮箱 可忽略
    DocumentRoot "/usr/local/apache2.4/docs/dummy-host.example.com" # 网站根目录
    ServerName dummy-host.example.com # 网站web站点名
    ServerAlias www.dummy-host.example.com # 站点别名 可忽略
    ErrorLog "logs/dummy-host.example.com-error_log" # 错误访问日志
    CustomLog "logs/dummy-host.example.com-access_log" common # 成功访问日志
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/usr/local/apache2.4/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
==>
<VirtualHost *:80>
    ServerAdmin [email protected] # 网站名随意
    DocumentRoot "/data/wwwroot/admin01.com"
    ServerName admin01.com
    ServerAlias www.admin01.com
    ErrorLog "logs/admin01.com-error_log"
    CustomLog "logs/admin01.com-access_log" common
</VirtualHost>

#<VirtualHost *:80>
#    ServerAdmin [email protected]
#    DocumentRoot "/usr/local/apache2.4/docs/dummy-host2.example.com"
#    ServerName dummy-host2.example.com
#    ErrorLog "logs/dummy-host2.example.com-error_log"
#    CustomLog "logs/dummy-host2.example.com-access_log" common
#</VirtualHost>
# 在第二段每行前面加上#号

mkdir -p /data/wwwroot/admin01.com
echo "admin01.com" > /data/wwwroot/admin01.com/index.html
# 创建admin.com目录,并创建网站主页

/usr/local/apache2.4/bin/apachectl -t
 Syntax OK
/usr/local/apache2.4/bin/apachectl graceful
# 检查配置文件,并重新加载http服务

curl -x127.0.0.1:80 www.admin01.com
#检查虚拟主机是否正常 输出为 admin01.com

2.2.3 配置用户认证

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
# 将前面的#号删除
#<VirtualHost *:80>
#    ServerAdmin [email protected]
#    DocumentRoot "/usr/local/apache2.4/docs/dummy-host2.example.com"
#    ServerName dummy-host2.example.com
#    ErrorLog "logs/dummy-host2.example.com-error_log"
#    CustomLog "logs/dummy-host2.example.com-access_log" common
#</VirtualHost>
==>
<VirtualHost *:80>
    DocumentRoot "/data/wwwroot/www.admin02.com"
    ServerName www.admin02.com
    <Directory "/data/wwwroot/www.admin02.com"> # 保护目录
        AllowOverride AuthConfig # 认证开关
        AuthName "test.com user auth" # 认证名字,可无
        AuthType Basic # 认证类型,一般为Basic
        AuthUserFile /data/.htpasswd # 密码文件目录
        require valid-user # 指定需要认证的用户
    </Directory>
</VirtualHost>

mkdir -p /data/wwwroot/www.admin02.com

/usr/local/apache2.4/bin/htpasswd -cm /data/.htpasswd user1
# 创建用户 user1

/usr/local/apache2.4/bin/apachectl -t
 Syntax OK
/usr/local/apache2.4/bin/apachectl graceful
# 检查配置文件,并重新加载http服务

# 配置完成后,需要带宿主机(你的windows)上去修改hosts文件(目录为:C:Windows\System32\drivers\etc\hosts),添加如下
# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost
==>
# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost
 	192.168.211.128	www.admin02.com
# 左边的IP为你的Linux IP地址,请注意修改
# 保存hosts文件后,用浏览器访问www.admin02.com,就会弹出一个用户认证的提示框,如图所示

2.2.4 配置域名跳转

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
# 将前面的#号删除
#<VirtualHost *:80>
#    ServerAdmin [email protected]
#    DocumentRoot "/usr/local/apache2.4/docs/dummy-host2.example.com"
#    ServerName dummy-host2.example.com
#    ErrorLog "logs/dummy-host2.example.com-error_log"
#    CustomLog "logs/dummy-host2.example.com-access_log" common
#</VirtualHost>
==>
<VirtualHost *:80>
    DocumentRoot "/data/wwwroot/www.admin02.com"
    ServerName www.admin02.com
    ServerAlias admin02.com
    <IfModule mod_rewrite.c> # 需要mod_rewrite模块
        RewriteEngine on # 打开rewrite功能
        RewriteCond %{HTTP_HOST} !^www.admin02.com$ # 当主机名不是www.admin02.com时触发下面条件
        RewriteRule ^/(.*)$ http://www.admin02.com/$1 [R=301,L]
    </IfModule>
</VirtualHost>
# 修改配置文件

vim /usr/local/apache2.4/conf/httpd.conf
#LoadModule rewrite_module modules/mod_rewrite.so
==>
LoadModule rewrite_module modules/mod_rewrite.so
# 修改配置文件,让rewrite模块生效

/usr/local/apache2.4/bin/apachectl -t
 Syntax OK
/usr/local/apache2.4/bin/apachectl graceful
# 检查配置文件,并重新加载http服务

/usr/local/apache2.4/bin/apachectl -M | grep -i rewrite
# 查看模块是否生效,生效会提示 rewrite_module (shared)

curl -x127.0.0.1:80 -I admin02.com
    HTTP/1.1 301 Moved Permanently
    Date: Tue, 06 Sep 2022 08:06:04 GMT
    Server: Apache/2.4.54 (Unix) PHP/5.6.40
    Location: http://admin02.com/
    Content-Type: text/html; charset=iso-8859-1
# 5.查看跳转是否正常,正常 状态码为301,location为test.com

2.2.5 配置访问日志

 vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf 
 #<VirtualHost *:80>
 #    ServerAdmin [email protected]
 #    DocumentRoot "/usr/local/apache2.4/docs/dummy-host2.example.com"
 #    ServerName dummy-host2.example.com
 #    ErrorLog "logs/dummy-host2.example.com-error_log"
 #    CustomLog "logs/dummy-host2.example.com-access_log" common
 #</VirtualHost>
 ==>
 <VirtualHost *:80>
    DocumentRoot "/data/wwwroot/www.admin02.com"
    ServerName www.admin02.com
    ServerAlias admin02.com
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTP_HOST} |^www.admin02.com$
        RewriteRule ^/(.*)$ http://www.admin02.com/$1 [R=301,L]
    </IfModule>
    CustomLog "logs/admin02.com-access_log" combined
 </VirtualHost>
 
 /usr/local/apache2.4/bin/apachectl -t
  Syntax OK
 /usr/local/apache2.4/bin/apachectl graceful
# 检查配置文件,并重新加载http服务

curl -x127.0.0.1:80 -I admin02.com
 HTTP/1.1 200 OK
 Date: Wed, 07 Sep 2022 07:03:15 GMT
 Server: Apache/2.4.54 (Unix) PHP/5.6.39
 X-Powered-By: PHP/5.6.39
 Content-Type: text/html; charset=UTF-8
#访问一次就会生成日志

tail /usr/local/apache2.4/logs/znje12.com-access_log
 127.0.0.1 - - [07/Sep/2022:15:03:15 +0800] "HEAD HTTP://admin02.com/ HTTP/1.1" 200 - "-" "curl/7.29.0"
# 发现生成了日志

限制静态元素

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
#添加
 ······
 </IfModule>
 SetEnvIf Reequest_URI ".*\.gif$" image-request
 SetEnvIf Reequest_URI ".*\.jpg$" image-request
 SetEnvIf Reequest_URI ".*\.png$" image-request
 SetEnvIf Reequest_URI ".*\.bmp$" image-request
 SetEnvIf Reequest_URI ".*\.swf$" image-request
 SetEnvIf Reequest_URI ".*\.js$" image-request
 SetEnvIf Reequest_URI ".*\.css$" image-request
# 最后一行改成如下
CustomLog "logs/admin02.com-access_log" combined
==>
CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/znje12.com-access_%Y%m%d.log 86400" combined env=|image-request

/usr/local/apache2.4/bin/apachectl -t
 Syntax OK
/usr/local/apache2.4/bin/apachectl graceful
# 检查配置文件,并重新加载http服务

curl -x127.0.0.1:80 -I admin02.com
# 再次访问,才会生成新的日志
ls /usr/local/apache2.4/logs/
# 会生成一下文件
 admin02.com-access_20220907.log

touch /data/wwwroot/www.admin02.com/admin02.jpg
touch /data/wwwroot/www.admin02.com/admin02.txt
# 生成一个jpg文件和一个txt文件

curl -x127.0.0.1:80 -I admin02.com/admin02.jpg
curl -x127.0.0.1:80 -I admin02.com/admin02.txt
# 访问

cat /usr/local/apache2.4/logs/admin02.com-access_20220907.log
 127.0.0.1 - - [07/Sep/2022:15:54:25 +0800] "HEAD HTTP://admin02.com/ HTTP/1.1" 200 - "-" "curl/7.29.0"
 127.0.0.1 - - [07/Sep/2022:15:58:28 +0800] "HEAD HTTP://admin02.com/admin02.jpg HTTP/1.1" 200 - "-" "curl/7.29.0"
 127.0.0.1 - - [07/Sep/2022:16:03:10 +0800] "HEAD HTTP://admin02.com/admin02.txt HTTP/1.1" 200 - "-" "curl/7.29.0"
# 生成的日志

2.2.6 配置静态元素过期时间

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
# 在CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/admin02.com-access_%Y%m%d.log 86400" combined env=!image-request后面加上如下
 <IfModule mod_expires.c>
        ExpiresActive on
        ExpiresByType image/gif "access plus 1 days"
        ExpiresByType image/jpeg "access plus 24 hours"
        ExpiresByType image/png "access plus 24 hours"
        ExpiresByType text/css "now plus 2 hours"
        ExpiresByType application/x-javascript "now plus 2 hour"
        ExpiresByType application/javascript "now plus 2 hour"
        ExpiresByType application/x-shockwave-flash "now plus 2 hour"
        ExpiresDefault "now plus 0 min"
    </IfModule>
# 解释如图

vim /usr/local/apache2.4/conf/httpd.conf
#LoadModule expires_module modules/mod_expires.so
==>
LoadModule expires_module modules/mod_expires.so

/usr/local/apache2.4/bin/apachectl graceful
/usr/local/apache2.4/bin/apachectl -M|grep -i expires
 expires_module (shared)
# 有这行输出,说明已经正确加载expires模块
# 如果这里没有输出,说明当前httpd并不支持expires模块,还需修改配置文件

curl -x127.0.0.1:80 -I www.admin02.com/admin02.jpg
 HTTP/1.1 200 OK
 Date: Thu, 08 Sep 2022 01:37:10 GMT
 Server: Apache/2.4.54 (Unix) PHP/5.6.39
 Last-Modified: Wed, 07 Sep 2022 07:58:06 GMT
 ETag: "0-5e811ac4d5400"
 Accept-Ranges: bytes
 Cache-Control: max-age=86400 # 看到max-age=86400,这说明jpg的图片将缓存86400秒,也就是一天
 Expires: Fri, 09 Sep 2022 01:37:10 GMT
 
curl -x127.0.0.1:80 -I www.admin02.com/admin02.txt
 HTTP/1.1 200 OK
 Date: Thu, 08 Sep 2022 01:39:29 GMT
 Server: Apache/2.4.54 (Unix) PHP/5.6.39
 Last-Modified: Wed, 07 Sep 2022 07:58:10 GMT
 ETag: "0-5e811ac8720e0"
 Accept-Ranges: bytes
 Cache-Control: max-age=0 #这里max-age=0,说明灭有缓存该类型的文件
 Expires: Thu, 08 Sep 2022 01:39:29 GMT
 Content-Type: text/plain

2.2.7 配置防盗链

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
# 在CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/admin02.com-access_%Y%m%d.log 86400" combined env=!image-request后面加上如下(注意不要添加到上一个标签内)
<Directory /data/wwwroot/www.znje12.com>
        SetEnvIfNoCase Referer "http://www.znje12.com" local_ref
        SetEnvIfNoCase Referer "http://znje12.com" local_ref
        SetEnvIfNoCase Referer "^$" local_ref # ^$为空referer
        <filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif)">
            Order Allow,Deny
            Allow from env=local_ref
        </filesmatch>
     </Directory>

/usr/local/apache2.4/bin/apachectl -t
 Syntax OK
/usr/local/apache2.4/bin/apachectl graceful
# 检查配置文件,并重新加载http服务

curl -x127.0.0.1:80 -I -e "http://www.admin02.com/123.txt"v http://www.admin02.com/admin02.jpg
 HTTP/1.1 200 OK
 Date: Thu, 08 Sep 2022 02:32:55 GMT
 Server: Apache/2.4.54 (Unix) PHP/5.6.39
 Last-Modified: Wed, 07 Sep 2022 07:58:06 GMT
 ETag: "0-5e811ac4d5400"
 Accept-Ranges: bytes
 Cache-Control: max-age=86400
 Expires: Fri, 09 Sep 2022 02:32:55 GMT
 Content-Type: image/jpeg
 
curl -x127.0.0.1:80 -I -e "http://www.1234.com/1.txt" http://admin02.com/admin02.jpg
 HTTP/1.1 403 Forbidden
 Date: Thu, 08 Sep 2022 02:33:04 GMT
 Server: Apache/2.4.54 (Unix) PHP/5.6.39
 Content-Type: text/html; charset=iso-8859-1
# 使用非允许的referer会返回403的状态码

curl -x127.0.0.1:80 -I -e "http://www.1234.com/1.txt" http://admin02.com/index.html
 HTTP/1.1 200 OK
 Date: Thu, 08 Sep 2022 02:33:19 GMT
 Server: Apache/2.4.54 (Unix) PHP/5.6.39
 X-Powered-By: PHP/5.6.39
 Cache-Control: max-age=0
 Expires: Thu, 08 Sep 2022 02:33:19 GMT
 Content-Type: text/html; charset=UTF-8
# index.html文件没有的话,就自己创建,使用下面这句
# touch /data/wwwroot/www.admin02.com/index.html
# 访问HTML类型的文件时,也不会被保护

2.2.7 访问控制

对IP限制访问(只允许公司内网IP或者被信任的公网IP访问):

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
# 在CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/admin02.com-access_%Y%m%d.log 86400" combined env=!image-request后面加上如下(注意不要添加到上一个标签内)
<Directory /data/wwwroot/www.admin02.com/admin>
	Order allow.deny # 控制顺序,哪个在前面就先匹配哪个规则
	Deny from all # 对所有IP限制
	Allow from 127.0.0.1 # 只允许127.0.0.1进行访问
</Directory>

mkdir /data/wwwroot/www.admin02.com/admin/
# 创建admin目录,模拟·网站后台
echo "admin" > /data/wwwroot/www.admin02.com/admin/index.html
# 在后台目录下创建文件,并写入内容
> /usr/local/apache2.4/logs/admin02.com-access_20220908.log
# 清空当天的访问日志,">"号要加

curl -x192.168.211.128:80 -I www.admin02.com/admin/index.html
 HTTP/1.1 403 Forbidden
 Date: Thu, 08 Sep 2022 03:35:17 GMT
 Server: Apache/2.4.54 (Unix) PHP/5.6.39
 Content-Type: text/html; charset=iso-8859-1
# 192.168.211.128是Linux IP,注意更改

curl -x127.0.0.1:80 -I www.admin02.com/admin/index.html
 HTTP/1.1 200 OK
 Date: Thu, 08 Sep 2022 03:40:23 GMT
 Server: Apache/2.4.54 (Unix) PHP/5.6.39
 Last-Modified: Thu, 08 Sep 2022 03:25:50 GMT
 ETag: "6-5e821fc793064"
 Accept-Ranges: bytes
 Content-Length: 6
 Cache-Control: max-age=0
 Expires: Thu, 08 Sep 2022 03:40:23 GMT
 Content-Type: text/html

cat /usr/local/apache2.4/logs/admin02.com-access_20220908.log
 192.168.211.128 - - [08/Sep/2022:12:37:16 +0800] "HEAD HTTP://admin02.com/admin/index.html HTTP/1.1" 403 - "-" "curl/7.29.0"
 127.0.0.1 - - [08/Sep/2022:12:37:29 +0800] "HEAD HTTP://www.admin02.com/admin/index.html HTTP/1.1" 200 - "-" "curl/7.29.0"

# 也可用windows访问,如图所示
tail -1 /usr/local/apache2.4/logs/znje12.com-access_20220908.log
 192.168.211.1 - - [08/Sep/2022:12:43:30 +0800] "GET /admin/ HTTP/1.1" 403 199 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0"

也可以单独对某个文件来做限制:

<Directory /data/wwwroot/www.admin02.com>
	<filesmatch "admin.php(.*)">
	    Order demy,allow
	    Deny from all
	    Allow from 127.0.0.1
	</filesmatch>
</Directory>

上传文件禁止解析PHP代码:

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
#添加
<Directory /data/wwwroot/www.admin02.com/upload>
	php_admin_flag engine off
</Directory>

/usr/local/apache2.4/bin/apachectl -t
 Syntax OK
/usr/local/apache2.4/bin/apachectl graceful
# 检查配置文件,并重新加载http服务

cp /usr/local/apache2.4/htdocs/1.php /data/wwwroot/www.admin02.com/upload/
curl -x127.0.0.1:80 www.znje12.com/upload/1.php
 <?php
         echo "php解析正常";
 ?>
# 可以看到php是不能正常解析的

限制恶意请求:

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
#添加
<IfModule mod_rewreite.c>
	RewriteEngine on
	RewriteCond %{HTTP_USER_AGENT} .*curl.* [NC,OR]
	RewriteCond %{HTTP_USER_AGENT} .*baidu.com.* [NC]
	RewriteRule .* - [F]
</IfModule>

/usr/local/apache2.4/bin/apachectl -t
 Syntax OK
/usr/local/apache2.4/bin/apachectl graceful
# 检查配置文件,并重新加载http服务

3. 安装并配置php

3.1 安装php

php版本为:5.6.39

cd /usr/local/src 
wget http://cn2.php.net/distributions/php-5.6.39.tar.bz2
tar -jxf php-5.6.39.tar.bz2 
# 获取源码包,以及解压源码包
 
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel epel-release
yum -y install libmcrypt-devel
# 安装必须的软件包
 
./configure -prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/1ocal/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif 
# 编译

make && make install 
# 安装

3.2 配置php

 cd /usr/local/src/php-5.6.39
 cp php.ini-production /usr/local/php/etc/php.ini #复制配置文件
  • 注意:安装完成php后,必须配置httpd支持PHP

4. 开启apache

#开启apache
/usr/local/apache2.4/bin/apachectl -t
#如有错误继续修改httpd.conf。配置成功会显示“Syntax OK”
/usr/local/apache2.4/bin/apachectl start

# 测试配置文件
netstat -lnp |grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      32315/httpd
# 显示如此htppd就已经启动httpd了(32315为进程uid,所以会有所不同)

# 测试PHP
vim /usr/local/apache2.4/htdocs/1.php
# 编写一个测试脚本
<?php
	echo "php解析正常";
?>
curl localhost/1.php
 php解析正常
# 如果能显示以上信息则说明PHP解析正常

标签:CentOS,com,admin02,LAMP,usr,mysql,local,apache2.4
From: https://www.cnblogs.com/winterchocolates/p/18282275

相关文章

  • 成功解决CentOS7中yum能ping通外网,但是无法下载问题
    今天安装完centos7后,使用yum安装vim时出现连接国外源超时情况,想通过yumupdate来解决问题,但是出现以下情况:通过pingwww.baidu.com,网络是通的。怀疑是CentOS-Base.repo文件出了问题。通过命令将该文件备份:mv/etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base......
  • centos系统构建安装john导致的编译问题error: size of array element is not a multip
    blake2.h:112:5:error:sizeofarrayelementisnotamultipleofitsalignment112|blake2b_stateS[4][1];|^~~~~~~~~~~~~blake2.h:113:5:error:sizeofarrayelementisnotamultipleofitsalignment113|blake2b_stateR[1];......
  • Centos7下安装Redis
    1.安装依赖redis是由C语言开发,因此安装之前必须要确保服务器已经安装了gcc,可以通过如下命令查看机器是否安装:gcc-v如果没有安装则通过以下命令安装:yuminstall-ygcc2.下载redis安装包并解压#下载,我是在root下执行的下载,所以我的下载目录为:/root/redis-6.2.6,这里......
  • centos7下载关联centos镜像文件
    1.CentOS在官网上直接下载网址:https://www.centos.org/download/我选择在这里下载https://mirrors.aliyun.com/centos/7/isos/x86_64/ 感觉还是慢直接网盘下载了 centos7.9:链接: https://pan.baidu.com/s/13BAfdn1-T5YkxLJ1IpwQyw提取码: bqyg2. 3. 4, 5. ......
  • centos7定时检测磁盘大小,并输出为csv格式
    脚本:!/bin/bash定义输出文件名OUTPUT_FILE="/path/to/output.csv"获取当前日期时间,为CSV文件名添加时间戳TIMESTAMP=$(date+"%Y%m%d%H%M%S")OUTPUT_FILE_WITH_TIMESTAMP="${OUTPUT_FILE}_${TIMESTAMP}.csv"检测磁盘空间并输出到CSV文件df-h|awk-vOFS=','&#......
  • linux_centos镜像下载及百度网盘分享链接
    1.Centos镜像国内最全下载地址CentOS官方下载地址:https://www.centos.org/download/Centos国内下载源http://man.linuxde.net/download/CentOShttp://mirrors.btte.net/centoshttp://mirrors.cn99.com/centos (希网)http://mirrors.sohu.com/centos (搜狐)http://mirrors.aliyun.......
  • CentOS Stream 8 发布.net 8 webapi
    参考资料https://learn.microsoft.com/zh-cn/dotnet/core/install/linux-rhel#where-is-centos-linux 微软好像不持支.net7所以把demo换成.net8sudodnfinstalldotnet-sdk-8.0 然后就开始报错,大致意思就是无法解析,找不到地址资源进入yum的repos目录cd/etc/yum.rep......
  • 在vmare中创建centos虚拟机
    1,环境window11vmareworkstation172. 3, 4这里是因为一会儿可以使用自己下载的镜像文件 5.选择用户操作系统linux  6. 7. 8. 9. 10. 11. 12, 13. 14. 15 ......
  • linux安装telnet服务(Centos7.9环境)
    使用telnet临时替代ssh安装配置接上一篇OpenssH升级至9.8P1教程发出后有不少朋友反馈在升级过程中服务器连接断开无法远程,对租用云服务器的朋友们不是太友好,后续只能联系云厂商或者通过购买云服务器账号后台登陆操作浪费时间,现在我们可以采用安装telnet服务临时替代ssh远程登......
  • 红队工具Finger 安装具体以步骤-示例centos
    1.gitclonehttps://github.com/EASY233/Finger.git如果没有yuminstallgit2.pip3install-rrequirements.txt找到finger所在的文件夹可以用find-name"Finger"进入文件中配置命令前提要安装pythonyuminstallpython-pip33.python3Finger.py-h......