centos手動編譯安裝apache、php、mysql

伽馬科技.攻城師發表於2016-10-01

64位centos 5.5手動安裝lamp,要求curl、json、pdo_mysql、gd,記錄如下。

centos 5.4、5.5、5.6的核心都是2.6.18,都可以安裝php 5.3。

解除安裝舊版本apache、php、mysql:
sudo yum erase httpd
sudo yum erase php php-cli
sudo yum erase mysql
下載編譯安裝apache 2.2.19:
http://httpd.apache.org/download.cgi

cd ~
wget http://mirror.bjtu.edu.cn/apache/httpd/httpd-2.2.19.tar.bz2
tar -jxvf httpd-2.2.19.tar.bz2
cd httpd-2.2.19
sudo yum install gcc
./configure --prefix=/opt/httpd --enable-so --enable-rewrite
make
sudo make install
sudo /opt/httpd/bin/httpd -k start
安裝完apache,用瀏覽器訪問http://localhost,能正常顯示說明裝好了。

下載安裝mysql 5.5.13:
http://dev.mysql.com/downloads/mysql/#downloads

下載這2個(64位的): MySQL-client MySQL-server

sudo yum install libaio
sudo rpm -i MySQL-client-5.5.13-1.rhel5.x86_64.rpm
sudo rpm -i MySQL-server-5.5.13-1.rhel5.x86_64.rpm
sudo /etc/init.d/mysql start
/usr/bin/mysqladmin -u root password '1'
sudo cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
sudo /etc/init.d/mysql restart
mysql -uroot -p1
下載編譯安裝php 5.3.6:
http://php.net/downloads.php

sudo yum install libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel libtool-ltdl-devel
tar -jxvf php-5.3.6.tar.bz2
cd php-5.3.6
./configure --prefix=/opt/php -with-apxs2=/opt/httpd/bin/apxs --with-curl --with-mcrypt --enable-mbstring --with-iconv --with-gd -with-jpeg-dir=/usr/local/lib --enable-pdo --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd
make
sudo make install
sudo cp php.ini-development /opt/php/lib/php.ini
sudo ln -s /opt/php/bin/php /usr/bin/php
sudo vi /opt/php/lib/php.ini

把include_path前面的分號刪除,改成include_path = "/opt/php/lib/php"
sudo vi /opt/httpd/conf/httpd.conf
在最下面加入一行AddHandler application/x-httpd-php .php
sudo /opt/httpd/bin/httpd -k restart
sudo vi /opt/httpd/htdocs/phpinfo.php
phpinfo.php的內容如下:

<?php
phpinfo();
?>
安裝完php,重啟apache,用瀏覽器訪問http://localhost/phpinfo.php,能正常顯示說明php裝好了。搜尋mysqlnd、pdo_mysql、mysqli,如果有,則說明php能訪問mysql。

PHP常用配置
http://www.cnblogs.com/sink_cup/archive/2011/10/28/php_ini.html

把apache加入系統service,開機自啟動
sudo cp /opt/httpd/bin/apachectl /etc/init.d/httpd
sudo vi /etc/init.d/httpd
在檔案開頭加入下面幾行:
!/bin/sh
chkconfig: 2345 85 15
description: Apache is a World Wide Web server.
sudo chmod +x /etc/init.d/httpd
sudo /sbin/chkconfig --add httpd
sudo /sbin/chkconfig --list httpd
sudo ln -s /sbin/chkconfig /usr/bin/chkconfig
sudo ln -s /sbin/service /usr/bin/service
把mysql加入系統service,開機自啟動
sudo /sbin/chkconfig --list mysql
通過rpm安裝的mysql,已經開機自啟動了。

安裝php擴充套件ssh2
先安裝libssh2

http://sourceforge.net/projects/libssh2/

./configure

make

sudo make install

再安裝ssh2

http://pecl.php.net/package/ssh2

/opt/php/bin/phpize && ./configure --with-ssh2 && make

sudo make install

在/opt/php/lib/php.ini中加1行:

extension=ssh2.so

相關文章