PHP/Mysql - Switching from localhost to online hosting

Asked

Viewed 981 times

0

I created a website with PHP and a Mysql database using XAMPP. Now I’d like to put the site online on a host, I have to change the connection to the database where it says localhost?

What procedures do I have to do?

2 answers

1

There are many procedures to be followed which I will list in general, and may vary from case to case. If you do not feel safe, it is recommended to request a technician or someone experienced.

1. Domain name

Choose a domain name for your website (e.g., meusite.com.br). Choose a name as short as possible and that has to do with the purpose of the site, as it will be as an "identity" of the site.

If you want a Brazilian domain (e.g., with.br), log in to register.br and register your domain, as it is usually cheaper there than on hosting sites, except when they give you free domain registration when you hire a hosting service. This can vary a lot from company to company.

If you want to register a foreign domain (e.g., .com), you can do this directly at the hosting company if it has this service.

The domain may take a few hours to take effect after the registration.

2. Lodging

Hire a host that will meet your demand (if there is support for the PHP version you use, the database you use, comfortable traffic limit, sufficient storage space, etc.). They will inform you the FTP access data (server, user and password) that will be the means for you to send the files to the server.

If you have registered the domain in the.br registry, you will need to inform the.br registry panel of your hosting’s DNS servers so that the domain points there (the DNS servers you can find in hosting support).

3. Creation of the database and sending of files

Create the database on the hosting server and migrate the tables there. Generally, the hosts have an administrative panel (e.g., phpMyAdmin, Control Panel, etc.) where you can manage the database. Change in your PHP file connection to the host, user and password database according to the remote database.

Use an FTP client program to upload the files to the server. I recommend using Filezilla, which has an interface similar to the Windows file manager, simply drag the files to the remote folder, which is usually called "public_html/" on the server.

4. Finalizing

After all these steps: registered domain, created database and uploaded files, do a test by opening the site in the browser to see if everything is working.

These are the basic procedures. As stated at the beginning, it may vary from case to case.

  • Thanks for your help. My main question is even about the database, because in the database I created in php admin on the connection there is localhost, user and pass. If I create the database again already with the site on the host the settings will be on the same localhost or have to give the ip?

0

First you need to hire a hosting service. Once she’s been hired then you’ll need to take your files from the site and move up the hosting storage (this is usually done via FTP if you don’t use Git).

Remember never put passwords and users inside your code. They are environment related, most hosts support the passage of environment variables, if not, you can create a file with the extension .ini and use the function parse_ini_file PHP to bring your database data.

From there is to create a base in the hosting and point there.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.