1. 安裝mysqlphp
###############################html
注意,剛開始安裝出錯,緣由是二進制包下載錯了,本機centos是32位的,卻下載了個64位的二進制包mysql
###############################linux
[root@chen src]# cd /usr/local/src/sql
[root@chen src]# wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz apache
#二進制包免編譯,如果64位系統,則下載這個包,32位則下載下面排錯時的包vim
[root@chen src]# tar zxvf mysql-5.1.73-linux-x86_64-glibc23.tar.gzcentos
[root@chen src]# mv mysql-5.1.73-linux-x86_64-glibc23 /usr/local/mysqlapp
[root@chen ~]# useradd -s /sbin/nologin mysqlcurl
[root@chen ~]# cd /usr/local/mysql
[root@chen mysql]# mkdir -p /data/mysql
[root@chen mysql]# chown -R mysql:mysql /data/mysql
[root@chen mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
./scripts/mysql_install_db: line 249: ./bin/my_print_defaults: cannot execute binary file
Neither host 'chen' nor 'localhost' could be looked up with
./bin/resolveip
Please configure the 'hostname' command to return a correct
hostname.
If you want to solve this at a later stage, restart this script
with the --force option
########################
此時出現錯誤,通過蒐集資料,發現是由於本機系統爲32位,卻下載了一個64位的二進制包
使用命令以下命令查看本機系統是32位,仍是64位
[root@chen mysql]# getconf LONG_BIT
32
########################
#從新下下載一個對應包,再進行以前的操做,錯誤解決
[root@chen mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
#出現兩個OK則正確安裝上了
[root@chen mysql]# cp support-files/my-large.cnf /etc/my.cnf
cp:是否覆蓋"/etc/my.cnf"? y #因爲系統自帶此文件,須要將它覆蓋掉
[root@chen mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@chen mysql]# chmod 755 /etc/init.d/mysqld
[root@chen mysql]# vim /etc/init.d/mysqld #修改basedir和basedir,以下:
# overwritten by settings in the MySQL configuration files.
basedir=/usr/local/mysql
datadir=/data/mysql
[root@chen mysql]# chkconfig --add mysqld
[root@chen mysql]# chkconfig mysqld on
[root@chen mysql]# service mysqld start
Starting MySQL............. SUCCESS!
#成功安裝並啓動mysql
2. 安裝apache
[root@chen src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.tar.gz
[root@chen src]# tar zxvf httpd-2.2.31.tar.gz
[root@chen src]# cd httpd-2.2.31
[root@chen httpd-2.2.31]# ./configure --prefix=/usr/local/apache2 --with-included-apr --with-pcre --enable-mods-shared=most
[root@chen httpd-2.2.31]# echo $? #檢查上一步是否出錯,若爲0則未出錯,非0則有錯
0
[root@chen httpd-2.2.31]# make && make install
[root@chen httpd-2.2.31]# echo $?
0
【如何指定使用worker/prefork】http://www.lishiming.net/thread-944-1-1.html
【apache兩種工做模式】http://www.lishiming.net/thread-838-1-2.html
3. 安裝php
[root@chen src]# wget http://cn2.php.net/distributions/php-5.3.28.tar.gz
[root@chen src]# tar zxf php-5.3.28.tar.gz
[root@chen src]# cd php-5.3.28
[root@chen php-5.3.28]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/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 --disable-ipv6
######################
執行上面命令的過程當中會遇到一些依賴缺乏的提示,下面列出我遇到的依賴問題: 錯誤: configure: error: xml2-config not found. Please check your libxml2 installation. 解決: yum install -y libxml2-devel 錯誤: configure: error: jpeglib.h not found. 解決: yum install -y libjpeg-devel 錯誤: configure: error: mcrypt.h not found. Please reinstall libmcrypt. 解決: yum install -y libmcrypt-devel 因爲版權緣由,可能沒法直接安裝上面的包,在百度經驗裏找到了一個解決辦法: http://jingyan.baidu.com/article/54b6b9c0e94f1e2d583b4782.html 錯誤: checking for recode support... yes configure: error: Can not find recode.h anywhere under /usr /usr/local /usr /opt. 解決: yum install -y librecode-devel
######################
從新編譯執行如上操做,出現如下提示,則代表安裝成功:
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
[root@chen php-5.3.28]# echo $?
0
[root@chen php-5.3.28]# make && make install
[root@chen php-5.3.28]# echo $?
0
[root@chen php-5.3.28]# cp php.ini-production /usr/local/php/etc/php.ini #拷貝配置文件
4. 配置apache結合php
vim /usr/local/apache2/conf/httpd.conf找到:
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
改成:
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
找到:
AddType application/x-gzip .gz .tgz
在該行下面添加:
AddType application/x-httpd-php .php
找到:
DirectoryIndex index.html
將該行改成:
DirectoryIndex index.html index.htm index.php
找到:
#ServerName www.example.com:80
修改成:
ServerName localhost:80
查看配置文件是否有問題:
/usr/local/apache2/bin/apachectl -t
若是顯示Syntax OK,則沒有問題了。而後啓動服務:
/usr/local/apache2/bin/apachectl start
檢查Apache是否正常啓動:
[root@chen php-5.3.28]# ps aux |grep httpd
root 6733 0.0 1.0 28912 9952 ? Ss 03:58 0:00 /usr/local/apache2/bin/httpd -k start
daemon 6734 0.0 0.9 28912 8716 ? S 03:58 0:00 /usr/local/apache2/bin/httpd -k start
daemon 6735 0.0 0.9 28912 8716 ? S 03:58 0:00 /usr/local/apache2/bin/httpd -k start
daemon 6736 0.0 0.9 28912 8716 ? S 03:58 0:00 /usr/local/apache2/bin/httpd -k start
daemon 6737 0.0 0.9 28912 8716 ? S 03:58 0:00 /usr/local/apache2/bin/httpd -k start
daemon 6738 0.0 0.9 28912 8716 ? S 03:58 0:00 /usr/local/apache2/bin/httpd -k start
root 6753 0.0 0.0 6052 788 pts/0 S+ 04:01 0:00 grep httpd
5. 測試解析php
vim /usr/local/apache2/htdocs/1.php
寫入:
<?php
echo "php解析正常";
?>
保存後,繼續測試:
curl localhost/1.php