一、安裝Apache
若要安裝apache服務器軟件,需要安裝以下幾個依賴軟件
apr-1.4.6.tar.gz 下載地址:http://apr.apache.org/
apr-util-1.4.1.tar.gz 下載地址:http://apr.apache.org/
pcre-8.20.tar.gz 下載地址:http://www.pcre.org/
httpd-2.4.10.tar.gz 下載地址:http://httpd.apache.org/download.cgi
將以上軟件都下載到自定義目錄如:/home/cc/apache,並分別解壓縮各個壓縮包
1、安裝apr(以下軟件默認安裝的目錄為:/usr/local/)
tar -zxvf apr-1.5.1.tar.gz cd apr-1.5.1 ./configure --prefix=/usr/local/apr make && make install
2、安裝apr-util
tar -zxvf apr-util-1.5.4.tar.gz cd apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/ make && make install
3、安裝pcre
tar pcre-8.36.tar.gz cd ../pcre-8.36 ./configure --prefix=/usr/local/pcre make && make install
4、安裝Apache
tar -zxvf httpd-2.4.10.tar.gz cd httpd-2.4.10 ./configure --prefix=/usr/local/apache/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/ make && make install
報錯以及解決方法:
1、AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
解決方法
#ServerName www.example.com:80
ServerName localhost:80
2、(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
解決方法:
查看到對應哪個應用占用了80端口:
netstat -tulnp | grep ':80 ' 或者 ps -ef | grep httpd
kill ‘PID’ 或者 killall -9 httpd
二、安裝MySQL
MySql5.5版本之后是需要用cmake命令安裝源碼編譯的,所以需要現在系統上安裝cmake
mysql-5.6.19.tar.gz 下載地址:http://dev.mysql.com/downloads/mysql/(選擇Source Code)
make-4.0.tar.gz 下載地址:http://ftp.gnu.org/gnu/make/
GCC 4.8.3 下載地址:http://www.gnu.org/software/gcc/
(上面兩項linux系統自帶的有,所以一般不需要再次下載安裝)
cmake-3.0.2.tar.gz 下載地址:http://www.cmake.org/download/
bison-3.0.tar.gz 下載地址:http://www.gnu.org/software/bison/
ncurses-5.9.tar.gz 下載地址:http://www.gnu.org/software/ncurses/
tar -zxvf mysql-5.6.19.tar.gz
cd mysql-5.6.19 以下是一行 這里為了方便大家理解和注釋寫成換行注釋,實際編譯中請在換行前 加 " \ "鏈接,以下代碼可以直接復制黏貼 cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci make && make install (此過程需要半個小時的時間)
如果沒有mysql用戶和mysql用戶組,則需要新建mysql用戶和mysql用戶組
useradd mysql
groupadd -g mysql mysql
cd /usr/local/mysql chown -R mysql:mysql . (請注意點號) ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data chown -R root:mysql . (請注意點號) chown -R mysql:mysql ./data chmod -R ug+rwx . (請注意點號) #cp support-files/my-medium.cnf /etc/my.cnf (原始老版本是此操作,5.6.12版本的是如下文件地址) cp support-files/my-default.cnf /etc/my.cnf (並給/etc/my.cnf +x權限 同時刪除 其他用戶的寫權限) vi /etc/my.cnf 編輯my.cnf配置文件 default-storage-engine=MyISAM explicit_defaults_for_timestamp=true (此處是用於開啟緩存)
啟動mysql 服務
/usr/local/mysql/bin/mysqld_safe --user=mysql &
#將mysql的啟動服務添加到系統服務中
cp support-files/mysql.server /etc/init.d/mysql
#讓chkconfig管理mysql服務
chkconfig --add mysql
#開機啟動
chkconfig mysql on
啟動MySQL服務
service mysql start
修改root用戶密碼
/usr/local/mysql/bin/mysqladmin -u root password
新建用戶時候報錯解決方法:
打開my.cnf,查找
sql_mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
修改為
sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
然后重啟MYSQL /etc/init.d/mysqld restart
三、安裝PHP
tar -zxvf php-5.5.13.tar.gz cd php-5.5.13 ./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/lib --with-mysql=/usr/local/mysql --enable-track-vars --with-xml make && make install
1、cp php.ini-production /usr/local/php/lib/php.ini
2、vim /usr/local/apache/conf/httpd.conf
添加如下AddType到已有的AddType下面(沒有下面語句將不能解析php文本)
AddTypeapplication/x-httpd-php .php
<IfModule dir_module>
DirectoryIndex index.html index.php //首頁索引添加index.php
</IfModule>
LoadModule php5_module modules/libphp5.so