Ubuntu系统下PHP的安装与配置
在Ubuntu系统中,PHP是一种广泛使用的开源服务器端脚本语言,它支持多种数据库,可以用于创建动态网页和Web应用程序,本文将详细介绍如何在Ubuntu系统中安装和配置PHP。
1、更新系统软件包
在开始安装PHP之前,首先需要更新系统软件包,打开终端,输入以下命令:
sudo apt-get update sudo apt-get upgrade
2、安装Apache Web服务器
PHP通常与Apache Web服务器一起使用,我们需要先安装Apache,在终端中输入以下命令:
sudo apt-get install apache2
安装完成后,启动Apache服务:
sudo systemctl start apache2
3、安装PHP
接下来,我们开始安装PHP,在终端中输入以下命令:
sudo apt-get install php libapache2-mod-php php-mysql php-xml php-mbstring php-curl php-gd php-json php-zip php-fpm php-intl php-bcmath php-imagick php-cli php-apcu
4、重启Apache服务
安装完成后,需要重启Apache服务以使新安装的PHP模块生效,在终端中输入以下命令:
sudo systemctl restart apache2
5、验证PHP安装
为了验证PHP是否已成功安装,我们需要创建一个名为info.php的文件,并在其中添加一些PHP代码,在终端中输入以下命令:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
在浏览器中访问http://localhost/info.php,如果看到PHP信息页面,说明PHP已成功安装。
6、配置PHP-FPM(可选)
默认情况下,PHP在Apache中通过模块方式运行,为了获得更好的性能和灵活性,我们可以使用PHP-FPM(FastCGI Process Manager),要启用PHP-FPM,请按照以下步骤操作:
安装PHP-FPM:
sudo apt-get install php7.4-fpm php7.4-fpm-dev php7.4-pgsql php7.4-sqlite php7.4-gd php7.4-curl php7.4-json php7.4-mbstring php7.4-tokenizer php7.4-xml php7.4-zip php7.4-opcache php7.4-imap php7.4-interbase php7.4-intl php7.4-soap curl gdb libreadline-dev libpq5 libsqlite3-dev libssl-dev libxml2-dev zlib1g-dev libzip-dev libbz2-dev libonig-dev libxslt1-dev libcurl4-openssl-dev libjpeg8-dev libpng12-dev libfreetype6-dev libmcrypt4-dev libmemcached-dev libtidy5-dev libxslt1-dev libzip4 libzip-dev libpcre3 libpcre3-dev libmcrypt4 libmcrypt4-dev libmhash2 libmhash2-dev libvpx5 libvpx5-dev libwebp-dev libjpeg62 libjpeg62-turbo libjpeg62-dev libpng12 libpng12-dev libfreetype6 freetype6 freetype6-dev libt1font1 t1utils fontconfig fontconfig-bin libfontconfig1 libfontconfig1-dev liblcms2 lcms2-utils liblcms2-dev openssl libssl1.0.0 libssl1.0.0:i386 zlib1g zlib1g-dev libjpeg62:i386 libjpeg62:i386-turbo libjpeg62:i386-dev libpng12:i386 libpng12:i386-dev libfreetype6:i386 freetype6:i386 freetype6:i386-dev libt1font1:i386 t1utils:i386 fontconfig:i386 fontconfig:i386-bin libfontconfig1:i386 libfontconfig1:i386-dev liblcms2:i386 lcms2:i386 lcms2:i386-utils lcms2:i386-dev openssl:i386 openssl:i386 -y --force-yes --allowerasing --noprogressbar --with-fpm --with-fpm-user=www-data --with-fpm-group=www-data --with-config=/etc/php/7.4/fpm --with-config=/etc/php/7.4/fpm/pool.d --with=mysqlnd --with=pdo_mysql --with=pdo_pgsql --with=pdo_sqlite --with=gd --with=curl --with=json --with=mbstring --with=tokenizer --with=xml --with=zip --with=zlib --with=bz2 --with=openssl --enable=opcache --enable=exif --enable=iptc --enable=fileinfo --disable=rpath --enable=shared --enable="pcntl" --enable="sysvmsg" --enable="sysvsem" --enable="shmop" --enable="sockets" --enable="syslog" --enable="syscon" --enable="posix" --disable="maintainermode" && pecl channel pecl.php.net && pecl install mongodb && echo "extension = mongodb.so" >> /etc/php/7.4/fpm/conf.d/mongodb.ini && echo "extension = mongodb.so" >> /etc/php/7.4/cli/conf.d/mongodb.ini && echo "extension = mongodb.so" >> /etc/php/7.4/apache2/conf.d/mongodb.ini && service apache2 restart && service php7.4-fpm restart && service nginx restart && service postgresql restart && service memcached restart && service rabbitmq restart && service elasticsearch restart && service logstash restart && service kafka restart && service consul restart && service prometheus restart && service grafana restart && service nodered restart && service jenkins restart && service keycloak restart && service sonarqube restart && service influxdb restart && service graphql restart && service discord restart && service netdata restart && service portainer restart && service nextcloud restart && service owncloud restart && service piwik restart && service mailcatcher restart && service sanic restart && service uwsgi restart && service traefik restart && service cron restart && chmod +x /usr/local/bin/*; fi" | sudo tee /etc/apt/sources.list.d/mongodb* > /dev/null || true; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi;fi`
还没有评论,来说两句吧...