長期更新各種好文,建議關注收藏!
本文近期更新完畢。
LNMP=linux+nginx+mysql+php
- 需要的資源
linux服務器
web服務軟件nginx
對應的語言編譯器+代碼文件
數據庫mysql - 安裝
tar.gz包或者命令行安裝
進入root: sodu 或su
mkdir path/{server,soft} -p
#{}表示幾個文件夾
#-p: create parent directories as needed. If path/ doesn’t exist, it will create it. mv path/* newpath #*表示所有文件
nginx
nginx提供web服務訪問
安裝nginx之前需要創建專用的啟動用戶,某個軟件如果有root權限比較危險
useradd bootuser -s /sbin/nologin -M
tar xzf nginx-version.tar.gz
cd nginx-version
./configure --perfix=/data/server/nginx
make#編譯
make install#安裝
gedit /data/server/nginx/conf/nginx.conf#修改配置文件
##user nobody;找到這句 改為user bootuser取消注釋/data/server/nginx/sbin/nginx#運行nginx 這個sbin里的nginx是可執行文件
- ./configure --perfix=/data/server/nginx
執行可執行程序configure
安裝到perfix指定目錄下
設置完之后 外網訪問服務器的ip地址,以及本服務器電腦訪問localhost都應該能出現nginx默認網頁
netstat -tnulp | grep nginx #查看是否啟動服務
/data/server/nginx/sbin/nginx -s stop#關閉服務
/data/server/nginx/sbin/nginx -s reload#重啟服務
mysql
mysql安裝完具備2個軟件,客戶端(/data/server/mysql/bin/mysql啟動 exit退出 )、服務端
useradd -s /sbin/nologin -M mysqlln -s mysql-version-folder mysql #軟連接/data/server/mysql/scripts/mysql_intall_db --basedir=/data/server/mysql --datadir=/data/ --datadir=/data/server/mysql/data/ --user=mysql
#安裝#配置文件管理
mv /etc/my.cnf /etc/my.cnf-bak #更換名稱
cp /data/server/mysql/support-files/my-default.cnf /etc/my.cnf#啟動命令配置
cp /data/server/mysql/support-files/mysql.server /etc/init.d/mysqld#修改啟動文件 's替換 #content1 #content2 # g所有東西找到做修改' content1替換為content2
sed -i 's#/usr/local/mysql#/data/server/mysql#g' /data/server/mysql/bin/mysqld_safe /etc/init.d/mysqld#數據庫權限設置
chown -R mysql.mysql /data/server/mysql/#設置開機自啟動
chkconfig --add mysqld
chkconfig mysqld on#啟動/停止/重啟服務端
service mysqld start/stop/restartnetstat -tnulp | grep mysqld #查看是否啟動服務#配置環境變量
gedit /etc/profile
#末尾添加這條配置 輸入的命令都在這個PATH里挨個找
PATH=/data/server/mysql/bin:$PATH
#配置文件生效
source /etc/profile
#連接服務端 沒有密碼
mysql -uroot -p
php
依賴軟件 libiconv
cd /data/soft
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --perfix=/usr/local/libiconv
make
make installcd /data/soft/
tar xzf php-5.3.29.tar.gz
cd php-5.3.29#配置
ln -s /data/server/mysql/lib/libmysqlclient.so.18 /usr/lib64
touch ext/phar/phar.phar
./configure \
--perfix=/data/server/php-5.3.29 \
--with-mysql=/data/server/mysql \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftpmake
make install#php文件配置
cd /data/server
ln -s php-version php
#修改php.ini 開啟session
cp /data/soft/php-version/php.ini-production /data/server/php/lib/php.ini
gedit /data/server/php/lib/php.ini #啟動記事本#找到下面內容
;session.save_path ="/tmp
#改為 刪掉分號
session.save_path ="/tmp#復制php-fpm配置文件,默認沒有該文件但有備份文件
cp /data/server/php/etc/php-fpm.conf.default /data/server/php/etc/php-fpm.conf#啟動
/data/server/php/sbin/php-fpm
#關閉
pkill php-fpm
netstat -tnulp | grep php #查看是否啟動服務#nginx整合php
#修改nginx配置文件
cp /data/server/nginx/conf/nginx.conf /data/server/nginx/conf/nginx.conf-bak
gedit /data/server/nginx/conf/nginx.conf
#把server內容替換成
server{listen 80;server_name localhost;#靜態請求處理locationlocation / {root html;index index.php index.html index.htm;}#動態請求處理locationlocation ~* .*\.(php|php5)?${root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fastcgi.conf;}
}
/data/server/nginx/sbin/nginx -t
#重啟nginx
/data/server/nginx/sbin/nginx -s reload#編寫簡單的php程序
echo "<?php echo '<p>hello world</p>'; ?" > /data/server/nginx/html/test.php#url: 127.0.0.1/test.php 可以看到
部署網站
上述服務都啟動后。
cd /data/soft/
unzip code.zip #項目代碼
mv /data/soft/code /data/server/nginx/html
#修改權限
chown -R www.www /data/server/nginx/html/code
#url:localhost/code
部署禪道
cd /data/soft/
unzip zentao.zip #項目代碼
mv /data/soft/zentao/zentaopms/ /data/server/nginx/html/chandao
#修改權限
chown -R www.www /data/server/nginx/html/chandao
#url:localhost/chandao/www
Navicat設置
本機管理哪些能連本服務器,
打開navicat->mysql數據庫->表user 顯示哪些人可以連接
::1表示ip末尾是1的可以連接
修改其中一條為%表示都可以連接
改完后新建查詢,輸入下面執行,運行