LAMP平台部署与应用-创新互联
LAMP平台部署与应用
一 安装Apache服务
1 删除rpm方式安装的httpd
rpm -e httpd --nodeps
2 安装支持的软件包
yum -y install apr apr-devel cyrus-sasl-devel expat-devel libdb-devel openldap-devel apr-util-devel apr-util pcre-devel pcre
结果如图:
3 源码编译及安装
上传 rz httpd……
解压 tar zxf httpd…… -C /usr/src
cd /usr/src/httpd……
配置及编译安装
./configure --prefix=/usr/local/httpd –enable-so –enable-rewrite –enable-charset-lite –enable-cgi && make && make install
添加系统服务
vim /lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/httpd/logs/httpd.pid
ExecStart=/usr/local/bin/apachectl $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=graphical.target
4 启动系统服务
systemctl start(stop) httpd
systemctl enable httpd 开机自启
若出现:Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
查看配置文件,保证无错的情况下,做优化连接
ln -s /usr/local/httpd/bin/* /usr/local/bin/
结果如图:
Vim /usr/local/httpd/conf/httpd.conf
二 安装启动MySQL
1 yum –y install ncurses-devel
2 安装cmake编译安装包
Rz 上传
Tar zxf cmake..
Cd cmake…
./configure && gmake && gmake install
3 源码编译及安装
创建组用户 groupadd mysql
创建用户 useradd –M –s /sbin/nologin mysql –g mysql
解压 tar zxf mysql… -C /usr/src
配置 cd /usr/src/mysql….
cmake –DCMAKE_INSTALL_PREFIX=/usr/local/mysql –DSYSCONFDIR=/etc –DDEFAULT_CHARSET=utf8 –DDEFAULT_COLLATION=utf8_general_ci –DWITH_EXTRA_CHARSETS=all
编译安装 make && make install
4 安装后的调整
权限设置 chown –R mysql:mysql /usr/local/mysql
建立配置文件:
CentOS 7 默认支持MariaDB数据库,系统默认的/etc/my.cnf为MariaDB的配置
文件因此需要将原本的文件替换为MySQL的
Rm –rf /etc/my.cnf
Cp support-files/my-default.cnf /etc/my.cnf
初始化数据库
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
设置变量环境
Echo “PATH=$PATH:/usr/local/mysql/bin” >> /etc/profile
./etc/profile 生效
若出现FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
Data::Dumper
解决方法:yum –y install autoconf
5 添加系统服务
Cp support-files/mysql.server /usr/local/mysql/bin/mysql.sh
Chmod +x /usr/local/mysql/bin/mysql.sh
方法一:ln -s /usr/local/mysql/bin/* /usr/local/bin/ 用mysql.sh start 启用
方法二:vim /usr/lib/systemd/system/mysqld.service
重新加载:systemctl daemon-reload 重启
systemctl stop(start) mysqld
三 构建PHP运行环境
1.查看并卸载rpm包PHP
rpm -e php php-cli php-ldap php-common php-mysql --nodeps
2.安装mcrypt加密工具
前提:yum -y install zlib-devel xz-devel libxml2-devel
(1)解压
Libmcrypt mhash mcrypt (可以从http://sourceforge.net下载)
(2)cd /usr/src/libmcypt...
./configure && make && make install
ln -s /usr/local/lib/libmcrypt. /usr/lib
(3)cd /usr/src/mhash...
./configure && make && make install
ln -s /usr/local/lib/libmhash /usr/lib
(4)cd /usr/src/mcrypt...
./configure && make && make install
若报错(configure: error: *** libmcrypt was not found),
则export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH后重新配置安装
3.编译安装PHP
(1)解压: tar zxf php-5... -C /usr/src
(2)编译安装
cd /usr/src/php-5...
./configure --prefix=/usr/local/php5 --with-mcrypt --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php5 --enable-mbstring && make && make install
4.设置LAMP组建环境
(1)php.ini配置调整
安装好PHP软件包后,服务器并不会自动创建php.ini的配置文件,但在源码包目录下提供两个样例
php.ini-development 开发版
php.ini-production 生产版
cp /usr/src/php…/php.ini-development /usr/local/php5/php.ini
vim /usr/local/php5/php.ini
default_charset = "utf-8"
short_open_tag = on
extension=php_mysqli.dll
(2)添加ZendGuardLoader优化模块(http://www.zend.com)
tar zxf zend... -C /usr/src
cd /usr/src/zend...
cp Zend... /usr/local/php5/lib/php
vim /usr/loca/php5/php.ini
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1
(3)httpd.conf配置调整
vim /usr/local/httpd/conf/httpd.conf
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php
/usr/local/httpd/bin/apachectl restart
(4)测试
①测试PHP网页能否正确显示
vim /usr/local/httpd/htdocs/test1.php
phpinfo();
?>
结果:
②测试PHP网页能否访问MySQL数据库
vim /usr/local/httpd/htdocs/test2.php
结果:
5.安装phpMyadmin(官方地址:http://www.phpadmin.net)
(1)解压
(2)mv phpMyadmin... /usr/local/httpd/htdocs/phpmyadmin
(3)cd /usr/local/httpd/htdocs/phpmyadmin
cp config.sample.inc.php config.inc.php
(4)访问测试
mysqladmin -u root -p password ‘123456’
结果:
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章题目:LAMP平台部署与应用-创新互联
标题来源:http://cdiso.cn/article/hscdp.html