NGINX+PHP7+MYSQL+Swoole 在CENTOS7.3下安装
一、Nginx1.8.1 安装
1. 安装 nginx 需要的扩展gcc,pcre-devel,zlib-devel, openssl openssl-devel
yum -y install gcc-c++ pcre-devel zlib-devel openssl openssl-devel
2. 安装Nginx
cd /usr/local/src;
wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar -zxvf nginx-1.8.1.tar.gz -C /usr/local/src
cd /usr/local/src/nginx-1.8.1
./configure #默认安装到/usr/local/nginx目录下
make #编译
make install #安装
3. 启动Nginx
/usr/local/nginx/sbin/nginx 开启Nginx
4. Nginx设置开机自启
vim /etc/rc.local中添加/usr/local/nginx/sbin/nginx,保存并推出
chmod -R 777 /etc/rc.local
5. Nginx 配置文件所在目录
/usr/local/nginx/conf
6. nginx编译扩展参考https://www.cnblogs.com/zhang-shijie/p/5294162.html
二、php7编译安装
1. cd /usr/local/src/
2. wget http://cn2.php.net/distributions/php-7.0.2.tar.gz
3. tar -xzxvf php-7.0.2.tar.gz
4. cd php-7.0.2
5. 检查php所需要的全部扩展 ,没有的话执行
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 libjpeg-devel bzip2-devel.x86_64 libXpm-devel install gmp-devel icu libicu libicu-devel php-mcrypt libmcrypt libmcrypt-devel postgresql-devel libxslt-devel
注:因为改为用nginx了,所以编译参数中的--with-apxs2=/usr/bin/apxs去掉了,如果要配置apache用,安装PHP前,请先安装apache。
6. 编译参数配置
‘./configure’ ‘–prefix=/usr/local/php’ ‘–with-pdo-pgsql’ ‘–with-zlib-dir’ ‘–with-freetype-dir’ ‘–enable-mbstring’ ‘–with-libxml-dir=/usr’ ‘–enable-soap’ ‘–enable-calendar’ ‘–with-curl’ ‘–with-mcrypt’ ‘–with-gd’ ‘–with-pgsql’ ‘–disable-rpath’ ‘–enable-inline-optimization’ ‘–with-bz2’ ‘–with-zlib’ ‘–enable-sockets’ ‘–enable-sysvsem’ ‘–enable-sysvshm’ ‘–enable-pcntl’ ‘–enable-mbregex’ ‘–enable-exif’ ‘–enable-bcmath’ ‘–with-mhash’ ‘–enable-zip’ ‘–with-pcre-regex’ ‘–with-pdo-mysql’ ‘–with-mysqli’ ‘–with-jpeg-dir=/usr’ ‘–with-png-dir=/usr’ ‘–enable-gd-native-ttf’ ‘–with-openssl’ ‘–with-fpm-user=www-data’ ‘–with-fpm-group=www-data’ ‘–with-libdir=/lib/x86_64-linux-gnu/’ ‘–enable-ftp’ ‘–with-gettext’ ‘–with-xmlrpc’ ‘–with-xsl’ ‘–enable-opcache’ ‘–enable-fpm’ ‘–with-iconv’ ‘–with-xpm-dir=/usr’
7. configure: error: mcrypt.h not found. Please reinstall libmcrypt.
报错这个的时候参考 http://blog.csdn.net/l_yangliu/article/details/53018117
8.配置的checking 结束后,执行: make clean && make && make install(如果出现错误:–ENABLE-OPCACHE=NO时执行export LD_LIBRARY_PATH=/usr/local/mysql/lib或export LD_LIBRARY_PATH=/lib/:/usr/lib/:/usr/local/lib)
装完成后,我们要把源码包中的配置文件复制到PHP安装目录下,源码包中有两个配置 php.ini-development php.ini-production ,看名字就知道,一个是开发环境,一个是生产环境,我们这里就复制开发环境的
cp php.ini-development /usr/local/php/lib/php.ini
9.另外还需要设置环境变量 :修改vim /etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码
PATH=$PATH:/usr/local/php/bin
export PATH
如果使用root权限还显示不够的话,esc然后:wq!强制保存
然后执行 命令 source /etc/profile
10.php -v 就可以看到PHP版本信息了。
11.此时还需要配置PHP-fpm:
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 /usr/local/src/php-7.0.2/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
12.启动php-fpm: useradd www-data; /usr/local/php/sbin/php-fpm
13.php-fpm设置开机自启 systemctl enable php-fpm
三、MySQL5.6 yum安装 参考
http://www.cnblogs.com/yuanfeiblog/p/5276492.html
1. 安装rpm包
[root@typecodes ~]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
成功示例
Retrieving http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-release-el7-5 ################################# [100%]
2. 这时查看当前可用的mysql安装资源:
[root@typecodes ~]# yum repolist enabled | grep “mysql.-community.”
成功的示例
mysql-connectors-community/x86_64 MySQL Connectors Community 14
mysql-tools-community/x86_64 MySQL Tools Community 17
mysql56-community/x86_64 MySQL 5.6 Community Server 139
3. 从上面的列表可以看出,mysql56-community/x86_64和MySQL 5.6 Community Server可以使用。因此,我们就可以直接用yum方式安装了MySQL5.6版本了。
[root@typecodes ~]# yum -y install mysql-community-server
成功的示例
Loaded plugins: axelget, langpacks
No metadata available for base
No metadata available for epel
No metadata available for extras
(Failed to load module fastestmirror: No module named fastestmirror)
repomd.xml | 2.5 kB 00:00:00
update mysql-connectors-community metadata successfully
(Failed to load module fastestmirror: No module named fastestmirror)
repomd.xml | 2.5 kB 00:00:00
update mysql-tools-community metadata successfully
(Failed to load module fastestmirror: No module named fastestmirror)
repomd.xml | 2.5 kB 00:00:00
update mysql56-community metadata successfully
No metadata available for updates
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql56-community | 2.5 kB 00:00:00
(1/3): mysql-connectors-community/x86_64/primary_db | 7.3 kB 00:00:00
(2/3): mysql56-community/x86_64/primary_db | 83 kB 00:00:01
mysql-tools-community/x86_64/p FAILED ============================================== ] 19 kB/s | 92 kB 00:00:00 ETA
http://repo.mysql.com/yum/mysql-tools-community/el/7/x86_64/repodata/3301d2eb425f300dec5a46c4201d08f2cf9232a6-primary.sqlite.bz2: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-tools-community/el/7/x86_64/repodata/3301d2eb425f300dec5a46c4201d08f2cf9232a6-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 3 seconds')
Trying other mirror.
(3/3): mysql-tools-community/x86_64/primary_db | 15 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.24-3.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.24-3.el7 for package: mysql-community-server-5.6.24-3.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) = 5.6.24-3.el7 for package: mysql-community-server-5.6.24-3.el7.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.24-3.el7.x86_64
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.41-2.el7_0 will be obsoleted
---> Package mysql-community-client.x86_64 0:5.6.24-3.el7 will be obsoleting
--> Processing Dependency: mysql-community-libs(x86-64) = 5.6.24-3.el7 for package: mysql-community-client-5.6.24-3.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.6.24-3.el7 will be installed
---> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed
--> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64
--> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.41-2.el7_0 will be obsoleted
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.41-2.el7_0 for package: 1:mariadb-devel-5.5.41-2.el7_0.x86_64
---> Package mysql-community-libs.x86_64 0:5.6.24-3.el7 will be obsoleting
---> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed
--> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Compress::Zlib) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Running transaction check
---> Package mariadb-devel.x86_64 1:5.5.41-2.el7_0 will be obsoleted
---> Package mysql-community-devel.x86_64 0:5.6.24-3.el7 will be obsoleting
---> Package perl-IO-Compress.noarch 0:2.061-2.el7 will be installed
--> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
--> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
---> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed
--> Running transaction check
---> Package perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 will be installed
---> Package perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================================================================
Installing:
mysql-community-client x86_64 5.6.24-3.el7 mysql56-community 19 M
replacing mariadb.x86_64 1:5.5.41-2.el7_0
mysql-community-devel x86_64 5.6.24-3.el7 mysql56-community 3.4 M
replacing mariadb-devel.x86_64 1:5.5.41-2.el7_0
mysql-community-libs x86_64 5.6.24-3.el7 mysql56-community 2.0 M
replacing mariadb-libs.x86_64 1:5.5.41-2.el7_0
mysql-community-server x86_64 5.6.24-3.el7 mysql56-community 58 M
Installing for dependencies:
mysql-community-common x86_64 5.6.24-3.el7 mysql56-community 256 k
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k
perl-DBI x86_64 1.627-4.el7 base 802 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k
Transaction Summary
=======================================================================================================================================================================
Install 4 Packages (+7 Dependent packages)
Total download size: 83 M
Downloading packages:
mysql-community-devel-5.6.24-3.el7.x86_64.rpm | 3.4 MB 00:00:03
mysql-community-client-5.6.24-3.el7.x86_64.rpm | 19 MB 00:00:05
mysql-community-server-5.6.24-3.el7.x86_64.rpm | 58 MB 00:00:11
mysql-community-libs-5.6.24-3.el7.x86_64.rpm | 2.0 MB 00:00:02
perl-DBI-1.627-4.el7.x86_64.rpm | 0 B 00:00:01 ...
perl-DBI-1.627-4.el7.x86_64.rpm | 802 kB 00:00:00
(1/6): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm | 57 kB 00:00:00
(2/6): perl-Net-Daemon-0.48-5.el7.noarch.rpm | 51 kB 00:00:00
(3/6): perl-PlRPC-0.2020-14.el7.noarch.rpm | 36 kB 00:00:00
(4/6): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm | 32 kB 00:00:00
(5/6): perl-IO-Compress-2.061-2.el7.noarch.rpm | 260 kB 00:00:00
warning: /var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.24-3.el7.x86_64.rpm: V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY 00:00:01 ETA
Public key for mysql-community-common-5.6.24-3.el7.x86_64.rpm is not installed
(6/6): mysql-community-common-5.6.24-3.el7.x86_64.rpm | 256 kB 00:00:01
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 388 kB/s | 692 kB 00:00:01
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
Package : mysql-community-release-el7-5.noarch (installed)
From : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : mysql-community-common-5.6.24-3.el7.x86_64 1/14
Installing : mysql-community-libs-5.6.24-3.el7.x86_64 2/14
Installing : mysql-community-client-5.6.24-3.el7.x86_64 3/14
Installing : perl-Net-Daemon-0.48-5.el7.noarch 4/14
Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 5/14
Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 6/14
Installing : perl-IO-Compress-2.061-2.el7.noarch 7/14
Installing : perl-PlRPC-0.2020-14.el7.noarch 8/14
Installing : perl-DBI-1.627-4.el7.x86_64 9/14
Installing : mysql-community-server-5.6.24-3.el7.x86_64 10/14
Installing : mysql-community-devel-5.6.24-3.el7.x86_64 11/14
Erasing : 1:mariadb-devel-5.5.41-2.el7_0.x86_64 12/14
Erasing : 1:mariadb-5.5.41-2.el7_0.x86_64 13/14
Erasing : 1:mariadb-libs-5.5.41-2.el7_0.x86_64 14/14
Verifying : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 1/14
Verifying : mysql-community-common-5.6.24-3.el7.x86_64 2/14
Verifying : mysql-community-devel-5.6.24-3.el7.x86_64 3/14
Verifying : mysql-community-client-5.6.24-3.el7.x86_64 4/14
Verifying : perl-PlRPC-0.2020-14.el7.noarch 5/14
Verifying : mysql-community-server-5.6.24-3.el7.x86_64 6/14
Verifying : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 7/14
Verifying : mysql-community-libs-5.6.24-3.el7.x86_64 8/14
Verifying : perl-Net-Daemon-0.48-5.el7.noarch 9/14
Verifying : perl-DBI-1.627-4.el7.x86_64 10/14
Verifying : perl-IO-Compress-2.061-2.el7.noarch 11/14
Verifying : 1:mariadb-5.5.41-2.el7_0.x86_64 12/14
Verifying : 1:mariadb-devel-5.5.41-2.el7_0.x86_64 13/14
Verifying : 1:mariadb-libs-5.5.41-2.el7_0.x86_64 14/14
Installed:
mysql-community-client.x86_64 0:5.6.24-3.el7 mysql-community-devel.x86_64 0:5.6.24-3.el7 mysql-community-libs.x86_64 0:5.6.24-3.el7
mysql-community-server.x86_64 0:5.6.24-3.el7
Dependency Installed:
mysql-community-common.x86_64 0:5.6.24-3.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBI.x86_64 0:1.627-4.el7
perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7
Replaced:
mariadb.x86_64 1:5.5.41-2.el7_0 mariadb-devel.x86_64 1:5.5.41-2.el7_0 mariadb-libs.x86_64 1:5.5.41-2.el7_0
Complete!
4. MySQL安装完成后,进行相关配置
#######安装成功后,将其加入开机启动
[root@typecodes ~]# systemctl enable mysqld
#######启动mysql服务进程
[root@typecodes ~]# systemctl start mysqld
#######配置mysql(设置密码等)
[root@typecodes ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y [设置root用户密码]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables…
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y [删除匿名用户]
… Success!
Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y [禁止root远程登录]
… Success!
By default, MySQL comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y [删除test数据库]
- Dropping test database…
ERROR 1008 (HY000) at line 1: Can’t drop database ‘test’; database doesn’t exist
… Failed! Not critical, keep moving… - Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y [刷新权限]
… Success!
All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up…
四、swoole的安装
1、下载swoole
wget https://pecl.php.net/get/swoole-4.2.0.tgz
ls查看有没有swoole-4.2.0.tgz文件
如果有则解压:tar -zxf swoole-4.2.0.tgz
解压以后:cd swoole-4.2.0
测试php环境安装没:php -v
2、安装依赖
yum -y install gcc gcc-c++ autoconf pcre-devel make
3、编译
phpize
./configure
make && make install
4、配置
如果忘记php.ini在哪个位置用:locate php.ini
cd 位置
进去以后 /进行搜索 n进行向下查询 i当前位置进行编辑
编译成功后,修改php.ini加入extension=swoole.so(注意这里是swoole.so扩展地址)
添加完成以后:esc :wq!强制保存
重启php-fpm:service php-fpm restart
5、测试
在终端输入php -m查看swoole扩展是否用,或者打印phpinfo();
知识插入:
执行firewall-cmd --permanent --zone=public --add-port=3306/tcp,提示FirewallD is not running,如下图所示。
通过systemctl status firewalld查看firewalld状态,发现当前是否是dead状态,如果是,即防火墙未开启。
通过systemctl start firewalld开启防火墙,没有任何提示即开启成功。
再次通过systemctl status firewalld查看firewalld状态,显示running即已开启了。
如果要关闭防火墙设置,可能通过systemctl stop firewalld这条指令来关闭该功能。(我的暂时没关)
查看已开放的端口
firewall-cmd --list-ports
开放端口(开放后需要要重启防火墙才生效)
firewall-cmd --zone=public --add-port=3338/tcp --permanent
重启防火墙
firewall-cmd --reload
关闭端口(关闭后需要要重启防火墙才生效)
firewall-cmd --zone=public --remove-port=3338/tcp --permanent
开机启动防火墙
systemctl enable firewalld
开启防火墙
systemctl start firewalld
禁止防火墙开机启动
systemctl disable firewalld
停止防火墙
systemctl stop firewalld
如果ctenOS 7的ip忽然失效:
如果这个文件 ifcfg-ens33已经将ONBOOT改为yes了,之前用的还好好的还有ip地址的但是现在没有了,先
重启网络服务: sudo service network restart没有问题那么就已经OK了。
出现问题
解决方式:禁用NetworkManager
systemctl stop NetworkManager
systemctl disable NetworkManager
然后重新启动网络服务就OK了
Centos7 firewalld防火墙打开端口后仍不能访问ftp解决办法
firewall-cmd --list-services后发现缺失ftp
增加:firewall-cmd --permanent --add-service=ftp
重启:firewall-cmd --reload
如果22端口开放,ftp可以正常连接的情况下:
在/www/wwwroot/新建文件夹名
在phpstorm打开项目文件:
1、工具–>Deployment–>Connection–>±->名称最好和项目名称一样
2、Mappings那列里面(local path)本地文件所在目录一般不用修改,Deployment path填写/()表示根目录
3、Connection:
Type:SFTP
Host:服务器ip 端口号
User name:用户名
password:密码
Root path:点击文件夹,选中新增/www/wwwroot/文件名
4、工具–>Deployment–>Automatic Upload选中,自动上传
5、工具–>Deployment–>Browse Remote Host可以实时查看服务器项目是否实时更新