Install php 7.3 centos 7 digitalocean
Question Show
I’ve been trying to install the latest PHP version on my CentOS 7 droplet but every install keeps missing some key extensions. If I try to add them afterwards, there are some dependency failures which really bugs me. I’ve removed and installed PHP from 5.4 to 7.3 about a dozen times already. Can someone provide me with some proper stepts to do so. Submit an answer This textbox defaults to using Markdown to format your answer. You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link! Sign In or Sign Up to Answer These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others. IntroductionA “LAMP” stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is an acronym which represents the Linux operating system, with the Apache web server. The site data is typically stored in a MySQL database and dynamic content is processed by PHP. On most Linux systems, you can install
MySQL by downloading the PrerequisitesBefore you begin with this guide, you should have a separate, non-root user account set up on your server. You can learn how to do this by following our initial server setup for CentOS 7 tutorial. Step 1 — Installing the Apache Web ServerApache is a popular open-source web server that is used to display web pages to visitors. You can configure it to serve PHP pages. Install Apache using CentOS’s package manager, Type this command in your terminal to install the
When prompted, enter
You can test if your server is running by entering your public IP address or your domain name in your web browser. Note: If you are using DigitalOcean as DNS hosting provider, you can check our product docs for detailed instructions on how to set up a new domain name and point it to your server. If you do not have a domain name pointed at your server or do not know your server’s public IP address, you can find it by running the following command:
This will print out a few different addresses. You can try each of them in your web browser. An alternative method is to use an outside party to tell you how it sees your server. You can do this by asking a specific server what your IP address is with this command:
Whichever method you choose, type in your IP address into your web browser to verify that your server is running.
You will be presented with the default CentOS 7 Apache landing page: You can enable Apache to start on boot with:
Step 2 — Installing MySQL (MariaDB)With your web server up and running, you can install MariaDB. It will organize and provide access to databases where your site can store information. To install the MariaDB software package, run:
When the installation is complete, start MariaDB:
You can enable MariaDB to start on boot with this command:
To improve the security of your database server, it’s recommended that you run a security script that comes pre-installed with MariaDB. This script will remove some insecure default settings and lock down access to your database system. Start the interactive script by running:
This script will take you through a series of prompts where you can make some changes to your MariaDB setup. The first prompt will ask you to enter the current database root password. This is not to be confused with the system root user. The database root user is an administrative user with full privileges over the database system. Because you just installed MariaDB and haven’t made any
configuration changes, this password will be blank. Press The next prompt asks you whether you’d like to set up a database root password. Type From there, you can press When you’re finished, log in to the MariaDB console by entering:
This connects you to the MariaDB server as the administrative database user root:
For increased security, it’s best to have dedicated user accounts with less expansive privileges set up for every database. This is especially important if you plan on having multiple databases hosted on your server. To demonstrate such a setup, create a
database named Run the following command from your MariaDB console to create a new database:
You can create a new user and grant them full privileges on the custom database you’ve just created. The following command defines this user’s password as
This command gives the
example_user user full privileges over the Use the
Exit the MariaDB shell:
You can test if the new user has the proper permissions by logging in to the MariaDB console again, but using the example_user credentials you created above:
Note the
Your
To exit the MariaDB shell, type:
Your database system is set up and you can move on to installing PHP. Step 3 — Installing PHPYou have Apache installed to serve your content and MariaDB to store and manage your data. PHP will process code to display dynamic content to the user. In addition to the Use this command to install the
Restart the Apache web server to enable the PHP module you installed:
Your server is now configured with all the components necessary for your LAMP stack application. The next step is to test your configuration to ensure that everything is working harmoniously. Step 4 — Testing PHP on your Apache Web ServerThe default Apache installation on CentOS 7 will create a document root located at You can, however, make an adjustment to change the default permission settings on your Apache document root folder. This allows you to create and modify files in that directory with your regular system user without the need to prefix each command with The following command will change the ownership of the default Apache document root to a user and group called
You can create a PHP test file to ensure the web server works as expected. Use your preferred text editor to create this file. The following examples use the default Create a PHP file called
This opens a blank PHP file at the /var/www/html/info.php
This PHP code displays information about the PHP environment running on your server. When you are finished with making your changes to this file, press the You can
test whether your web server correctly displays PHP content by going to your server’s public IP address, followed by
A web page, similar to the one below, will be displayed in your browser: This page gives you information about your server from the perspective of PHP. It is useful for debugging and ensuring that your settings are being applied correctly. After checking the relevant information about your PHP server, it’s best to remove this file as it contains sensitive information about your PHP environment and your CentOS server. You can use
You can always recreate this page if you need to access the information again later. Next, you can test the database connection utilizing PHP. Step 5 – Testing Database Connection with PHP (Optional)You can test if PHP connects to MariaDB and executes database queries by creating a test table with some test data. You can query for its contents from a PHP script. First, connect to the MariaDB console with the database user you created in Step 2 of this guide:
From the MariaDB console, run the following statement to create a table named
The MariaDB console will notify you about changes to your table after each edit.
Insert a few rows of content in the test table. You can repeat the next command a few times, using different values, to populate your test table:
To confirm that the data was successfully saved to your table, run:
Below is an example of the output:
After confirming that you have valid data in your test table, you can exit the MariaDB console:
Now you can create the PHP script that will connect to MariaDB and query for your content. Create a new PHP file in your custom web root directory using your preferred editor.
This example uses
Add the following content by pressing /var/www/html/todo_list.php
Save and close the file when you’re done editing by pressing You can now access this page in your web browser by visiting your server’s host name or public IP address, followed by
Below is an example of the web page, revealing the content you’ve inserted in your test table: ConclusionIn this guide, you’ve built a flexible foundation for serving PHP websites and applications to your visitors, using Apache as a web server. You’ve set up Apache to handle PHP requests, and set up a MariaDB database to store your website’s data. How do I install or upgrade to PHP 7 on CentOS 7 Linux?The procedure to install PHP 7.2 on CentOS 7 or RHEL 7 is as follows:. Turn on EPEL repo, enter: sudo yum -y install epel-release.. Turn on Remi repo i.e.remi-php72: sudo yum-config-manager --enable remi-php72.. Refresh repository: sudo yum update.. Install php version 7.2, run: sudo yum install php.. How upgrade PHP 5.4 to PHP 7.4 on CentOS 7?“centos 7 upgrade php 5.4 to 7.4” Code Answer's. sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm.. sudo yum -y install epel-release yum-utils.. sudo yum-config-manager --disable remi-php54.. sudo yum-config-manager --enable remi-php73.. sudo yum update.. How do I run multiple versions of PHP on CentOS 7?Running Multiple PHP version on the same server. Step 1 Install required packages. Run given Command to install each package. ... . Step 2 Install PHP multiple versions. ... . Step 3 Stop both PHP-FPM. ... . step 4 Configure PHP-FPM. ... . Step 5 Configure SELinux. ... . Step 6 Make Script Wrapper. ... . Step 7 Configure Apache. ... . Step 8 Start/Enable Services.. How do I install apache MySQL PHP lamp on CentOS RHEL 7?How to Install the LAMP Stack on CentOS 7. Step 1: Update Package Repository Cache.. Step 2: Install the Apache Web Server.. Step 3: Install MySQL (MariaDB) and Create a Database.. Step 4: Run MySQL Security Script.. Step 5: Install PHP.. Step 6: Test PHP Processing.. Step 7: Install PHP Modules.. Step 8: Restart Apache.. |