Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一組常用來搭建動態網站或者服務器的開源軟件,本身都是各自獨立的程序,但是因為常被放在一起使用,擁有了越來越高的兼容度,共同組成了一個強大的Web應用程序平台。隨著開源潮流的蓬勃發展,開放源代碼的LAMP已經與J2EE和.Net商業軟件形成三足鼎立之勢,並且該軟件開發的項目在軟件方面的投資成本較低,因此受到整個IT界的關注。從網站的流量上來說,70%以上的訪問流量是LAMP來提供的,LAMP是最強大的網站解決方案.
首先編譯安裝Apache之前我們要先解決依賴關系 http-2.4.20安裝前解決依賴關系先安裝apr、apr-util和pcre,安裝這apr和apr-util軟件包有兩種方式
第一、升級本機RPM包
第二、進行源碼編譯安裝,此處我們通用源碼編譯安裝
下載地址: http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz
[root@server1 src]# tar zxvf apr-1.5.2.tar.gz
[root@server1 src]# cd apr-1.5.2
[root@server1 apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@server1 apr-1.5.2]# make && make install
編譯安裝apr-util(apr-util-1.5.4.tar.gz)
下載地址: http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz
[root@server1 src]# tar zxvf apr-util-1.5.4.tar.gz
[root@server1 apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #編譯安裝apr-util必須指定apr的安裝位置
[root@server1 apr-util-1.5.4]# make && make install
編譯安裝pcre (pcre-8.38.tar.gz) ## 此處你也可以進行本地RPM包的安裝
下載地址: https://sourceforge.net/projects/pcre/files/pcre/8.38/pcre-8.38.tar.gz/download
[root@server1 src]# tar zxvf pcre-8.38.tar.gz
[root@server1 src]# cd pcre-8.38
[root@server1 pcre-8.38]# ./configure --prefix=/usr/local/pcre
[root@server1 src]# make && make install
編譯安裝Apache
下載地址: http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.20.tar.gz
[root@server1 src]# tar zxvf httpd-2.4.20.tar.gz
[root@server1 src]# cd httpd-2.4.20
[root@server1 httpd-2.4.20]# ./configure \
--prefix=/usr/local/apache --sysconfdir=/etc/httpd \
--enable-so --enable-ssl --enable-cgi --enable-rewrite \
--with-zlib --with-pcre=/usr/local/pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-mods-shared=most --enable-mpms-shared=all \
--with-mpm=event
[root@server1 httpd-2.4.20]# make && make install
選項解釋:
--prefix=/usr/local/apache # 指定安裝目錄
--sysconfdir=/etc/httpd # 指定配置文件安裝路徑
--enable-so --enable-ssl #允許運行時加載DSO模塊 # 啟動ssl加密功能
--enable-cgi --enable-rewrite # 啟用cgi協議 #啟用URL重寫功能
--with-zlib --with-pcre # 指定pcre的安裝路徑
--with-apr=/usr/local/apr #指定apr的安裝路徑
--with-apr-util=/usr/local/apr-util # 指定apr-util的安裝路徑
--enable-modules=most # 啟用大多數共享模塊
--enable-mpms-shared=most #啟用MPM大多數參數
--with-mpm=event #指定使用的MPM的類型
啟動Apache服務並驗證
[root@server1 bin]# ./apachectl start # 找到我們編譯安裝時指定的安裝路徑下bin目錄下
[root@server1 bin]# crul http://localhost # 驗證apache是否可以正常訪問
修改apache的配置文件並設置PidFile路徑(默認在/usr/local/apache/logs/httpd.pid)
[root@server1 bin]# ./apachectl stop # 先停止apache服務
[root@server1 bin]# vim /etc/httpd/httpd.conf # 添加以下內容
PidFile "/var/run/httpd.pid"
[root@server1 bin]# ./apachectl start
編寫服務腳本/etc/init.d/httpd,讓其可以使用service起停,並可以加到服務列表中
[root@server1 ~]# vim /etc/init.d/httpd #添加以下內容
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
<1> 給腳本添加執行權限
[root@server1 ~]# chmod +x /etc/init.d/httpd
[root@server1 ~]# service httpd start
Starting httpd: [ OK ]
[root@server1 ~]# service httpd status
httpd (pid 3365) is running...
<2> 將httpd服務加到服務列表中,並設置在235級別開機啟動
[root@server1 ~]# chkconfig --add httpd
[root@server1 ~]# chkconfig httpd --level 235 on
[root@server1 ~]# chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:off 5:on 6:off
將/usr/local/apache/bin加入到PATH路徑中去,讓其中的命令可以進行全局執行
[root@server1 ~]# vim /etc/profile.d/apache.sh # 腳本的名字必須要以.sh命名
export PATH=$PATH:/usr/local/apache/bin
編譯安裝MySQL前預准備
安裝前預准備,創建用戶和組,在Mysql5.5以後版本中編譯工具變成了cmake,編譯前確認系統已安裝cmake編譯工具。
建立mysql組和用戶,並將mysql用戶添加到mysql組
[root@server1 src]# groupadd mysql
[root@server1 src]# useradd -g mysql mysql
編譯安裝cmake工具(cmake-3.5.2.tar.gz)
下載地址: https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz –no-check-certificate
[root@server1 src]# tar zxvf cmake-3.5.2.tar.gz
[root@server1 src]# cd cmake-3.5.2
[root@server1 cmake-3.5.2]# ./bootstrap --prefix=/usr/local/cmake
[root@server1 cmake-3.5.2]# gmake & gmake install #默認安裝到/usr/local/bin/cmake
[root@server1 ~]# vim /etc/profile.d/cmake.sh # 將/usr/local/bin加到PATH中
export PATH=$PATH:/usr/local/cmake/bin
創建mysql數據文件存放的目錄
[root@server1 ~]# fdisk /dev/sdb # 分一個10G大小的分區
[root@server1 ~]# pvcreate /dev/sdb1
[root@server1 ~]# pvcreate /dev/sdb1
[root@server1 ~]# vgcreate myvg /dev/sdb1
[root@server1 ~]# lvcreate -L +10G -n mysql_date myvg
[root@server1 ~]# mke2fs -jv /dev/myvg/mysql_data
[root@server1 ~]# mkdir -p /mydata/mysql_data #建立數據存放目錄
[root@server1 ~]# vim /etc/fstab # 設置開機自動掛載
/dev/myvg/mysql_data /mydata ext3 defaults 0 0
[root@server1 ~]# mount -a # 重新加載
[root@server1 /]# chown -R mysql.mysql /mysql_date/ # 將目錄屬主屬組給改為mysql
[root@server1 /]# chmod o-rx mysql_date/mydata/ # 設置其他人沒有任何權限
編譯安裝MySQL
下載地址:wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12.tar.gz
[root@server1 src]# tar zxvf mysql-5.7.12.tar.gz
[root@server1 mysql-5.7.12]#cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mysql_date/mydata \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=../boost_1_59_0 \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \ MySQL的readline library
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled
[root@server1 mysql-5.7.12]# make && make install
參數解釋:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql # MySQL安裝的根目錄
-DMYSQL_DATADIR=/mysql_date/mydata # MySQL數據庫文件存放目錄
-DDOWNLOAD_BOOST=1 #從MySQL 5.7.5開始Boost庫是必需的
-DWITH_BOOST=../boost_1_59_0 # boost庫安裝目錄
-DSYSCONFDIR=/etc # MySQL配置文件所在目錄
-DMYSQL_USER=mysql # MySQL用戶名
-DWITH_MYISAM_STORAGE_ENGINE=1 # MySQL的數據庫引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 # MySQL的數據庫引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 # MySQL的數據庫引擎
-DWITH_MEMORY_STORAGE_ENGINE=1 # MySQL的數據庫引擎
-DWITH_READLINE=1 # MySQL的readline library
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock # MySQL的通訊目錄
-DMYSQL_TCP_PORT=3306 # MySQL的監聽端口
-DENABLED_LOCAL_INFILE=1 # 啟用加載本地數據
-DENABLE_DOWNLOADS=1 # MySQL編譯時允許自主下載相關文件
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all # 使MySQL支持所有的擴展字符
-DDEFAULT_CHARSET=utf8 # 設置MySQL的默認字符集為utf8
-DDEFAULT_COLLATION=utf8_general_ci #設置MySQL的默認字符校對
-DWITH_DEBUG=0 # 禁用調試模式
-DMYSQL_MAINTAINER_MODE=0
-DWITH_SSL:STRING=bundled # 設置MySQL通訊時支持ssl協議
-DWITH_ZLIB:STRING=bundled # 允許MySQL使用zlib library
更改mysql安裝目錄的屬主屬組並添加mysql環境變量
[root@server1 mysql]# chown -R mysql.mysql .
[root@server1 mysql]# vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
加入服務列表並設置為開機自啟
[root@server1 ~]# cd /usr/local/mysql/support-files/
[root@server1 support-files]# cp mysql.server /etc/init.d/mysqld
[root@server1 support-files]# chmod +x /etc/init.d/mysqld # 添加一個執行權限
[root@server1 support-files]# chkconfig mysqld on
[root@server1 support-files]# chkconfig mysqld --level 2345 on
[root@server1 support-files]# chkconfig --list mysqld
[root@server1 support-files]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
修改mysql的配置文件,以下內容為自選
[root@server1 ~]# vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
skip-name-resolve
skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
初始化MySQL自身的數據庫
##“-–initialize”會生成一個隨機密碼(~/.mysql_secret),而”–initialize-insecure”不會生成密碼 ##user表示指定用戶 ##basedir表示mysql的安裝路徑,# datadir表示數據庫文件存放路徑
[root@server1 ~]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mysql_date/mydata/
啟動MySQL數據庫
[root@server1 ~]# mysqld_safe –user=mysql –datadir=/mysql_date/mydata/ ## datadir指定數據目錄
[root@server1 ~]# service mysqld start
Starting MySQL [ OK ]
查看MySQL服務的進程和端口
[root@server1 ~]# ps -ef | grep mysqld
root 31618 1 0 16:22 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/mysql_date/mydata --pid-file=/mysql_date/mydata/server1.pid
mysql 32370 31618 0 16:22 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mysql_date/mydata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql_date/mydata/mysql-error.log --open-files-limit=65535 --pid-file=/mysql_date/mydata/server1.pid --socket=/tmp/mysql.sock --port=3306
root 34026 29191 1 16:59 pts/1 00:00:00 grep mysqld
[root@server1 ~]# netstat -an | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
初始化MySQL數據庫的root用戶密碼
[root@typecodes mysql]# mysql_secure_installation
............省略前面的過程............
Press y|Y for Yes, any other key for No: y #需要修改密碼,所以輸入y
There are three levels of password validation policy:
LOW Length >= 8 #只需要長度大於或等於8】
MEDIUM Length >= 8, numeric, mixed case, and special characters #還需要包含數字、大小寫和類似於@#%等特殊字符
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file #還需要包含字典文件
............省略剩下的過程............
將MySQL數據庫的動態鏈接庫共享至系統鏈接庫
[root@server1 ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib [root@server1 ~]# ldconfig -v # 讓系統重新讀取庫文件
測試登陸MySQL數據庫
[root@server1 ~]# mysql -u root -p
Enter password: # 輸入之前設置的密碼
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.12-log Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
編譯安裝PHP前預准備
如果想讓編譯的php支持mcrypt擴展,還需要下載的php擴展包(mcrypt-2.6.8.tar.gz、libmcrypt-2.5.8.tar.gz、mhash-0.9.9.9.tar.gz)
下載地址:
http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz
http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
安裝順序( libmcrypt –> mhash –> mcrypt )
編譯安裝libmcrypt(libmcrypt-2.5.8.tar.gz)
[root@server1 src]# tar zxvf libmcrypt-2.5.8.tar.gz
[root@server1 src]# cd libmcrypt-2.5.8
[root@server1 libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt
[root@server1 libmcrypt-2.5.8]# make && make install
[root@server1 libmcrypt-2.5.8]# vim /etc/ld.so.conf.d/libmcrypt.conf # 此選項為將libmcrypt的庫文件能讓系統找到,不然後面編譯安裝mcrypt會報錯
/usr/local/libmcrypt/lib
[root@server1 libmcrypt-2.5.8]# ldconfig -v # 重新加載庫文件
編譯安裝mhash(mhash-0.9.9.9.tar.gz)
[root@server1 src]# tar -zxvf mhash-0.9.9.9.tar.gz
[root@server1 src]# cd mhash-0.9.9.9
[root@server1 mhash-0.9.9.9]# ./configure
[root@server1 mhash-0.9.9.9]# make && make install
[root@server1 mhash-0.9.9.9]# vim /etc/ld.so.conf.d/mhash.conf # 做添加mhash的庫文件讓系統找到,不然後面編譯安裝mcrypt會報錯
/usr/local/mhash/lib
[root@server1 mhash-0.9.9.9]# ldconfig -v # 重新加載庫文件
編譯安裝mcrypy(mcrypt-2.6.8.tar.gz)
[root@server1 src]# tar zxvf mcrypt-2.6.8.tar.gz
[root@server1 src]# cd mcrypt-2.6.8
[root@server1 mcrypt-2.6.8]# ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt/
[root@server1 mcrypt-2.6.8]# make && make install
編譯安裝PHP
下載地址:http://cn2.php.net/get/php-5.5.36.tar.bz2/from/this/mirror
[root@server1 src]# tar -zxvf php-5.5.36.tar.gz
[root@server1 php-5.5.36]#./configure
--prefix=/usr/local/php \
--with-mysql=mysqlnd --with-openssl \
--with-mysqli=mysqlnd \
--enable-mbstring --with-freetype-dir \
--with-jpeg-dir --with-png-dir \
--with-zlib --with-libxml-dir=/usr \
--enable-xml --enable-sockets \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-mcrypt --with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 --enable-maintainer-zts
[root@server1 php-5.5.36]# make && make install
參數解釋;
--prefix=/usr/local/php # 指定php安裝的路徑
--with-mysql=mysqlnd --with-openssl # 指定mysql的安裝目錄 #支持ssl功能
--with-mysqli=mysqlnd # 可以讓mysql與php結合的接口
--enable-mbstring --with-freetype-dir # 指定可以支持中文非一個字節能表示語言 # 加載freetype的頭文件,可以支持不同字體
--with-jpeg-dir --with-png-dir # 支持jpep格式圖片 #支持pnp格式圖片
--with-zlib --with-libxml-dir=/usr # 支持壓縮庫 # 指定xml的庫路徑
--enable-xml --enable-sockets #支持擴展標記語言 # 支持套接字的通信功能
--with-mcrypt --with-config-file-path=/etc # 支持額外的加密功能的庫 # 指定php配置文件的路徑(/etc/php.ini)
--with-config-file-scan-dir=/etc/php.d # 支持php文件的附件配置文件(/etc/php.d/*.ini)
--with-bz2 --enable-maintainer-zts #支持bz2的壓縮庫 # 此選項是否安裝取決於你的Apache工作的mpm模式,
說明:
1、這裡為了支持apache的worker或event這兩個MPM,編譯時使用了–enable-maintainer-zts選項。【prefork不需要加載】【event或work
mpm工作模式必須要加此選項】 驗證Apache mpm工作模式命令:httpd -M
2、如果使用PHP5.3以上版本,為了鏈接MySQL數據庫,可以指定mysqlnd,這樣在本機就不需要先安裝MySQL或MySQL開發包了。mysqlnd從php5.3開始可用,可以編譯時綁定到它(而不用和具體的MySQL客戶端庫綁定形成依賴),但從PHP 5.4開始它就是默認設置了。 ./configure –with-mysql=mysqlnd –with-pdo-mysql=mysqlnd
–with-mysqli=mysqlnd
為php提供配置文件:
[root@server1 php-5.5.36]# cp php.ini-production /etc/php.ini
編輯apache配置文件httpd.conf,以apache支持php
[root@server1 ~]# vim /etc/httpd/httpd.conf
<1> 添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<2> 定位至DirectoryIndex index.html
修改為:
DirectoryIndex index.php index.html
重啟apache服務
[root@server1 ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@server1 ~]# netstat -an | grep :80 # apache已啟動,並監聽80端口
tcp 0 0 :::80 :::* LISTEN
編輯Apache的網頁測試是否支持php、
[root@server1 ~]# cd /usr/local/apache/htdocs/
[root@server1 htdocs]# vim index.php
打開浏覽器進行web測試訪問
編輯Apache的網頁測試php是否可以連接MySQL、
[root@server1 htdocs]# vim index.php
打開浏覽器進行web測試訪問
關閉MySQL服務再來測試
[root@server1 htdocs]# service mysqld stop
Shutting down MySQL. [ OK ]
[root@server1 htdocs]# service mysqld status
MySQL is not running [FAILED]
[root@server1 htdocs]# netstat -an | grep 3306
打開浏覽器進行web測試訪問
到此為止我們基於源碼安裝的LAMP就搭建好了,在搭建環境的期間出現了好多問題,經過各種的google和前車之鑒,最終還是搭建好了。