当前位置: 代码迷 >> 综合 >> PHP环境安装-php7.3.15
  详细解决方案

PHP环境安装-php7.3.15

热度:70   发布时间:2023-12-05 22:43:57.0
一、创建用户
1.创建www用户
useradd www
创建mysql用户
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
二、创建目录
1.创建安装包目录
mkdir /usr/src/base_soft
2.创建www相关目录
mkdir /data
mkdir /data/www
mkdir /data/release
mkdir /data/logs
mkdir /data/logs/nginx
三、获取安装包
scp -r root@x.x.x.x:/usr/src/base_soft/* /usr/src/base_soft/
四、安装环境
1.安装nginx
#安装依赖
yum -y install pcre-devel openssl openssl-devel lua-devel
cd /usr/src/base_soft/
#解压安装包
tar -xvzf nginx-1.12.2.tar.gz
tar -xvzf LuaJIT-2.0.5.tar.gz
tar -xvzf v0.10.11.tar.gz
tar -xvzf v0.3.0.tar.gz
cp -r lua-nginx-module-0.10.11 /usr/local/src/
cp -r ngx_devel_kit-0.3.0 /usr/local/src/
cd nginx-1.12.2
#安装
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_realip_module
--with-pcre --add-module=/usr/local/src/lua-nginx-module-0.10.11 --add-module=/usr/local/src/ngx_devel_kit-
0.3.0 --with-http_stub_status_module
make
make install
测试
/usr/local/nginx/sbin/nginx
curl 127.0.0.1
2.安装php
1.安装依赖 yum -y install gcc gcc-c++ libxml2 libxml2-devel openssl openssl-devel curl curl-devel libjpeg libjpeg-devel
libpng libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel gmp-devel
libmcrypt-devel readline-devel sqlite-devel gd gd-devel autoconf
2.安装cmake
#卸载系统自带cmake
yum remove cmake
cd /usr/src/base_soft
tar zxvf cmake-3.16.0.tar.gz
mv cmake-3.16.0 /usr/local/cmake
cd /usr/local/cmake
./bootstrap
gmake
gmake install
rm -rf cmake-3.16.0.tar.gz
3.安装libzip库依赖
cd /usr/src/base_soft/
tar zxvf libzip-1.6.1.tar.gz
cd libzip-1.6.1
mkdir build
cd build/
cmake ..
make
make install
#新增编译时使用的动态库的路径
vim /etc/ld.so.conf
#底部新增两行
/usr/local/lib64
/usr/local/lib
#刷新动态库缓存
ldconfig
4.安装php zip扩展
cd /usr/src/base_soft/
tar zxvf zip-1.17.2.tgz
cd zip-1.17.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make test
make install
5.安装php ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-
inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-xmlrpc --with-
openssl --with-pcre-regex --with-sqlite3 --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-freetype-dir --enable-gd-
jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --
enable-mbregex-backtrack --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd -
-with-zlib-dir --with-pdo-sqlite --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
若报错:configure: error: off_t undefined; check your library configuration
vim /etc/ld.so.conf
#添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
# 使之生效
ldconfig
make
make install
6.安装phpredis扩展
cd /usr/src/base_soft/
tar -xvzf phpredis-4.3.0.tgz
cd redis-4.3.0
1.安装
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
2.更新php.ini
vim /usr/local/php/lib/php.ini
#新增扩展
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/redis.so
3.redis
cd /usr/src/base_soft/
tar -xvzf redis-4.0.2.tar.gz
cd redis-4.0.2
make PREFIX=/usr/local/redis install
4.mysql
#安装
cd /usr/src/base_soft/
tar -xvzf mysql-5.6.16.tar.gz
cd mysql-5.6.16
yum install gcc gcc-c++ cmake ncurses-devel bison
cmake .  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1
make
make install
#配置多实例
cd /usr/local/mysql
mkdir -p {3306,3307}/data
cp support-files/my-default.cnf /usr/local/mysql/data/3306/my.cnf
cp support-files/my-default.cnf /usr/local/mysql/data/3307/my.cnf
ln -s /usr/local/mysql/bin/* /usr/local/sbin/
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/3306
--defaults-file=/usr/local/mysql/data/3306/my.cnf --user=mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/3307
--defaults-file=/usr/local/mysql/data/3307/my.cnf --user=mysql
#启动
/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/data/3306/my.cnf &
/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/data/3307/my.cnf &
#sock登录
mysql -uroot -S /usr/local/mysql/data/3306/mysql.sock
#设置密码
m ysqladmin -uroot -S /usr/local/mysql/data/3306/mysql.sock password "dscs-dev"
mysqladmin -uroot -S /usr/local/mysql/data/3307/mysql.sock password "dscs-test"
#密码登录
mysql -u root -h 127.0.0.1 -p
#设置外网ip访问账号
GRANT ALL PRIVILEGES ON *.* TO 'username'@'ip' IDENTIFIED BY 'password' WITH GRANT OPTION;
flush privileges;
备注:参考 https://blog.csdn.net/weixin_34087307/article/details/93091990 五、配置文件优化
1.添加环境变量
vim /etc/profile
## 末尾添加
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
export
PATH=/usr/local/mysql/bin:/usr/local/nginx/sbin/:/usr/local/php/bin/:/usr/local/php/sbin/:/usr/local/redis/bin:$PATH
## 保存退出
source /etc/profile
2.修改nginx、php配置文件
1.nginx
/usr/local/nginx/conf/nginx.conf
2.php
/usr/local/php/lib/php.ini
/usr/local/php/etc/php-fpm.conf
/usr/local/php/etc/php-fpm.d/ www.conf
3.redis
mkdir /usr/local/redis/6379
/usr/src/base_soft/redis-4.0.2/utils/install_server.sh
## 相关设置
Port : 6379
Config file : /usr/local/redis/6379/redis.conf
Log file : /usr/local/redis/6379/redis.log
Data dir : /usr/local/redis/6379/
Executable : /usr/local/redis/bin/redis-server
## 相关 warning
#WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to
the lower value of 128.
echo 511 > /proc/sys/net/core/somaxconn
# WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this
issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl
vm.overcommit_memory=1' for this to take effect.
echo 1 > /proc/sys/vm/overcommit_memory
echo never > /sys/kernel/mm/transparent_hugepage/enabled
redis 启动退出命令
## 启动
/usr/local/redis/bin/redis-server /usr/local/redis/6379/redis.conf
#多端口配置
mkdir /usr/local/redis/6380
cp /usr/local/redis/6379/redis.conf /usr/local/redis/6380/redis.conf
vim /usr/local/redis/6380/redis.conf
## 替换 6379 6380
#启动6380端口
/usr/local/redis/bin/redis-server /usr/local/redis/6380/redis.conf 六、更新web目录所有者
chown www.www -R /data
chown www.www -R /usr/local/php
chown mysql.mysql -R /usr/local/mysql/
  相关解决方案