Quick Guide to Installing PHP 8.2 Stack on Ubuntu 20.04 Using Alibaba Cloud Mirrors
This tutorial shows how to quickly set up a full PHP 8.2, Nginx, MySQL 8, Redis 6, and Composer environment on Ubuntu 20.04 by configuring Alibaba Cloud apt mirrors, installing required packages, adjusting configurations, and verifying the stack, all in roughly twenty minutes.
The article presents a step‑by‑step procedure for rapidly installing a complete PHP 8.2 development stack (PHP, Nginx, MySQL, Redis, Composer, etc.) on an Ubuntu 20.04 (Focal) server, using Alibaba Cloud mirrors to speed up package downloads.
Software versions used :
ubuntu 20.04
php 8.2.1
nginx 1.22.1
mysql 8.0.31
redis 7.0.7
git 2.24.41. Configure Alibaba apt repositories
apt update
vim /etc/apt/sources.list # replace with Alibaba http sources
# example entry
deb http://mirrors.aliyun.com/ubuntu focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu focal main restricted universe multiverse
# repeat for security, updates, backports
apt update
apt install -y --reinstall ca-certificatesAfter editing, switch the URLs to https and run apt update again.
2. Install PHP 8 and extensions
apt install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils systemd gnupg2 lsb-release ubuntu-keyring
curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /usr/share/keyrings/ppa_ondrej_php.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list
apt-get update
apt-get install -y php8.2-cli php8.2-dev php8.2-pgsql php8.2-sqlite3 php8.2-gd php8.2-curl php8.2-imap php8.2-mysql php8.2-mbstring php8.2-xml php8.2-zip php8.2-bcmath php8.2-soap php8.2-intl php8.2-readline php8.2-ldap php8.2-msgpack php8.2-igbinary php8.2-redis php8.2-swoole php8.2-memcached php8.2-pcov php8.2-fpm php8.2-gmp php8.2-imagick php8.2-mcrypt php8.2-uuid php8.2-yamlThe installation typically takes about fifteen minutes.
3. Configure Composer to use Alibaba mirror
curl -o /usr/local/bin/composer https://mirrors.aliyun.com/composer/composer.phar
chmod +x /usr/local/bin/composer
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/To suppress the "yes" prompt when running Composer as root, add the environment variable:
echo "export COMPOSER_ALLOW_SUPERUSER=1" >> /etc/environment
source /etc/environment4. Install Nginx and link it with php‑fpm
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" | tee /etc/apt/sources.list.d/nginx.list
apt update
apt install nginx
sed -i 's/listen = \/run\/php\/php8.2-fpm.sock/listen = 127.0.0.1:9000/g' /etc/php/8.2/fpm/pool.d/www.conf
# modify /etc/nginx/nginx.conf to set user www-data;
rm -f /etc/nginx/conf.d/default.conf
cat > /etc/nginx/conf.d/default.conf <<'EOF'
server {
listen 80;
server_name localhost;
charset utf-8;
access_log /var/log/nginx/host.access.log main;
root /usr/share/nginx/html;
index index.php index.html index.htm;
error_page 404 500 502 503 504 /50x.html;
location = /50x.html { root /usr/share/nginx/html; }
location / { try_files $uri $uri/ /index.php?$query_string; }
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
/etc/init.d/nginx start
/etc/init.d/php8.2-fpm start
curl localhost/1.php # should display phpinfo()5. Install MySQL 8 and configure a new root user
apt install mysql-server-8.0 mysql-client-8.0
grep 'temporary password' /var/log/mysqld.log # obtain initial password
mysql -uroot -p # login with temporary password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'tb4Wn3BthR.';
flush privileges;
CREATE USER 'root'@'%' IDENTIFIED BY 'root1234';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root1234';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
DROP USER root@localhost;
flush privileges;
mysql -uroot -proot1234 # verify login
SELECT user, host, plugin FROM mysql.user\G;6. Install Redis 6 (stack) and optionally Redis 5
curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/redis.list
apt-get update
apt-get install redis-stack-server # installs Redis 6
# For Redis 5 simply:
# apt install redis-serverThe guide concludes by noting that Alibaba Cloud mirrors speed up most downloads, though Ubuntu packages may still be slower due to bandwidth limits.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
php Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
