centos最新版本安裝最新的php , nginx , mysql
背景介紹:
我在百度上看到大量的所謂lnmp安裝,百分之八十一個抄一個,還給抄錯了,剩下的百分之二十還有場景侷限, 我現在用純淨的系統開始用壓縮包安裝(因爲我可以很方便的找到我的壓縮包,以及安裝的文件)配置,我會盡量讓這個過程詳細一點;後面我會陸續記錄gitserver安裝,ftp安裝配置等等,(有可能今天一起發出來)
準備工作:(php,nginx,mysql需要的一些依賴,可能需要一陣子,耐心等待就好)
#這裏的大家都可以執行一下,已經安裝的會跳過的,不要跳着安裝,大家最好把yum 換成最新的(如果國內網易的,或者阿里的)
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers perl* httpd-devel postgresql-devel
#安裝所需其它依賴
1.下載pcre(支持nginx 僞靜態)
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
tar -xzvf pcre-8.41.tar.gz
cd pcre-8.41
./configure --prefix=/usr/local/pcre #配置
make && make install #編譯安裝
2.安裝cmake (用於編譯c++)
wget https://cmake.org/files/v3.10/cmake-3.10.1.tar.gz
tar -xzvf cmake-3.10.1.tar.gz
cd cmake-3.10.1
./bootstrap
make && make install
開始安裝環境 : (/usr/local/src):
1.下載最新的php :
wget http://cn2.php.net/distributions/php-7.2.0.tar.gz
2.下載最新的nginx:
wget http://nginx.org/download/nginx-1.13.7.tar.gz
3.下載最新的mysql :
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
4.解壓縮
for tar in *.tar.gz; do tar xvf $tar; done #這裏是批量解壓縮
========安裝配置nginx:
進入nginx
cd nginx-1.13.7
./configure --prefix=/usr/local/nginx #編譯配置設置
make && make install #老規矩 安裝
echo 'PATH=/echo 'PATH=/usr/local/php/bin/:$PATH' >> /etc/profile #配置環境變量
source /etc/profile #立即生效
cd /usr/local/nginx/conf #來到nginx 配置目錄下
egrep -v "#|^$" nginx.conf.default >nginx.conf #精簡配置,方面進去修改
vi /lib/systemd/system/nginx.service #創建nginx 啓動文件
內容如下:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=
true
[Install]
WantedBy=multi-user.target
systemctl start nginx.service #啓動nginx
systemctl enable nginx.service #設置開機啓動
==========安裝php :
配置: ./configure --enable-fpm --prefix=/usr/local/php --sysconfdir=/usr/local/php/etc --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --with-bz2 --enable-soap --without-pear
然後 make && make install #編譯安裝
echo 'PATH=/usr/local/nginx/sbin/:$PATH' >> /etc/profile #寫入環境變量
source /etc/profile #讓配置生效
cp php-fpm /etc/init.d/php-fpm #設置啓動腳本
報錯: [21-Dec-2017 16:08:42] ERROR: [pool www] please specify user and group other than root
解決 : adduser nginx # 添加用戶
groupadd nginx #添加用戶組
useradd -g nginx nginx #新建用戶同時增加工作組
vim vim /usr/local/php/etc/php-fpm.d/www.conf #修改
user = nginx
group = nginx 然後保存
再啓就啓動成功
========安裝mysql
進入mysql:
groupadd -r mysql #添加mysql組
useradd -g mysql -r -s /sbin/nologin mysql #添加mysql 用戶
mv mysql-5.7.20-linux-glibc2.12-x86_64 /usr/local/mysql #移動
./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
安裝成功如下圖:
Note:是我們的臨時密碼;
cp support-files/mysql.server /etc/init.d/mysqld #加入系統進程
echo 'PATH=/usr/local/mysql/bin/:$PATH' >> /etc/profile #寫入環境變量
source /etc/profile #讓配置生效
chkconfig mysqld on #開機啓動
mysql -u root -p #進入數據庫
update
mysql.
user
set
authentication_string=
password
(
'123qwe'
)
where
user
=
'root'
and
Host =
'localhost'
; #修改密碼
flush
privileges
;
#立刻生效
quit; 退出