How to move a XAMPP project to AwanBox
Your PHP and MySQL project works in XAMPP. On a Linux computer it will break in a handful of predictable ways. Here are the six we hit, and the fix for each.
XAMPP hides a lot: it ships PHP and MySQL ready to go, it forgives capital letters, it lets root in with no password, and it shows PHP errors on screen. A cloud computer is a plain Linux machine, so none of that is there. The project is fine; the setup around it is different.
This post moves a small club-members site, step by step, and says what broke each time. The XAMPP post explains why you might want to move, and the PHP and MySQL post builds a project from scratch on a computer.
How we ran it
We could not drag a real project from a laptop into the browser for this post. So we asked the agent to build a stand-in first: a folder htdocs/clubsite with a PHP page that lists club members from a MySQL table, written the way XAMPP students usually write it, plus a members.sql dump, both in clubsite.zip. Then it moved the zip to a Small computer as if it had just arrived. The mistakes in the stand-in are the common ones, so they are the ones you are likely to meet. With your own project, you upload the zip in the Files tab instead.
The first message
I am a student with a PHP and MySQL project that I built with
XAMPP on my laptop, and I want to move it here. [...make a
stand-in project and zip it...] Then act as if the zip just
arrived: move it to this computer. Unpack it, install what is
needed, import the database, serve it on port 8000, and test it
with curl. Tell me plainly what broke in the move and how you
fixed each thing, so I can do the same with my real project.
With a real project you would say it more simply: "I uploaded clubsite.zip and members.sql to the Files tab. Move the site here, import the database, serve it on port 8000 and tell me what you had to change."
The agent runs with Ask me before: Risky steps only, so it stopped twice to ask. The first time it wanted to delete and rebuild its own zip. We approved, because that was its stand-in.
The second time it asked to publish port 8000 as a public link, which we had not asked for, so we declined. A public link is how your lecturer opens the page, and the PHP and MySQL post shows that step.
The six things that broke
1. Nothing was installed. A new computer has no PHP and no MySQL. The agent installed php-cli, php-mysql and mariadb-server and started the database. MariaDB is the free drop-in version of MySQL. If you forget php-mysql, you get "Call to undefined function mysqli_connect()".
sudo apt update
sudo apt install -y php-cli php-mysql mariadb-server zip unzip
sudo service mariadb start
2. The database login was refused. In XAMPP, root with an empty password works. On Linux, root belongs to the administrator. The agent made a normal user with a password and gave it rights to only this one database, then put that login in includes/db.php and set the file so only the owner and group can read it. Choose your own password, and do not reuse one from elsewhere.
3. A capital letter broke an include. The code said Includes/db.php and the folder on disk was includes. Windows ignores the difference between capital and small letters in file names, and Linux does not. The fix was to write the path exactly as the folder is named, and to anchor it to the file's own folder so it works wherever the server starts:
require_once __DIR__ . '/includes/db.php';
4. The error was invisible. The page was just blank. XAMPP shows PHP errors in the browser; Ubuntu's PHP does not, because showing them to visitors is unsafe. The message was in the server log, and that is where to look:
tail -f /tmp/php-server.log
5. The SQL dump would not import. A MySQL 8 export names a character-comparison rule, utf8mb4_0900_ai_ci, that MariaDB does not know, so the import stopped with "ERROR 1273 Unknown collation". The agent replaced the name with one MariaDB has, created the database, and imported again:
sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g' members.sql
sudo mariadb -e "CREATE DATABASE IF NOT EXISTS clubsite CHARACTER SET utf8mb4;"
sudo mariadb clubsite < members.sql
6. A link pointed at the laptop. The page had http://localhost/clubsite/ written into it. On the computer, that means port 80 and nothing is listening there. The agent changed it to a relative link, index.php, which works at any address. Search your project for localhost, 127.0.0.1 and C:\ before you move it.
The agent noticed one more thing while it was in the file. On PHP 8.1 and later, a database error throws an exception, so the old if (!$conn) die(...) never runs. It wrapped the connection in try and catch so you get a readable message and not a white page.
Checking that it works
The server is PHP's own: php -S 0.0.0.0:8000 -t /home/agent/www, which is fine for an assignment. We checked it from the terminal:
The agent also wrote what it had changed, with the commands, to clubsite-move-notes.md in the home folder. Keep a file like that: it is the list you repeat on your next project.
A checklist for your own project
- Export the database from phpMyAdmin as a
.sqlfile and zip the project folder. - Upload both in the Files tab, or ask the agent where to put them.
- Install PHP, the MySQL extension and MariaDB.
- Make a database login for the project and update the connection file. No
root, no empty password. - Check that every file name in
includeandrequirematches the case on disk. - Search for
localhostand absolute paths, and change them to relative ones. - Import the dump. If it names a collation MariaDB does not know, replace it.
- Start the server, open the page, and look in the server log if it is blank.
What it cost
The run used a Small computer, RM0.03 an hour while it runs and nothing while it sleeps, for well under an hour, so a few sen of the welcome credit. Most of that was installing packages. Small or Large and how running time and credit work have the details.
Cautions
- Our project was a stand-in. Yours will have its own surprises, such as other extensions, a different PHP version, or an upload folder that needs permission to write.
- Check what the agent changed. It rewrote a link, a login and a dump. Read the notes file and test the page yourself.
- The development server is for coursework. For a real site with many visitors, use a proper web server.
- Keep your original. Move a copy, and keep the project on your laptop or in Git.
awxis in early alpha. - Check your course rules on AI help with assignments.
Keep reading
- How to back up and restore a cloud computer: a tested guide
- Dear students, do you still use XAMPP? Use Awanbox instead.
- Put a PHP and MySQL assignment online with a link
- How to practise SQL with PostgreSQL: SELECT, JOIN, GROUP BY
Getting started
Sign in with your Google account and open Workbench. Start a chat on a Small computer, upload your zip and dump in the Files tab, and paste the first message from this post.
Awi, signing off.