linux系统—apache支持的语言

1,php语言

下载php

[root@server ~]# yum install php
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Package php-5.4.16-46.el7.x86_64 already installed and latest version
Nothing to do		我这里是已经提前下载过了php语言的

[root@server ~]# cd /var/www/html/ 切换到默认的发布目录下

编辑发布文件内容

[root@server html]# vim index.php
[root@server html]# cat  index.php
 <?php
      phpinfo();
  ?>

测试:在网页上直接测试就行
http://192.168.100.200/index.php 直接测试即可

在这里插入图片描述

perl语言

cd /var/www/html         切换到默认的发布目录下
[root@server html]# mkdir cgi
[root@server html]# ls -Z          查看安全上下文,
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 cgi
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.php
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 lc
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 readme
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 upload
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 utility
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 westos
[root@server html]# semanage fcontext -a -t httpd_sys_script_exec_t '/var/www/html/cgi(/.*)?'           更改安全上下文
[root@server html]# restorecon -RvvF /var/www/html/cgi/            刷新
restorecon reset /var/www/html/cgi context unconfined_u:object_r:httpd_sys_content_t:s0->system_u:object_r:httpd_sys_script_exec_t:s0
[root@server html]# cd cgi                切换到cgi路径下的
[root@server cgi]# vim  index.cgi           编辑默认发布文件
[root@server cgi]# cat  index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
[root@server cgi]# python /var/www/html/cgi/index.cgi             执行perl语言的是使用python语言的
Content-type: text/html
Traceback (most recent call last):
  File "/var/www/html/cgi/index.cgi", line 3, in <module>
    print `date`;
NameError: name 'date' is not defined               发现执行不了
[root@server cgi]# chmod +x /var/www/html/cgi/index.cgi                赋予权限后就可以执行了
[root@server cgi]# cd ..
[root@server html]# ./cgi/index.cgi              执行发布文件内容
Content-type: text/html
Sat May 11 23:12:27 PDT 2019                 查看是已经有了内容
[root@server html]# 

编辑主配置文件
cd /etc/httpd/conf.d/
[root@server conf.d]# vim vhost.conf
[root@server conf.d]# cat vhost.conf 
<Directory "/var/www/html/cgi">
	Options +ExecCGI
          AddHandler cgi-script .cgi
</Directory>
[root@server conf.d]# systemctl restart httpd.service 
[root@server conf.d]# 

测试:
在这里插入图片描述

3 python语言

环境配置:
下载安全的python包 yum install mod_wsgi.x86_64 -y
将这个包安装到 /var/www/cgi-bin/ 这个路径下,以防安全上下文不一样,

[root@server ~]# cd /var/www/cgi-bin/
[root@server cgi-bin]# yum install mod_wsgi.x86_64  -y

在这里插入图片描述

编辑主配置文件

[root@server cgi-bin]# cd /etc/httpd/conf.d
[root@server conf.d]# vim vhost.conf

在这里插入图片描述

测试:
主机端添加wsgi.westos.com进行域名解析

浏览器端输入wsgi.westos.com

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/liuchuang11/article/details/89892733
今日推荐