在Fedora23安裝apache、php、mysql與python

在Fedora23安裝apache、php、mysql與python

Step1)安裝apache(httpd)

(a)使用dnf安裝apache

#dnf install httpd

(b)啟用apache的ipv4

#vi /etc/httpd/conf/httpd.conf

Listen:0.0.0.0:80

(c)設定開機預設啟用apache (httpd)

#systemctl enable httpd

(d)啟動apache

#systemctl start httpd

(e)開啟防火牆

#firewall-cmd --permanent --add-service=http

#firewall-cmd --permanent --add-service=https

#firewall-cmd --reload

Step2)安裝mysql(mariadb)

(a)安裝mysql(mariadb)的用戶端與伺服端程式

#dnf install mariadb mariadb.server

(b)設定開機預設啟用mysql(mariadb)

#systemctl enable mariadb

(c)啟動mysql(mariadb)

#systemctl start mariadb

(d)設定mysql(mariadb)

#mysql_secure_installation

Step3)安裝php

使用dnf安裝php

#dnf install php

Step4)安裝mod_wsgi,Python2與Python3只能選一個安裝

(a)安裝python3

#dnf install python3

(b)將python2的設定檔/etc/httpd/conf.module.d/10-wsgi.conf備份到/root,表示不啟動python2。

#mv /etc/httpd/conf.module.d/10-wsgi.conf /root

(c)安裝python3-mod_wsgi

#dnf install python3-mod_wsgi

(d)設定完成後重新啟動httpd。

#systemctl restart httpd

Step5)測試Python程式

(a)編輯wsgi.conf,將test_wsgi連結到test_wsgi.py。

#vi /etc/httpd/conf.d/wsgi.conf

WSGIScriptAlias /my_wsgi /var/www/html/my_wsgi.py

(b)重新啟動apache(httpd)

#systemctl start httpd

Step6)編輯my_wsgi.py

#vi /var/www/html/my_wsgi.py

def application(env, start_response):

html = b"<html>\n <body>\n<H1>Python<H1>\n</body>\n</html>\n"

start_response('200 OK', [('Content-Type','text/html')])

return [html]