1、创建centos7容器
docker run -itd -v E:\PHP\project:/var/www -v E:\PHP\sites:/etc/nginx/conf.d --privileged=true -p 8080:80 -p 22:22 -p 3306:3306 -p 6399:6379 --name lnmp centos /usr/sbin/init
2、进入容器
docker exec -it lnmp /bin/bash
3、安装SSH服务
1.yum install -y openssh-server
2.修改密码:passwd root
3.启动ssh服务:systemctl start sshd.service
4.ssh开机启动:systemctl enable sshd.service
5.查看ssh状态:systemctl status sshd.service
4、安装PHP74
1. yum -y 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 zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libzip gcc-c++ sqlite-devel.x86_64 lsof wget which tcl
2. cd /opt
3. wget https://github.com/kkos/oniguruma/releases/download/v6.9.5_rev1/onig-6.9.5-rev1.tar.gz -O onig-6.9.5.tar.gz
4. tar -zxvf onig-6.9.5.tar.gz
5. cd onig-6.9.5
6. ./configure --prefix=/usr --libdir=/lib64
7. make && make install
8. cd /opt
9. wget https://www.php.net/distributions/php-7.4.33.tar.gz
10. tar -zxvf php-7.4.33.tar.gz
11. groupadd www
useradd -g www www
12. mkdir -p /usr/local/php/conf && mkdir -p /usr/local/php/etc
13. cd php-7.4.33
14.
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/conf --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-fpm --with-fpm-user=www --with-fpm-group=www
15. make && make install
16. echo "PATH=$PATH:/usr/local/php/bin" >> /etc/profile && echo "export PATH" >> /etc/profile
17. source /etc/profile
18. cp php.ini-production /usr/local/php/conf/php.ini && ln -s /usr/local/php/sbin/php-fpm /usr/local/bin
19. cp sapi/fpm/www.conf /usr/local/php/etc/php-fpm.d/www.conf
20. cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
21. cp sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm
22. vi /etc/init.d/php-fpm
php_fpm_BIN=/usr/local/php/sbin/php-fpm
php_fpm_CONF=/usr/local/php/etc/php-fpm.conf
php_fpm_PID=/usr/local/php/var/run/php-fpm.pid
23. chmod +x /etc/init.d/php-fpm
24. 设置开机启动
cd /etc/init.d/
chkconfig php-fpm on
25. 启动服务
systemctl start php-fpm
5、 安装redis
1. cd /opt
2. 安装python3
wget https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tgz
tar -zxvf Python-3.11.1.tgz
cd Python-3.11.1
./configure --prefix=/usr/local/python3 --with-ssl
make
make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
3. 安装redis
cd /opt
wget https://download.redis.io/redis-stable.tar.gz
tar -xzvf redis-stable.tar.gz
cd redis-stable
make
make install
cp redis.conf /usr/etc/
cd /usr/etc
修改配置
vi redis.conf
找到daemonize no改为 daemonize yes
找到requirepass,这一行是默认是注释了 的,说明没有开启密码保护
改为 requirepass root # root为密码
允许远程访问
找到bind 127.0.0.1 -::1,修改为 bind 0.0.0.0
设置开机启动
cd /opt/redis-stable
cp utils/redis_init_script /etc/init.d/redis
vi /etc/init.d/redis
CONF="/usr/etc/redis.conf" # 这个是redis的配置文件,改成你本地的路径
PASS="root" # 密码
如下图
image.png
设置redis 权限
chmod 755 /etc/init.d/redis
设置开机启动
cd /etc/init.d/
chkconfig redis on
启动redis systemctl start redis
关闭redis systemctl stop redis
6、安装redis-php扩展
yum install -y autoconf m4
cd /opt
wget https://github.com/phpredis/phpredis/archive/refs/tags/5.3.7.tar.gz
tar -zxvf 5.3.7.tar.gz
cd phpredis-5.3.7
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
vi /usr/local/php/conf/php.ini #编辑配置文件,在最后一行添加以下内容
添加
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/redis.so
7、安装composer
1、使用命令下载
cd /opt/
curl -sS https://getcomposer.org/installer | php
2.下载之后设置环境变量
mv composer.phar /usr/local/bin/composer
3.修改镜像地址为阿里云
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
8、安装nginx
cd /opt
curl -O http://nginx.org/download/nginx-1.22.1.tar.gz
tar -zxvf nginx-1.22.1.tar.gz
cd nginx-1.22.1
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --user=www --group=www --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_stub_status_module --with-http_gzip_static_module
make && make install
cd /usr/local/nginx
vi nginx.conf
添加 include /etc/nginx/conf.d/*.conf;
设置开机自启
vi /lib/systemd/system/nginx.service
添加如下内容
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
#使配置生效
systemctl daemon-reload
#设置开机启动
systemctl enable nginx.service
#启动服务
systemctl start nginx
9、安装PHP mongodb扩展
cd /opt/
wget http://pecl.php.net/get/mongodb-1.15.0.tgz
tar -zxvf mongodb-1.15.0.tgz
cd mongodb-1.15.0
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
vi /usr/local/php/conf/php.ini 在末尾追加
/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/mongodb.so
10、docker导出、导入镜像
docker export -o lnmp-1.0.tar 容器ID
docker import lnmp-1.0.tar lnmp:1.0
11、 安装GO
cd /opt/
wget https://golang.google.cn/dl/go1.19.5.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.19.5.linux-amd64.tar.gz
vi /etc/profile
在末尾添加 export PATH=$PATH:/usr/local/go/bin
source /etc/profile
网友评论