linux 下如何安装php,详解在Linux下如何安装配置PHP
1、安裝php
(1)獲得PHP源碼:php-5.4.1.tar.gz(最新版本為5.4.2),保存到/usr/local目錄下。下載地址:http://cn.php.net/get/php-5.4.2.tar.gz/from/a/mirror。
(2)解壓縮源碼文件:
#tar -zvxf php-5.4.1.tar.gz
(3)安裝libxm12以及libXML2-devel,不然編譯源碼時會出現“Configure: error: xml2-config not
found. Please check your libxml2 installation.”問題。
#yum install -y libxml2 libxm12-devel
(4)編譯源碼:
#cd /usr/local/php-5.4.1
#./configure --prefix=/usr/local/php
--with-apxs2=/usr/local/apache2/bin/apxs --with-MySQL=/usr/local/mysql
#make
(5)安裝
#make install
2、配置PHP
(1)將PHP源碼包(/usr/local/php-5.4.1)中的php.ini-development文件復制到/usr/local/lib/下,更名為php.ini。
#cp /usr/local/php-5.4.1/php.ini-development /usr/local/lib/php.ini
(2)修改Apache配置文件(gedit
/usr/local/apache2/conf/httpd.conf)以支持對PHP的解析。如果httpd.conf中沒有下列語句,就將它們分別添加到LoadModule和AddType項的后面。
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
在DirectoryIndex index.html index.html.var一行后加入index.php,即改為:
DirectoryIndex index.html index.html.var index.php
重啟Apache服務器:
#/usr/local/apache2/bin/apachectl restart
(3)測試PHP:
在Apache服務器的文件根目錄(/usr/local/apache2/htdocs/)下新建一個PHP文件test.php,并輸入以下內容:
《?
phpinfo();
?>
在瀏覽器中輸入http://localhost/test.php,如果看到下圖,則表示已成功安裝了PHP。
以上參考《基于Linux的Web程序設計PHP網站開發》一書。
3、問題及解決
問題1:“Cannot load /usr/local/apache2/modules/libphp5.so into server:
/usr/local/apache2/modules/libphp5.so”
[root@localhost ~]# /usr/local/apache2/bin/apachectl restart
httpd: Syntax error on line 144 of /usr/local/apache2/conf/httpd.conf:
Cannot load /usr/local/apache2/modules/libphp5.so into server:
/usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc:
Permission denied
[root@localhost ~]# ls -lh /usr/local/apache2/modules/libphp5.so
-rwxr-xr-x 1 root root 18M May 5 19:21
/usr/local/apache2/modules/libphp5.so
[root@localhost ~]# service httpd restart
Stopping httpd: [FAILED]
Starting httpd: [ OK ]
[root@localhost ~]# setenforce 0
[root@localhost ~]# chcon -c -v -R -u system_u -r object_r -t
textrel_shlib_t /usr/local/apache2/modules/libphp5.so
context of /usr/local/apache2/modules/libphp5.so changed to
system_u:object_r:textrel_shlib_t
[root@localhost ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@localhost ~]# setenforce 1
參考:Cannot load /usr/local/apache2/modules/libphp5.so into server:
/usr/local/apache2/modules/libphp5.s
問題2:“(98)Address already in use: AH00072: make_sock: could not bind to
address [::]:80”
[root@localhost ~]# /usr/local/apache2/bin/apachectl restart
httpd not running, trying to start
(98)Address already in use: AH00072: make_sock: could not bind to address
[::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address
0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
[root@localhost ~]# netstat -lnp|grep 80
tcp 0 0 :::80 :::* LISTEN 30735/httpd
unix 2 [ ACC ] STREAM LISTENING 18053 4742/ssh-agent
/tmp/ssh-alQwqZ4706/agent.4706
unix 2 [ ACC ] STREAM LISTENING 18337 4803/metacity
/tmp/orbit-bingo/linc-12c3-0-1fd1658ce18f6
unix 2 [ ACC ] STREAM LISTENING 18394 4809/nautilus
/tmp/orbit-bingo/linc-12c9-0-253df8021e3e
unix 2 [ ACC ] STREAM LISTENING 18431 4807/gnome-panel
/tmp/orbit-bingo/linc-12c7-0-253df802d473
unix 2 [ ACC ] STREAM LISTENING 18460 4823/gnome-volume-m
/tmp/orbit-bingo/linc-12cb-0-253df803776b
[root@localhost ~]# ps 30735
PID TTY STAT TIME COMMAND
30735 ? Ss 0:00 /usr/sbin/httpd
[root@localhost ~]# kill 30735
[root@localhost ~]# /usr/local/apache2/bin/apachectl restart
httpd not running, trying to start
[root@localhost ~]# /usr/local/apache2/bin/httpd -k start
httpd (pid 31918) already running
總結
以上是生活随笔為你收集整理的linux 下如何安装php,详解在Linux下如何安装配置PHP的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php连接到mysql数据库,PHP M
- 下一篇: tar php启动,安装php过程(Fa