9. PHP, LAMP and LEMP Step by Step
9.2 Installing PHP on Amazon Linux 2023 and Ubuntu
| OS + web server | Install command | PHP handler |
|---|---|---|
| AL2023 + Nginx or Apache | sudo yum install -y php php-fpm php-mysqlnd php-cli |
PHP-FPM socket /run/php-fpm/www.sock |
| CentOS Stream 9 + Nginx or Apache | sudo yum install -y php php-fpm php-mysqlnd php-cli |
PHP-FPM socket /run/php-fpm/www.sock |
| Ubuntu + Nginx | sudo apt install -y php-fpm php-mysql |
PHP-FPM socket /run/php/php8.x-fpm.sock |
| Ubuntu + Apache | sudo apt install -y php libapache2-mod-php php-mysql |
Apache mod_php (no FPM needed) |
On AL2023 / CentOS, start PHP-FPM and restart the web server:
sudo service php-fpm start
sudo systemctl enable php-fpm
sudo service nginx restart # or: sudo service httpd restart
php -v
On Amazon Linux 2023 and CentOS, Apache is automatically wired to PHP-FPM by /etc/httpd/conf.d/php.conf, and the default Nginx server is wired by /etc/nginx/default.d/php.conf. For your own Nginx server block, add the PHP location shown below.
Ravindra Bagale's Tip
Amazon Linux var PHP install kela pan php-fpm start kela nahi – mag Nginx "502 Bad Gateway" deto aani students gondhaltat. 502 mhanje Nginx la maagcha (PHP-FPM) program sapadla nahi. sudo service php-fpm status aadhi bagha.
Practice task
Install PHP on both instances and run php -v and php -m | grep -i mysql to confirm the MySQL extension is loaded.