這篇文章給大家介紹CentOS 7中怎么搭建LNMP環(huán)境,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
創(chuàng)新互聯(lián)公司主要從事成都做網(wǎng)站、網(wǎng)站建設(shè)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)南和,10多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):18982081108
yum install -y epel-release
yum install -y gcc automake autoconf libtool make gcc-c++ glibc libxslt-devel \ libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 \ libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 \ bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \ krb5-devel libidn libidn-devel openssl openssl-devel pcre pcre-devel libmcrypt \ libmcrypt-devel cmake
cat > /usr/local/src/url << "EOF" http://nginx.org/download/nginx-1.14.2.tar.gz http://jp2.php.net/distributions/php-5.6.39.tar.gz https://cdn.MySQL.com//Downloads/MySQL-5.7/mysql-boost-5.7.25.tar.gz EOF
wget -P /usr/local/src -i /usr/local/src/url
cd /usr/local/src for i in *.tar.gz ; do tar zxvf $i; done
安裝依賴包
yum install -y gcc gcc-c++ cmake ncurses ncurses-devel bison
mysql5.7 編譯安裝需要boost 庫(kù),這里官網(wǎng)下載含boost的源碼包
添加用戶
useradd -s /sbin/nologin mysql
建立所需目錄并更改所有者為mysql
mkdir -p /data/mysql/data chown -R mysql:mysql /data/mysql
將下載好的mysql 解壓到/usr/local/mysql 目錄下
mv /usr/local/src/mysql-boost-5.7.25 /usr/local/mysql
切換到/usr/local/mysql-5.7.25 目錄下,編譯安裝
cmake -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
make && make install
安裝好后的/usr/local/mysql目錄結(jié)構(gòu)
配置
編輯/etc/my.cnf ( 如果沒(méi)有則創(chuàng)建)
我這邊的一個(gè)配置文件內(nèi)容如下
[client] port = 3306 socket = /tmp/mysql.sock [mysqld] port = 3306 socket = /tmp/mysql.sock user = mysql basedir = /usr/local/mysql datadir = /data/mysql/data pid-file = /data/mysql/mysql.pid log_error = /data/mysql/mysql-error.log slow_query_log = 1 long_query_time = 1 slow_query_log_file = /data/mysql/mysql-slow.log skip-external-locking key_buffer_size = 32M max_allowed_packet = 1024M table_open_cache = 128 sort_buffer_size = 768K net_buffer_length = 8K read_buffer_size = 768K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M thread_cache_size = 16 query_cache_size = 16M tmp_table_size = 32M performance_schema_max_table_instances = 1000 explicit_defaults_for_timestamp = true #skip-networking max_connections = 500 max_connect_errors = 100 open_files_limit = 65535 log_bin=mysql-bin binlog_format=mixed server_id = 232 expire_logs_days = 10 early-plugin-load = "" default_storage_engine = InnoDB innodb_file_per_table = 1 innodb_buffer_pool_size = 128M innodb_log_file_size = 32M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 32M sort_buffer_size = 768K read_buffer = 2M write_buffer = 2M
以上配置內(nèi)容非必須,可依據(jù)實(shí)際情況,做相應(yīng)的調(diào)整!
把安裝目錄用戶和組更改為mysql
chown -R mysql:mysql /usr/local/mysql
把數(shù)據(jù)庫(kù)數(shù)據(jù)目錄用戶和組更改為mysql ( 數(shù)據(jù)庫(kù)數(shù)據(jù)目錄:/data/mysql/data),方法同上!
注:/data/mysql/data目錄下一定要為空才行
初始化mysql
./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
注:到這一步很容易出問(wèn)題,在初始化的時(shí)候一定要加上面的參數(shù),而且在執(zhí)行這一步操作前/data/mysql/data 這個(gè)目錄必須是空的;在這里指定的basedir 和 datadir 目錄必須要和/etc/my.cnf 配置的目錄一直才行。
拷貝可執(zhí)行配置文件
cp mysql.server /etc/init.d/mysqld
注:有些網(wǎng)友文章在這一步中會(huì)寫到從/usr/local/mysql/support-files 這個(gè)目錄復(fù)制my-default.cnf 到/etc/下作為my.cnf 配置文件,我這里沒(méi)有這個(gè)文件,所以直接在配置環(huán)節(jié),自己配置了一個(gè)my.cnf文件。
啟動(dòng)
service mysqld start
注:這一步也是很容易出問(wèn)題的地方,當(dāng)這里出現(xiàn)問(wèn)題的時(shí)候,不要慌,看mysql 錯(cuò)誤日志的內(nèi)容,一般根據(jù)mysql 錯(cuò)誤日志的提示都能很好的解決問(wèn)題。
測(cè)試連接
./mysql -hlocalhost -uroot -p
無(wú)需密碼即可連接成功
修改環(huán)境變量
在/etc/profile 中新增一行
PATH=/usr/local/mysql/bin:$PATH
保存退出
source /etc/profile
設(shè)置開(kāi)機(jī)自啟動(dòng)
systemctl enable mysqld
登錄MySql并修改root密碼
#mysql -uroot -p mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new psd';
4,安裝PHP; 創(chuàng)建php賬戶進(jìn)入目錄
useradd -s /sbin/nologin php-fpm cd /usr/local/src/php-5.6.39
./configure \ --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --enable-fpm \ --with-fpm-user=php-fpm \ --with-fpm-group=php-fpm \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-libxml-dir \ --enable-pcntl \ --enable-mysqlnd \ --enable-opcache \ --enable-sockets \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-shmop \ --enable-zip \ --enable-soap \ --enable-xml \ --enable-mbstring \ --disable-rpath \ --disable-debug \ --disable-fileinfo \ --with-pcre-regex \ --with-iconv \ --with-zlib \ --with-mcrypt \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --enable-gd-native-ttf \ --with-freetype-dir \ --with-openssl \ --with-mhash \ --with-xmlrpc \ --with-curl \ --with-pear \ --enable-ftp \ --enable-exif \ --disable-ipv6 \ --with-imap-ssl
解決php編譯報(bào)錯(cuò)configure: error: mcrypt.h not found. Please reinstall libmcrypt. configure: error: mcrypt.h not found. Please reinstall libmcrypt. 方法一: yum install -y epel-release yum install -y libmcrypt-devel 兩個(gè)不能一起安裝,因?yàn)镃entOs6默認(rèn)的yum源沒(méi)有 libmcrypt-devel這個(gè)包,只能借助epel的yum源,所以先安裝epel,再安裝 libmcrypt。 方法二: 報(bào)錯(cuò)內(nèi)容:configure: error: mcrypt.h not found. Please reinstall libmcrypt 網(wǎng)上搜索了很多,包括自帶的 yum install libmcrypt libmcrypt-devel,這個(gè)是沒(méi)有效果的。 去SourceForget下載libmcrypt http://sourceforge.net/projects/mcrypt/files/Libmcrypt/ ,最新版是mcrypt 2.6.7.gz。下載下來(lái)安裝仍舊報(bào)錯(cuò)libmcrypt沒(méi)有找到! 繼續(xù)測(cè)試,最后安裝成功,感覺(jué)是版本太高。 方法(關(guān)鍵點(diǎn)在用 2.5.7版本): #使用wget可以通過(guò)以下路徑下載 wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz #解壓 tar -zxvf libmcrypt-2.5.7.tar.gz #進(jìn)入目錄 cd libmcrypt-2.5.7 #編譯(默認(rèn)安裝到/usr/local/lib/) ./configure --prefix=/usr/local/libmcrypt #執(zhí)行安裝 make && make install 再回到PHP-5.5.13解壓縮的ext目錄的mcrypt里面 phpize ./configure --with-php-config=/usr/local/php5/bin/php-config \ --with-libmcrypt=/usr/lib/libmcrypt make make test make install vim /etc/php.ini #加入extension=mcrypt.so
make && make install
cp php.ini-production /usr/local/php-fpm/etc/php.ini vi /usr/local/php-fpm/etc/php-fpm.conf
[global] pid = /usr/local/php-fpm/var/run/php-fpm.pid error_log = /usr/local/php-fpm/var/log/php-fpm.log [www] listen = /tmp/php-fcgi.sock listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod 755 /etc/init.d/php-fpm chkconfig --add php-fpm chkconfig php-fpm on service php-fpm start ps aux |grep php-fpm
cd /usr/local/src/nginx-1.14.2 ./configure --prefix=/usr/local/nginx
make && make install
vim /etc/init.d/nginx
#!/bin/bash # chkconfig: - 30 21 # description: http service. # Source Function Library . /etc/init.d/functions # Nginx Settings NGINX_SBIN="/usr/local/nginx/sbin/nginx" NGINX_CONF="/usr/local/nginx/conf/nginx.conf" NGINX_PID="/usr/local/nginx/logs/nginx.pid" RETVAL=0 prog="Nginx" start() { echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL } reload() { echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL } restart() { stop start } configtest() { $NGINX_SBIN -c $NGINX_CONF -t return 0 } case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1 esac exit $RETVAL
chmod 755 /etc/init.d/nginx chkconfig --add nginx chkconfig nginx on
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak vi /usr/local/nginx/conf/nginx.conf
user nobody nobody; worker_processes 2; error_log /usr/local/nginx/logs/nginx_error.log crit; pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 6000; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 3526; server_names_hash_max_size 4096; log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' ' $host "$request_uri" $status' ' "$http_referer" "$http_user_agent"'; sendfile on; tcp_nopush on; keepalive_timeout 30; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; connection_pool_size 256; client_header_buffer_size 1k; large_client_header_buffers 8 4k; request_pool_size 4k; output_buffers 4 32k; postpone_output 1460; client_max_body_size 10m; client_body_buffer_size 256k; client_body_temp_path /usr/local/nginx/client_body_temp; proxy_temp_path /usr/local/nginx/proxy_temp; fastcgi_temp_path /usr/local/nginx/fastcgi_temp; fastcgi_intercept_errors on; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 8k; gzip_comp_level 5; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css text/htm application/xml; server { listen 80; server_name localhost; index index.html index.htm index.php; root /usr/local/nginx/html; location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/tmp/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; } } }
/usr/local/nginx/sbin/nginx -t /etc/init.d/nginx start netstat -lntp |grep 80
測(cè)試php解析
vi /usr/local/nginx/html/1.php //加入如下內(nèi)容
<?php echo "test php scripts."; ?>
curl localhost/1.php
附:設(shè)置默認(rèn)虛擬主機(jī)和多站點(diǎn)配置
增加vhost文件夾用于配置多站點(diǎn)
vim /usr/local/nginx/conf/nginx.conf
include vhost/*.conf
mkdir /usr/local/nginx/conf/vhost
cd !$; vim default.conf //加入如下內(nèi)容
server
{
listen 80 default_server; // 有這個(gè)標(biāo)記的就是默認(rèn)虛擬主機(jī)
server_name aaa.com;
index index.html index.htm index.php;
root /data/wwwroot/default;
}
mkdir -p /data/wwwroot/default/
echo “This is a default site.”>/data/wwwroot/default/index.html
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
curl localhost
curl -x127.0.0.1:80 123.com
關(guān)于CentOS 7中怎么搭建LNMP環(huán)境就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
文章題目:CentOS7中怎么搭建LNMP環(huán)境
標(biāo)題網(wǎng)址:http://redsoil1982.com.cn/article22/iicccc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、云服務(wù)器、網(wǎng)頁(yè)設(shè)計(jì)公司、全網(wǎng)營(yíng)銷推廣、App設(shè)計(jì)、小程序開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)