1、nginx安裝php
一、下載nginx並安裝依賴html
nginx官網下載最新穩定版本(Stable version),http://nginx.org/en/download.html 。 cd /usr/local/src wget http://nginx.org/download/nginx-1.12.1.tar.gz tar -zxvf nginx-1.12.1.tar.gz 安裝依賴 yum -y install pcre-devel openssl openssl-devel gcc gcc-c++ ncurses-devel perl
二、編譯安裝node
cd /usr/local/src/nginx-1.12.1 ./configure --prefix=/usr/local/nginx make && make install /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 開啓 nginx /usr/local/nginx/sbin/nginx
2、php7安裝mysql
一、安裝依賴包linux
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel epel-release autoconf m4
二、下載php源碼nginx
php源碼下載地址:http://php.net/downloads.php cd /usr/local/src wget http://cn2.php.net/distributions/php-7.1.7.tar.gz tar zxvf php-7.1.7.tar.gz cd php-7.1.7 若服務器無nginx用戶與組,則添加 useradd nginx
三、編譯安裝c++
./configure \ --prefix=/usr/local/php \ --with-config-file-path=/etc \ --enable-fpm \ --with-fpm-user=nginx \ --with-fpm-group=nginx \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-soap \ --with-libxml-dir \ --with-xmlrpc \ --with-openssl \ --with-mcrypt \ --with-mhash \ --with-pcre-regex \ --enable-pcntl \ --with-zlib \ --enable-bcmath \ --with-iconv \ --with-bz2 \ --enable-calendar \ --with-curl \ --with-cdb \ --enable-dom \ --enable-exif \ --enable-fileinfo \ --enable-filter \ --with-pcre-dir \ --enable-ftp \ --with-gd \ --with-openssl-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib-dir \ --with-freetype-dir \ --enable-gd-native-ttf \ --with-gettext \ --with-gmp \ --with-mhash \ --enable-json \ --enable-mbstring \ --enable-mbregex \ --enable-mbregex-backtrack \ --with-libmbfl \ --with-onig \ --enable-pdo \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-zlib-dir \ --with-readline \ --enable-session \ --enable-shmop \ --enable-simplexml \ --enable-sockets \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-wddx \ --with-libxml-dir \ --with-xsl \ --enable-zip \ --enable-mysqlnd-compression-support \ --with-pear \ --enable-opcache make && make install
編譯說明:--enable-gd-jis-conv \ 這個參數儘可能不要添加,否則gd生成圖片沒法插入中文。中文會被認爲是日文。詳見php官方bug https://bugs.php.net/bug.php?id=42218sql
四、配置數據庫
添加環境變量json
vim /etc/profile 在末尾加入 PATH=$PATH:/usr/local/php/bin export PATH 執行 source /etc/profile 這時候便可查看php版本 php -v
配置php-fpm(php版本爲7.x)
cd /usr/local/src/php-7.1.7 cp php.ini-production /etc/php.ini cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm
配置php-fpm(php版本爲5.x)
cp /usr/local/src/php-5.6.29/php.ini-development /usr/local/php/lib/php.ini cp /usr/local/src/php-5.6.29/php.ini-production /etc/php.ini cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf /usr/local/php/sbin/php-fpm
啓動php-fpm(php版本5.x 在前文中已經啓動,因此不須要再啓動)
/etc/init.d/php-fpm start
相關優化
查找php.ini位置 php -i |grep php.ini 一、修改 /etc/php.ini 的默認時間區域爲 date.timezone = PRC
修改參數後,記得重啓php-fpm
五、配置nginx與php
cd /usr/local/nginx/conf vim nginx.conf 把php相關的註釋去掉 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } 重啓nginx /usr/local/nginx/sbin/nginx -s reload
3、mysql5.6安裝
一、先檢查有無mariadb的包 #若爲centos7如下版本,則檢查mysql
rpm -qa|grep mariadb #若爲centos7如下版本 則rpm -qa|grep mysql 如有,則刪掉包及依賴 rpm -e --nodeps mysql-libs-5.1.61-4.el6.x86_64
二、下載 解壓mysql
cd /usr/local/src wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64 mv mysql-5.6.33-linux-glibc2.5-x86_64 ../mysql
三、在mysql目錄更改組和用戶,data目錄初始化
cd /usr/local/mysql groupadd mysql useradd -r -g mysql mysql chown -R mysql:mysql ./ yum install -y perl-Module-Install.noarch libaio* #centos7如下版本,不需執行這一行命令 /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data chown -R root ./ chown -R mysql data
四、複製配置文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
五、將mysqld服務加入開機自啓動項
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 經過chkconfig命令將mysqld服務加入到自啓動服務項中 chkconfig --add mysqld 檢查是否添加成功 chkconfig --list mysqld
六、開啓mysql
service mysqld start
七、鏈接mysql
/usr/local/mysql/bin/mysql
八、將mysql加入環境變量
vi /etc/profile 在文件最後加上2行代碼 MYSQL_HOME=/usr/local/mysql export PATH=$PATH:$MYSQL_HOME/bin 再執行命令讓其生效 source /etc/profile 試試 mysql ,則能夠鏈接上數據庫
九、修改mysql密碼,並設置其可遠程鏈接數據庫
use mysql; update user set Password=password('123456') where Host='localhost' and User='root'; delete from user where Password=''; 設置用戶爲root密碼爲123456 的用戶,能夠遠程鏈接mysql GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; flush privileges;