Setting Up a Full LAMP Stack on CentOS Stream 9 Using Aliyun Mirrors
This guide walks through installing CentOS Stream 9, configuring Aliyun and EPEL repositories, adding the Remi PHP 8.2 repo, and then deploying Nginx, PHP‑FPM, MySQL 8, Redis and supporting tools via Docker and DNF, all with fast domestic mirrors.
This article focuses on CentOS Stream 9, the community edition of CentOS, and recommends using Aliyun or Baidu cloud mirrors for the OS image. It also mentions Rocky Linux and AlmaLinux as compatible alternatives.
To start, pull the official Docker image and run a privileged container:
docker pull dokken/centos-stream-9:latest</code>
<code>docker run -tid --name centos_stream_9 --privileged=true dokken/centos-stream-9:latest /usr/sbin/init</code>
<code>docker exec -it centos_stream_9 /bin/bashThe article then lists the software versions used: CentOS Stream 9, PHP 8.2.4, Nginx 1.22.1, MySQL 8.0.32, Redis 6.2.7, Git 2.39.1.
1. Install Aliyun CentOS repositories (Stream 9)
cd /etc/yum.repos.d</code>
<code>cp centos.repo centos.repo.bak</code>
<code>cp centos-addons.repo centos-addons.repo.bak</code>
<code># Edit centos.repo: comment out metalink lines and add baseurl lines for [baseos], [appstream] and [crb] pointing to https://mirrors.aliyun.com/centos-stream/9-stream/...</code>
<code>dnf makecache</code>
<code>dnf repolist2. Install the EPEL repository
dnf install 'dnf-command(config-manager)'</code>
<code>dnf --enable config-manager crb</code>
<code>dnf install -y epel-release epel-next-release</code>
<code>dnf makecache</code>
<code>dnf repolist3. Install Remi's PHP 8.2 repository
dnf install -y https://mirrors.aliyun.com/remi/enterprise/remi-release-9.rpm</code>
<code>sed -i 's|http://rpms.remirepo.net|https://mirrors.aliyun.com/remi|g' /etc/yum.repos.d/remi*</code>
<code>sed -i 's/#baseurl/baseurl/g' /etc/yum.repos.d/remi*</code>
<code>sed -i 's|^mirrorlist|#mirrorlist|' /etc/yum.repos.d/remi*</code>
<code>dnf makecache</code>
<code>dnf repolist</code>
<code>dnf -y install yum-utils4. Install PHP 8.2 and extensions
dnf install -y php82 php82-php-devel php82-php-fpm php82-php-mbstring php82-php-memcache php82-php-memcached php82-php-redis php82-php-mysqlnd php82-php-pdo php82-php-bcmath php82-php-xml php82-php-gd php82-php-gmp php82-php-igbinary php82-php-imagick php82-php-mcrypt php82-php-pdo_mysql php82-php-posix php82-php-simplexml php82-php-opcache php82-php-xsl php82-php-xmlwriter php82-php-xmlreader php82-php-swoole php82-php-zip php82-php-phalcon php82-php-yaml php82-php-yar php82-php-yaf php82-php-uuidAfter installation, replace the system php binary with the new one:
rm /usr/bin/php</code>
<code>ln -s /usr/bin/php82 /usr/bin/php5. Configure Composer to use Aliyun mirror
curl -o /usr/local/bin/composer https://mirrors.aliyun.com/composer/composer.phar</code>
<code>chmod +x /usr/local/bin/composer</code>
<code>composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/6. Install Nginx and integrate with PHP‑FPM
# Add Nginx repo via echo (single command)</code>
<code>dnf makecache</code>
<code>dnf install -y nginx</code>
<code>systemctl enable nginx</code>
<code>systemctl enable php82-php-fpm</code>
<code>sed -i 's/user = apache/user = nginx/g' /etc/opt/remi/php82/php-fpm.d/www.conf</code>
<code>sed -i 's/group = apache/group = nginx/g' /etc/opt/remi/php82/php-fpm.d/www.conf</code>
<code>sed -i 's|listen = /var/opt/remi/php82/run/php-fpm/www.sock|listen=9000|' /etc/opt/remi/php82/php-fpm.d/www.conf</code>
<code>rm -f /etc/nginx/conf.d/default.conf</code>
<code>vi /etc/nginx/conf.d/default.confThe default.conf file should contain:
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;
}
}Add a simple PHP test file ( 1.php) with <?php phpinfo(); ?>, then start services:
systemctl start nginx</code>
<code>systemctl start php82-php-fpm</code>
<code>curl localhost/1.phpIf the PHP info page appears, Nginx and PHP‑FPM are correctly configured.
7. Install MySQL 8
dnf install -y https://repo.mysql.com/mysql80-community-release-el9-1.noarch.rpm</code>
<code>dnf -y --enablerepo=mysql80-community install mysql-community-server</code>
<code>systemctl enable mysqld</code>
<code>systemctl start mysqld</code>
<code># Retrieve temporary root password</code>
<code>grep 'temporary password' /var/log/mysqld.log</code>
<code># Log in and reset password</code>
<code>mysql -uroot -pThen adjust root authentication and create a remote root user:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'tb4Wn3BthR.';</code>
<code>flush privileges;</code>
<code>set global validate_password.policy=LOW;</code>
<code>create user 'root'@'%' identified by 'root1234';</code>
<code>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root1234';</code>
<code>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';</code>
<code>drop user root@localhost;</code>
<code>flush privileges;Reconnect with the new password: mysql -uroot -proot1234 8. Install Redis 6 and common utilities
dnf --enablerepo=remi install -y redis</code>
<code>dnf install -y git wget vim zip unzip p7zip rsync crontabs supervisor net-tools python3</code>
<code>systemctl enable redis</code>
<code>systemctl start redisSummary
Using domestic Aliyun mirrors dramatically speeds up package downloads (≈3 MB/s). The guide demonstrates a rapid, end‑to‑end setup of a modern backend stack on CentOS Stream 9, covering OS preparation, repository configuration, PHP 8.2, Nginx, MySQL 8, Redis, and essential tools.
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.
