需求:內部人員經常到查閱資料,考慮在內網搭建wiki站點。
實驗拓撲:
實驗環境:
Nginx,PHP:192.168.198.160,10.0.0.07
MySQL:10.0.0.8
軟件包:
HDWiki-v5.1UTF8-20141205.zip
nginx-1.8.0.tar.gz
xcache-3.2.0.tar.gz
mysql-5.5.46-linux2.6-x86_64.tar.gz
php-5.3.27.tar.bz2
1、安裝Nginx
1.1準備
ntpdate 202.120.2.101 yum install pcre-devel -y #解決依賴關系 useradd -r -s /sbin/nologin nginx #添加Nginx用戶和組
1.2編譯安裝
cd /tools tar -xf nginx-1.8.0.tar.gz cd nginx-1.8.0 ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module make && make install
1.3 提供配置文件 (這一步在編譯PHP的時候進行,節約時間)
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name wiki.edelweiss0.com; location / { root html/wiki; index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root html/wiki; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } } }
2、安裝PHP
2.1解決依賴關系
yum install zlib libxml libjpeg freetype libpng gd curl zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel openssl-devel libxslt-devel -y
wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz tar zxf libiconv-1.14.tar.gz cd libiconv-1.14 ./configure --prefix=/usr/local/libiconv make make install #如果有依賴關系報錯,自行百度,安裝相應的軟件包即可
2.2編譯安裝
tar -xf php-5.3.27.tar.bz2 cd php-5.3.27 ./configure \ --prefix=/usr/local/php \ --enable-fpm \ --with-mysql=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-xmlrpc \ --with-openssl \ --with-zlib \ --with-freetype-dir \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-iconv=/usr/local/libiconv \ --enable-short-tags \ --enable-sockets \ --enable-soap \ --enable-mbstring \ --enable-static \ --enable-gd-native-ttf \ --with-curl \ --with-xsl \ --enable-ftp \ --with-libxml-dir \ --with-fpm-user=nginx \ --with-fpm-group=nginx \ --with-config-file-path=/etc \ --with-config-file-scan-dir=/etc/php.d #這是某運維老鳥說的他企業里都是這么配置的,不需要更改??勺孕兴阉?/pre>make && make install #這里需要等待一段時間了,可以同時進行第三步操作2.3為php提供配置文件,以fastcgi方式監聽在9000端口
cp php.ini-production /etc/php.ini #為php提供配置文件 cd /usr/local/php/ cp etc/php-fpm.conf.default etc/php-fpm.conf #如果要實現php和web服務分離可以編輯此文件,這里保持默認2.4安裝與配置xcache加速器
tar -xf xcache-3.2.0.tar.gz cd xcache-3.2.0 /usr/local/php/bin/phpize #注意這里要先解壓xcache在運行此命令 ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config make && make install #注意輸出的最后信息Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/mkdir /etc/php.d #提供xcache擴展配置文件 cp xcache.ini /etc/php.d/ vim /etc/php.d/xcache.ini [root@edeiweiss0 xcache-3.2.0]# diff xcache.ini /etc/php.d/xcache.ini 4c4 < extension = xcache.so --- > extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so3、安裝MySQL(在另一臺機器)
3.1準備
mkdir /data cd /usr/local/src/ #mysql-5.5.46-linux2.6-x86_64.tar.gz tar -xf mysql-5.5.46-linux2.6-x86_64.tar.gz -C /usr/local ln -sv /usr/local/mysql-5.5.46-linux2.6-x86_64/ /usr/local/mysql groupadd mysql useradd -g mysql mysql cd /usr/local/mysql3.2初始化數據庫
chown -R mysql.mysql . scripts/mysql_install_db --user=mysql --datadir=/data/ --basedir=/usr/local/mysql #一般出現兩個OK代表安裝正常3.3提供配置文件和服務腳本
cp support-files/my-medium.cnf /etc/my.cnf cp: overwrite `/etc/my.cnf'? y vim /etc/my.cnf[root@node1 mysql]# diff /etc/my.cnf support-files/my-medium.cnf 38,39c38 < datadir=/data < log-error=/data/mysql-err --- >cp support-files/mysql.server /etc/init.d/mysqld service mysqld start [root@node1 mysql]# ss -tnl | grep 330 LISTEN 0 50 *:3306 *:* echo "PATH=/usr/local/mysql/bin:/$PATH" > /etc/profile.d/mysql.sh source /etc/profile.d/mysql.sh3.4為站點提供數據庫和用戶
mysql> drop database test; #刪除無用的數據庫 Query OK, 0 rows affected (0.06 sec) mysql> delete from mysql.user where user=''; #刪除無用的用戶 Query OK, 2 rows affected (0.10 sec) mysql> create database wiki; #創建wiki數據庫 Query OK, 1 row affected (0.00 sec) mysql> grant all on wiki.* to 'wiki'@'10.0.0.%' identified by '123456'; #創建并授權wiki數據的用戶 Query OK, 0 rows affected (0.05 sec) mysql> flush privileges; #刷新權限 Query OK, 0 rows affected (0.00 sec)4、整合Nginx,PHP,MySQL
sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful sbin/nginx /usr/local/php/sbin/php-fpm4.1測試Nginx和PHP
mkdir html/wiki vim html/wiki/index.php <?php phpinfo(); ?>
![]()
4.2測試PHP和MySQL
#注意防火墻的配置 vim /usr/local/nginx/html/wiki/index.php <?php $link_id=mysql_connect('192.168.198.130','wiki','123456') or mysql_error(); if($link_id){ echo "mysql successful by yunzhonghe !"; }else{ echo mysql_error(); } ?>
4.3建站
cd /tools/ unzip HDWiki-v5.1UTF8-20141205.zip mv HDWiki-v5.1UTF8-20121102/* /usr/local/nginx/html/wiki/ chown nginx.nginx -R /usr/local/nginx/
#結果展示
到時候可以自行擴展
5、總結:希望大家有所收獲。
原創文章,作者:艾賀,如若轉載,請注明出處:http://www.www58058.com/8712