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

 

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