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 && make && make 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 生效
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
<?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’
結果:
LAMP平臺部署與應用