共计 16701 个字符,预计需要花费 42 分钟才能阅读完成。
本文目录
1. 编译 apache httpd
2. 编译 php
2.1 php 编译选项说明
2.2 php 编译过程
2.3 配置 httpd 使其转发动态请求给 php-fpm
3. 为 php 安装 xcache
3.1 基本安装
3.2 设置管理员后台
4 安装 MySQL(MariaDB)
4.1 初始化实例
4.2 安装后的规范化操作
5 测试 LAMP——搭建 discuz 论坛
本文给出搭建 LAMP 的步骤,其中 php 使用的是 php-fpm 管理方式,php 和 MySQL(MariaDB)交互使用的是 mysqlnd 方式(另一种是 libmysql)。最后给出一个 php+mysql 的论坛程序 discuz 的布置过程。
1. 编译 apache httpd
此处只简单给出编译 httpd 的步骤,具体的编译细节知识点见 编译 httpd 细节。
httpd 相关资源下载地址:http://archive.apache.org/dist/
安装依赖包。
yum -y install pcre pcre-devel expat-devel
编译 apr 和 apr-util。
tar xf apr-1.6.2.tar.gz | |
tar xf arp-1.6.0.tar.gz | |
cd apr-1.6.0 | |
./configure --prefix=/usr/local/apr | |
make | |
make install | |
cd ../apr-util-1.6.2 | |
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr | |
make | |
make install |
编译 httpd。
tar xf httpd-2.4.27.tar.gz | |
cd httpd-2.4.27 | |
./configure --prefix=/usr/local/apache --sysconfdir=/etc/apache --with-z --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-mpm=event --enable-mpms-shared=all |
编译后的规范化操作:
# 设置 man 路径。 | |
echo "MANPATH /usr/local/apache/man" >>/etc/man.config | |
# 设置 PATH 环境变量。 | |
echo 'PATH=/usr/local/apache/bin:$PATH' >/etc/profile.d/apache.sh | |
source /etc/profile.d/apache.sh | |
# 输出头文件。 | |
ln -s /usr/include /usr/local/apache/include |
提供服务启动脚本:
提供不提供没多大所谓,因为 apachectl 或 httpd 命令自身可以管理进程的启停,但自身管理启停时不提供 lock 文件。
如果要提供的话,从 yum 安装的 httpd 提供的 /usr/lib/systemd/system/httpd.service(systemd)或 /etc/init.d/httpd(sysV)拷贝后稍作修改就可以了。以下是按照我上面编译的环境做了修改后的 systemd 和 sysV 服务管理脚本。
以下是 httpd 的 systemd 服务管理脚本 /usr/lib/systemd/system/httpd.service。
[Unit] | |
Description=The Apache HTTP Server | |
After=network.target remote-fs.target nss-lookup.target | |
Documentation=man:httpd(8) | |
Documentation=man:apachectl(8) | |
[Service] | |
Type=notify | |
EnvironmentFile=/etc/sysconfig/httpd | |
ExecStart=/usr/local/apache/bin/httpd $OPTIONS -DFOREGROUND | |
ExecReload=/usr/local/apache/bin/httpd $OPTIONS -k graceful | |
ExecStop=/bin/kill -WINCH ${MAINPID} | |
# We want systemd to give httpd some time to finish gracefully, but still want | |
# it to kill httpd after TimeoutStopSec if something went wrong during the | |
# graceful stop. Normally, Systemd sends SIGTERM signal right after the | |
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give | |
# httpd time to finish. | |
KillSignal=SIGCONT | |
PrivateTmp=true | |
[Install] | |
WantedBy=multi-user.target |
以下是 httpd 的 sysV 服务管理脚本 /etc/rc.d/init.d/httpd。
# | |
# httpd Startup script for the Apache HTTP Server | |
# | |
# chkconfig: - 85 15 | |
# description: The Apache HTTP Server is an efficient and extensible \ | |
# server implementing the current HTTP standards. | |
# | |
###################################################################### | |
# 若 httpd 配置文件中指定了 PidFile,则修改此脚本中的 pidfile 变量 # | |
###################################################################### | |
. /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=/usr/local/apache/bin/apachectl | |
prog=httpd | |
pidfile=/usr/local/apache/logs/httpd.pid | |
lockfile=/var/lock/subsys/httpd | |
RETVAL=0 | |
STOP_TIMEOUT=${STOP_TIMEOUT-10} | |
config=/etc/apache/httpd.conf | |
# The semantics of these two functions differ from the way apachectl does | |
# things -- attempting to start while running is a failure, and shutdown | |
# when not running is also a failure. So we just do it the way init scripts | |
# are expected to behave here. | |
start() {echo -n $"Starting $prog:" | |
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd -f $config $OPTIONS | |
RETVAL=$? | |
echo | |
[$RETVAL = 0 ] && touch ${lockfile} | |
return $RETVAL | |
} | |
# When stopping httpd, a delay (of default 10 second) is required | |
# before SIGKILLing the httpd parent; this gives enough time for the | |
# httpd parent to SIGKILL any errant children. | |
stop() {status -p ${pidfile} $httpd > /dev/null | |
if [[$? = 0 ]]; then | |
echo -n $"Stopping $prog:" | |
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd | |
else | |
echo -n $"Stopping $prog:" | |
success | |
fi | |
RETVAL=$? | |
echo | |
[$RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} | |
} | |
reload() {echo -n $"Reloading $prog:" | |
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then | |
RETVAL=6 | |
echo $"not reloading due to configuration syntax error" | |
failure $"not reloading $httpd due to configuration syntax error" | |
else | |
# Force LSB behaviour from killproc | |
LSB=1 killproc -p ${pidfile} $httpd -HUP | |
RETVAL=$? | |
if [$RETVAL -eq 7 ]; then | |
failure $"httpd shutdown" | |
fi | |
fi | |
echo | |
} | |
# See how we were called. | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status -p ${pidfile} $httpd | |
RETVAL=$? | |
;; | |
restart) | |
stop | |
start | |
;; | |
condrestart|try-restart) | |
if status -p ${pidfile} $httpd >&/dev/null; then | |
stop | |
start | |
fi | |
;; | |
force-reload|reload) | |
reload | |
;; | |
graceful|help|configtest|fullstatus) | |
$apachectl $@ | |
RETVAL=$? | |
;; | |
*) | |
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}" | |
RETVAL=2 | |
esac | |
exit $RETVAL |
最后启动 httpd。
service httpd start
2. 编译 php
三种工作模式:CGI、作为模块加入到 apache、fastcgi。最简单的是以模块方式加入到 apache,此处演示的是 php-fpm 管理 php-cgi 方式。
fastcgi 模式的 php-cgi,由 php-fpm 提供服务管理,它会根据配置文件启动一定数量的 cgi 进程,其默认监听的端口为 9000,该服务正常工作需要配置文件。也就是说 fastcgi 模式的 php 有两个配置文件,一个是 php 的配置文件,一个是 php-fpm 的配置文件。
虽然此处演示的是 php-fpm 管理方式,但有必要说明下,在 Linux 中如果模块化安装 php,不推荐在使用 Apache 2.x 中使用线程化 MPM(worker 和 event),而是使用 prefork 模式的 mpm,因为 Linux 系统的线程设计并不那么完美。所以,如果 php 和 apache 在同一台主机上(cgi 或者模块化方式安装 php 的时候),建议 httpd 使用 prefork 模型,而不在同一台主机中,建议将 php 设计为 fastcgi 的工作模式。而在 windows 平台中则无需考虑这些问题,因为 windows 系统是真正意义上的多线程系统。
下载相关文件:
php 下载地址:http://php.net/downloads
php 手册地址:http://php.net/manual/zh/
手册下载地址:http://php.net/download-docs.php
2.1 php 编译选项说明
编译安装 php 有非常非常多的选项,比 httpd 还多。可以在解压 php 后的目录下使用 ./configure --help
查看。以下是部分选项,其中给出 ”–enable-XXXX” 的选项表示默认是 disable 的,若要开启,需要在此处手动 enable,如果给出的是 ”–disable-XXXX” 表示默认是 enable 的。
--prefix=PREFIX【SAPI modules:】--with-apxs2=FILE Build shared Apache 2.0 Handler module. FILE is the optional | |
pathname to the Apache apxs tool apxs | |
--enable-fpm Enable building of the fpm SAPI executable【General settings:】--with-config-file-path=PATH Set the path in which to look for php.ini [PREFIX/lib] | |
--with-config-file-scan-dir=PATH Set the path where to scan for configuration files【Extensions:】####################################################### | |
# --with-EXTENSION=shared[,PATH] # | |
# NOTE: Not all extensions can be build as 'shared'. # | |
# Example: --with-foobar=shared,/usr/local/foobar/ # | |
####################################################### | |
--with-openssl=DIR Include OpenSSL support (requires OpenSSL >= 0.9.6) | |
--enable-mbstring Enable multibyte string support | |
--with-zlib=DIR Include ZLIB support | |
--with-bz2=DIR Include BZip2 support | |
--with-mhash=DIR Include mhash support | |
--with-mcrypt=DIR Include mcrypt support | |
--with-freetype-dir=DIR GD: Set the path to FreeType 2 install prefix | |
--with-jpeg-dir=DIR GD: Set the path to libjpeg install prefix | |
--with-png-dir=DIR GD: Set the path to libpng install prefix | |
--with-libxml-dir=DIR SimpleXML: libxml2 install prefix | |
--enable-sockets Enable sockets support | |
--disable-xml Disable XML support (不写时默认 --enable-xml)【连接数据库:】--with-mysql=DIR Include MySQL support. DIR is the MySQL base | |
directory, if no DIR is passed or the value is | |
mysqlnd the MySQL native driver will be used | |
--with-mysqli=FILE Include MySQLi support. FILE is the path | |
to mysql_config. If no value or mysqlnd is passed | |
as FILE, the MySQL native driver will be used | |
--with-pdo-mysql=DIR PDO: MySQL support. DIR is the MySQL base directory | |
If no value or mysqlnd is passed as DIR, the | |
MySQL native driver will be used | |
--enable-mysqlnd Enable mysqlnd explicitly, will be done implicitly | |
when required by other extensions【Zend:】--enable-maintainer-zts Enable thread safety - for code maintainers only!! |
部分选项说明:
- 在【zend】扩展部分的选项 ”–enable-maintainer-zts” 是为了让 php 支持多线程 MPM 的,即 php 以模块化方式或 cgi 模式安装时且 httpd 配置为 worker 或 event 时需要启用该项。而如果 php 以 fastcgi 模式安装时,由于 php 有独立的服务和进程,所以该项是多余的。
- “–with-apxs2″ 是让 php 以模块化的方式安装到其他程序中,”–enable-fpm” 是让 php 以 fastcgi 模式工作的选项。所以此处采用后者,而以模块方式和 httpd 交互时采用前者。
- “–with-config-file-path” 和 ”–with-config-file-scan-dir” 分别是 php 配置文件 php.ini 的存放位置以及其他加载的配置文件路径,scan-dir 类的目录就像 /etc/profile.d、/etc/httpd/conf.d 这样的目录路径。
- “–with-openssl” 选项让 php 支持 ssl;”–enable-mbstring” 选项是让 php 支持多字节字符的,例如中文一个字符两个字节,也就是说让 php 支持国际化的;”–with-zlib”、”–with-bz2″、”–with-mhash” 和 ”–with-mcrypt” 选项让 php 支持这些压缩和加密机制。
- “–with-freetype-dir”、”–with-jpeg-dir” 和 ”–with-png-dir” 分别是让 php 支持多种文字样式、支持 jpeg、支持 png 的选项。
- php 连接 mysql 有两种方式,一种是以 libmysql 的驱动方式连接 mysql,一种是以 mysqlnd 方式驱动连接 mysql。以下列出了 libmysql 和 mysqlnd 这两种驱动方式的编译模式。
- (1). 以 libmysql 驱动方式连接 mysql(Mariadb),需要提前安装 mysql(Mariadb)和 mysql-devel(mariadb-devel),并使用 ”–with-mysql” 选项指定 mysql 安装路径,”–with-mysqli” 选项指定 mysql_config 脚本的路径,”–with-pdo-mysql” 选项也指定 mysql 安装路径。假如 mysql 安装在 /usr/local/mysql 下。
./configure --prefix=/usr/local/php \ --with-mysql=/usr/local/mysql \ --with-mysqli=/usr/local/mysql/bin/mysql_config - (2). 以 mysqlnd 驱动方式连接 mysql,不需要提前安装 mysql 和 mysql-devel,–with-mysql、–with-mysqli 和 –with-pdo-mysql 选项都不需要指定具体路径,只需使用 mysqlnd 作为这些选项的值即可。
./configure --prefix=/usr/local/php \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd 在 php 5.3 的时候已经支持 mysqlnd 驱动方式了,在 php 5.4 的时候 mysqlnd 已经是默认的配置选项了。建议使用 mysqlnd 的驱动方式。
- (1). 以 libmysql 驱动方式连接 mysql(Mariadb),需要提前安装 mysql(Mariadb)和 mysql-devel(mariadb-devel),并使用 ”–with-mysql” 选项指定 mysql 安装路径,”–with-mysqli” 选项指定 mysql_config 脚本的路径,”–with-pdo-mysql” 选项也指定 mysql 安装路径。假如 mysql 安装在 /usr/local/mysql 下。
2.2 php 编译过程
由于是配置 fastcgi 的模式,所以在 ./configure
的时候将 apxs2 功能换为 ”–enable-fpm”,并且由于此模式下的 php 由自己独立的服务来控制进程的生成,所以对于为了支持 httpd 线程的选项 ”–enable-maintainer-zts” 也去掉。以下是编译安装过程:
yum install -y bzip2-level libmcrypt-devel openssl-devel libxml2-devel | |
tar xf php-5.5.38.tar.bz2 -C /tmp | |
cd /tmp/php-5.5.38 | |
./configure --prefix=/usr/local/php --with-openssl --enable-mbstring --enable-sockets --with-freetype-dir --with-jpeg-dir --with-png-dir --with-libxml-dir=/usr --enable-xml --with-zlib --with-mcrypt --with-bz2 --with-mhash --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm | |
make | |
make install |
cp php.ini-production /etc/php.ini | |
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmd | |
chmod +x /etc/init.d/phpfpmd | |
cd /usr/local/php/ | |
cp etc/php-fpm.conf.default etc/php-fpm.conf | |
vim etc/php-fpm.conf | |
pm.max_children = 50 | |
pm.start_servers = 5 | |
pm.min_spare_servers = 2 | |
pm.max_spare_servers = 8 | |
service php-fpmd start |
2.3 配置 httpd 使其转发动态请求给 php-fpm
# 启用 fcgi 的支持模块。 | |
LoadModule proxy_module modules/mod_proxy.so | |
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so | |
# 添加 php 后缀格式文件的识别功能。 | |
AddType application/x-httpd-php .php | |
AddType application/x-httpd-php-source .phps | |
# 添加 php 后缀的主页 | |
DirectoryIndex index.php index.html | |
# 启用虚拟主机模块,Include 虚拟主机配置文件,并注释中心主机 DocumentRoot。 | |
#DocumentRoot "/usr/local/apache/htdocs" | |
Include /etc/apache/extra/httpd-vhosts.conf | |
# 配置虚拟主机。注意主机中需要添加下面两行,第一行表示关闭正向代理功能,第二行表示反向代理时进行正则匹配。 | |
# 对主机的.php(不区分大小写)文件的访问都通过 fcgi 协议交给 php,由于此处测试,php 正好和 httpd 在同一服务器上,# 且 php-fpm 默认监听的端口为 9000,所以为 fcgi://127.0.0.1:9000,在此之后还需要写上 /DocumentRoot/$1, | |
# "$1" 是正则的反向引用 | |
ProxyRequests off | |
ProxyPassMatch "(?i)^/(.*\.php)$" fcgi://127.0.0.1:9000/var/www/a.com/$1 |
提供主页测试文件 index.php。
mkdir -p /var/www/a.com | |
vim /var/www/a.com/index.php | |
<h1>a.com</h1> | |
phpinfo(); | |
重启 httpd,浏览器中进行站点访问测试。
3. 为 php 安装 xcache
php 是一种解释型语言,意味着 php 脚本在执行时不需要事先编译,而是像 shell 脚本一样直接执行。但事实上它还是会编译的,只不过是执行时 ” 偷偷地 ” 编译,它会将代码编译成字节码 (opcode) 然后运行。编译是一个很消耗时间的操作,因此需要为编译好的 opcode 提供缓存以提高性能,降低负载。目前最流行的 opcode 缓存工具是 XCache,它是一个开源的工具。
下载路径:http://xcache.lighttpd.net/pub/Releases/
3.1 基本安装
安装 xcache。
tar xf xcache-3.2.0.tar.bz2 -C /tmp | |
cd /tmp/xcache-3.2.0/ | |
# 添加扩展前,先运行 phpize | |
/usr/local/php/bin/phpize | |
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-cofig | |
make && make install |
在安装完成之后有一行,这一行很重要,因为这个路径要添加到配置文件中。
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20121212/
在解压 xcache 的目录下,有 xcache 的配置文件 xcache.ini,将其追加到 php 的配置文件中,或者将其复制到 php 的配置文件扫描目录 /etc/php.d 下 (该目录是之前编译 php 时./configure
配置选项 ”–with-config-file-scan-dir” 指定的项)。
mkdir /etc/php.d | |
cp xcache.ini /etc/php.d/ | |
vim /etc/php.d/xcache.ini |
在该文件中加上一行,该行必须在该文件中的所有 extension 指令的最前面。
zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20121212/xcache.so
其实对于 xcache 3.0 版本和以后版本,可以不用复制 xcache 模块的路径到配置文件中,因为可以自动找到 php 路径下的模块路径,甚至添加了可能还会出错。
3.2 设置管理员后台
设置了管理员后台,管理员可以查看 xcache 相关的信息和加速的情况。做法很简单。修改配置文件中的 xcache.admin.user 和 xcache.admin.pass 两项,分别为管理员账号和密码。注意该密码只能是 md5 加密的密码。
例如,user 设置为 Admin,密码为 ”123456″:
[ | ]|
e10adc3949ba59abbe56e057f20f883e - | |
[ | ]|
xcache.admin.user = "Admin" | |
xcache.admin.pass = "e10adc3949ba59abbe56e057f20f883e" |
保存退出。复制 xcache 解压路径下的 htdocs 目录 (有些版本的 xcache 是 admin 目录) 到 httpd 的 DocumentRoot 下。
cp -a htdocs /usr/local/apache/htdocs/
然后重启 httpd,在浏览器中输入http://IP/htdocs
,会弹出 xcache 的管理员验证,输入用户名 Admin 和密码 123456,即可查看管理员页面。
4. 安装 MySQL(MariaDB)
此处以 MySQL 通用二进制包安装为例,它相当于 windows 中的便携版软件,解压后稍微配置下进行初始化就可以直接使用,不用安装。其他方法、安装细节、多实例以及 MariaDB 等见mysql & mariadb 安装细节。
mysql 通用二进制版官方下载地址:
MySQL 5.6 通用二进制包下载: https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35-linux-glibc2.12-x86_64.tar.gz
MySQL 5.7 通用二进制包下载: https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.12-x86_64.tar.gz
其中文件中的 glibc2.12 表示的是 Linux 系统的 glibc 版本要比 2.12 新,可以使用 ldd –version 查看 glibc 版本。在 CentOS 6 上 glibc 默认就是 2.12 的,所以无需顾虑。
tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ | |
ln -s /usr/local/mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql |
4.1 初始化实例
初始化前先进行一些配置。
mkdir -p /mydata/data # 作为数据目录 datadir | |
useradd -r -s /sbin/nologin mysql | |
chown -R mysql.mysql /usr/local/mysql | |
chown -R mysql.mysql /mydata/data | |
cd /usr/local/mysql | |
scripts/mysql_install_db --datadir=/mydata/data --user=mysql | |
chown -R root.root /usr/local/mysql |
执行 mysql_install_db 初始化时会在 /tmp 下创建临时表,所以 mysql 用户需要对 /tmp 有写权限,否则执行实例初始化脚本时可能会报类似下面的错误:
ERROR: 1 Can’t create/write to file ‘/tmp/#sql_7a0e_0.MYI’ (Errcode: 13)
这说明没有写权限,所以需要修改 /tmp 目录的权限:
chmod 1777 /tmp
也可以使用下面的方法初始化,事实上 mysql_install_db
已经作为废弃的工具,在执行时很可能会提示该工具已废弃。
bin/mysqld --initialize-insecure --datadir=/mydata/data --user=mysql
初始化完成后,提供配置文件和服务启动脚本。
shell> cp -a support-files/mysql.server /etc/init.d/mysqld | |
shell> cp -a support-files/my-default.cnf /etc/my.cnf | |
shell> vim /etc/my.cnf | |
[ | ]|
datadir=/mydata/data |
如果是 centos7,则提供如下服务启动脚本(如有必要,修改 pid 文件路径)。
shell> cat /usr/lib/systemd/system/mysqld.service | |
[Unit] | |
Description=MySQL Server | |
Documentation=man:mysqld(8) | |
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html | |
After=network.target | |
After=syslog.target | |
[Install] | |
WantedBy=multi-user.target | |
[Service] | |
User=mysql | |
Group=mysql | |
Type=forking | |
PIDFile=/var/run/mysqld/mysqld.pid | |
# Disable service start and stop timeout logic of systemd for mysqld service. | |
TimeoutSec=0 | |
# Start main service | |
ExecStart=/usr/local/mysql-5.7.19/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS | |
# Use this to switch malloc implementation | |
EnvironmentFile=-/etc/sysconfig/mysql | |
# Sets open_files_limit | |
LimitNOFILE = 5000 | |
Restart=on-failure | |
RestartPreventExitStatus=1 | |
PrivateTmp=false |
修改 ”root@localhost” 密码。
mysql | |
alter user 'root'@'localhost' identified by '123456'; | |
\q |
4.2 安装后的规范化操作
编译安装或通用二进制安装后,一般都需要做一些额外的操作,包括设置环境变量、输出头文件和库文件、设置 man 路径。
echo "export PATH=/usr/local/mysql/bin:$PATH" >/etc/profile.d/mysql.sh | |
chmod +x /etc/profile.d/mysql.sh | |
source /etc/profile.d/mysql.sh | |
echo "MANPATH /usr/local/mysql/man" >>/etc/man.config | |
echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf | |
ldconfig | |
ln -s /usr/local/mysql/include /usr/include/mysql |
5. 测试 LAMP——搭建 discuz 论坛
discuz 是论坛软件系统,基于 php+MySQL 平台。基本配置很简单,更多的配置和个性化定制在官方主页查看教程。
官方主页:http://www.discuz.net/forum.php
discuz 下载地址:http://www.discuz.net/thread-3570835-1-1.html
简单布置它们的过程很简单,只需复制相关文件到对应的网站根目录下,然后在浏览器中输入对应的目录名即可打开程序。中间测试过程中如果出现问题,再对应修改即可。
首先配置 httpd,提供一个虚拟主机。
# 包含虚拟主机的配置文件,只需取消下面这行的注释符号 "#" 即可 | |
#Include /etc/apache/extra/httpd-vhosts.conf | |
# 提供虚拟主机 | |
vim /etc/apache/extra/httpd-vhosts.conf | |
<VirtualHost 192.168.100.61:80> | |
DocumentRoot "/var/www/a.com/" | |
ServerName www.a.com | |
ErrorLog "logs/error_log" | |
CustomLog "logs/access_log" combined | |
<Directory "/var/www/a.com/"> | |
Options None | |
AllowOverride None | |
Require all granted | |
</Directory> | |
</VirtualHost> |
将解压后 discuz 中的 upload 目录复制到对应虚拟主机的 DocumentRoot 目录下。
cd Discuz | |
cp -a upload/ /var/www/a.com |
重启 httpd 服务。测试 discuz。不过得先在客户端的 hosts 文件中添加解析记录,例如此处为:
192.168.100.61 www.a.com。
在浏览器中输入 http://www.a.com/upload
即可。
然后在安装前会自动检查是否符合安装条件。将以下所有不符合条件的全部修改成符合条件。
cd /var/www/a.com/upload | |
touch config/config_{global,ucenter}.php | |
chmod a+w config/config_{global,ucenter}.php | |
chmod a+w data config data/{cache,avatar,plugindata,download,addonmd5,template,threadcache,attachment,log} data/attachment/{album,forum,group} | |
chmod a+w uc_client/data/cache | |
chmod a+w uc_server/data uc_server/data/{cache,avatar,backup,logs,tmp,view} |
刷新下,条件满足。
卸载的方法是删除 upload 目录,删除 mysql 中的 discuz 数据库。
如果乱码,则修改 httpd 的配置文件中的 AddDefaultCharset 指令。如:
AddDefaultCharset UTF-8
以上为 LAMP 相关的内容,布置过程稍显死板,作为实验示例,这也是没办法的事情。熟悉相关知识点之后,很容易就明白该如何搭建。
下面关于 LAMP 相关 的内容你可能也喜欢:
LAMP 平台安装 Xcache 和 Memcached 加速网站运行 http://www.linuxidc.com/Linux/2015-06/118835.htm
CentOS 7 下搭建 LAMP 平台环境 http://www.linuxidc.com/Linux/2015-06/118818.htm
CentOS 7.3 下配置 LAMP 实现 WordPress http://www.linuxidc.com/Linux/2017-07/145947.htm
Ubuntu 14.04 配置 LAMP+phpMyAdmin PHP(5.5.9)开发环境 http://www.linuxidc.com/Linux/2014-10/107924.htm
LAMP 结合 NFS 构建小型博客站点 http://www.linuxidc.com/Linux/2015-08/121029.htm
CentOS7 下安装部署 LAMP 环境 http://www.linuxidc.com/Linux/2016-04/130653.htm
CentOS 7 上安装(LAMP)服务 Linux,Apache,MySQL,PHP http://www.linuxidc.com/Linux/2017-05/143868.htm
Ubuntu Server 14.04 LTS 下搭建 LAMP 环境图文详解 http://www.linuxidc.com/Linux/2016-12/138758.htm
Ubuntu Server 16.04 下配置 LAMP 环境 http://www.linuxidc.com/Linux/2016-12/138757.htm
在 Ubuntu 17.04 上安装搭建 LAMP 组件环境 http://www.linuxidc.com/Linux/2017-07/145644.htm
CentOS 6.7 编译安装 LAMP 详解 http://www.linuxidc.com/Linux/2017-03/141244.htm
Ubuntu 16.04 搭建 LAMP 开发环境 http://www.linuxidc.com/Linux/2016-10/136327.htm
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-10/147401.htm
