lamp服務器搭建參考

操作系統:centos6.5

卸載系統默認安裝的apache

#查詢當前系統中已安裝的apache軟件包
rpm -qa httpd*
#通過rpm -e --nodeps後面分別接查詢到的apache軟件包完整名稱,即可卸載當前系統中通過rpm安裝方式安裝的apache軟件包
#--nodeps:Don’t do a dependency check,意思是不做軟件間的依賴檢查
rpm -e --nodeps httpd-2.xxxxx

安裝apache

版本:2.4.17

包名:httpd-2.4.17.tar.gz

地址:http://archive.apache.org/dist/httpd/httpd-2.4.17.tar.gz

#解壓縮
tar zxvf httpd-2.4.17.tar.gz
cd httpd-2.4.17

編譯

#編譯參數說明:

#1. --prefix=/wwwServ/apache 表示指定安裝路徑爲:/wwwServ/apache。如果不指定安裝路徑,則默認路徑爲:/usr/local/apache2
#2. --enable-deflate 提供對內容的壓縮傳輸編碼支持,一般html,js,css等內容的站點,使用此參數功能會大大提高傳輸速度,提升訪問者訪問體驗。在生產環境中,這是apache調優的一個重要選項之一
#3. --enable-expires 激活允許通過配置文件控制http的“expires”和“cahe-control:”頭內容,即對網站圖片,JS,CSS等內容,提供在客戶端瀏覽器緩存的設置。這是apache調優的一個重要選項之一
#4. --enable-headers 提供允許對HTTP請求頭的控制
#5. --with-mpm=worker 選擇apache mpm的模式爲worker模式,因爲worker模式原理是更多的使用線程處理請求,所以可以處理更多的併發請求,而系統資源的開銷小於基於進程的mpm prefork。如果不指定此參數,默認的模式是prefork進程模式。這是apache調優的一個重要選項之一
#6. --enable-rewrite 提供基於URL規則的重寫功能。即根據已知URL地址,轉換其它想要的URL地址。如前文講解的僞靜態功能就是這個模塊實現的。這是APACHE在生產環境中必用的一個重要功能。
#7. --enable-so 激活APACHE服務的DSO(全稱dynamic shared object,動態共享對象)支持,即在以後可以以DSO的方式編譯安裝共享模塊。這個模塊本身不能以DSO方式編譯。有關DSO的知識,後文講解。
./configure \
--prefix=/wwwServ/apache \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-modules=most \
--enable-so \
--with-mpm=worker \
--enable-rewrite \
--with-apr-util=/usr/local/apr-util/ \
--with-pcre=/usr/local/pcre/

錯誤處理:


#錯誤,沒有安裝apr
configure: error: APR not found.  Please read the documentation.
#處理方法
#1.下載apr包
wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
#2.解壓、編譯、安裝
tar -zxvf apr-1.4.5.tar.gz  
cd apr-1.4.5  
./configure --prefix=/usr/local/apr  
make && make install
#3.apache的編譯中加上apr包的路徑
--with-apr=/usr/local/apr

#錯誤,沒有安裝apr-util
configure: error: APR-util not found.  Please read the documentation.
#處理方法
#1.下載apr-util包
wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
#2.解壓、編譯、安裝
tar -zxvf apr-util-1.3.12.tar.gz  
cd apr-util-1.3.12
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 
make && make install
#3.apache的編譯中加上apr-util包的路徑
--with-apr=/usr/local/apr-util

#錯誤,沒有安裝pcre
configure: error: pcre not found.  Please read the documentation.
#處理方法
#1.下載pcre包
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
#2.解壓、編譯、安裝
unzip -o pcre-8.10.zip 
cd pcre-8.10
./configure --prefix=/usr/local/pcre 
make && make install
#3.apache的編譯中加上apr包的路徑
--with-pcre=/usr/local/pcre

#錯誤,沒有安裝zlib-devel
checking for zlib location… not found
#處理方法
yum install zlib-devel

安裝:

make && make install

完成安裝。正確無誤的情況下 瀏覽器中使用ip訪問會出現it works!


安裝mysql

版本:5.5.46

包名:mysql-5.5.46.tar.gz

地址:https://downloads.mysql.com/archives/get/file/mysql-5.5.46.tar.gz

#解壓縮
tar xvzf mysql-5.5.46.tar.gz
cd mysql-5.5.46

安裝 cmake ncurses-devel boost 等庫

yum install boost 
yum install cmake
yum install ncurses-devel

安裝前準備:

#查看mysql的數據庫文件所存放路徑
mysql> show global variables like "%datadir%";

#刪除系統自帶的mysql
rpm -qa|grep mysql
rpm -e mysql-libs --nodeps

編譯:

cmake -DCMAKE_INSTALL_PREFIX=/wwwServ/mysql \
-DMYSQL_DATADIR=/wwwServ/mysql/data/ \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DDOWNLOAD_BOOST=1 

安裝:

make 
make install 
make clean 
rm CMakeCache.txt

配置mysql:

#配置環境變量
echo "PATH=$PATH:/wwwServ/mysql/bin" > /etc/profile.d/mysql.sh 
#使生效
source /etc/profile

#檢測是否加入開機自啓動
chkconfig --list|grep mysqld
#加入開機自啓動
cp /wwwServ/mysql/support-files/mysql.server /etc/init.d/mysqld 
ldconfig 
chmod 755 /etc/init.d/mysqld  
chkconfig –add mysqld 
chkconfig –level 345 mysqld on


#初始化mysql
cd /wwwServ/mysql/scripts
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data

#啓動mysql
service mysqld start

#設置密碼
mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');

附上my.cnf文件內容供參考:

# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

#datadir=/wwwServ/mysql/data
#user=mysql
#log-error = /wwwServ/mysql/data/error.log
#tmpdir = /var/tmp

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id       = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2

# The replication master for this slave - required
#master-host     =   <hostname>

# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>

# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /wwwServ/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /wwwServ/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

#[mysqld_safe]
#log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid

php安裝

#下載PHP源碼包
wget http://am1.php.net/distributions/php-5.5.30.tar.gz

安裝前準備

#安裝依賴包
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y

編譯

./configure \
--prefix=/wwwServ/php  \
--with-config-file-path=/wwwServ/php/etc  \
--with-apxs2=/wwwServ/apache/bin/apxs  \
--with-mysql=/wwwServ/mysql/  \
--with-mysqli=/wwwServ/mysql/bin/mysql_config  \
--with-openssl  \
--with-zlib  \
--with-gd  \
--with-jpeg-dir  \
--with-png-dir  \
--with-zlib-dir  \
--with-freetype-dir  \
--with-gettext  \
--with-curl=/usr/local/curl/  \
--with-mcrypt  \
--enable-ftp  \
--enable-sockets  \
--enable-soap  \
--enable-mbstring=all  \
--with-pdo-mysql=/wwwServ/mysql/  \
--enable-zip  \
--enable-bcmath  \
--with-gmp=/usr/local/gmp6.1.1/ 

錯誤處理

#錯誤
Cannot find OpenSSL's <evp.h>
#處理方法
yum install openssl openssl-devel

#錯誤
Unable to locate gmp.h
#處理方法
yum install gmp-devel

安裝

make && make install

修改httpd.conf

瀏覽器訪問不顯示文件夾索引

Options Indexes FollowSymLinks 改爲 Options -Indexes +FollowSymLinks

添加.php的識別

DirectoryIndex index.php index.html

 

配置工作:
重啓使用../apache/bin/apachectl start

不要使用service httpd start   否則會出現奇怪的問題。可能是因爲這個命令開啓的系統自帶的apache

 

運行以下命令可以使用service httpd start等命令

cp ../apache/bin/apachectl /etc/rc.d/init.d/httpd

 

 

參考資料:

安裝apache相關:

https://www.cnblogs.com/ginvip/p/6400304.html

https://blog.csdn.net/CuiXiaoBo521/article/details/78028610

https://blog.csdn.net/dongyanwen6036/article/details/77332771

安裝mysql相關:

https://blog.csdn.net/weixin_37750188/article/details/78816712

https://www.cnblogs.com/sqbk/p/5888331.html

安裝php相關:

https://www.cnblogs.com/zdqc/p/9510072.html

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章